Skip to content

Commit

Permalink
Merge branch 'release-1.1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantinos committed Jul 27, 2019
2 parents b58a74f + 5f2a17b commit 8f96527
Show file tree
Hide file tree
Showing 14 changed files with 172 additions and 88 deletions.
17 changes: 17 additions & 0 deletions .bandit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# (optional) list included tests here:
#tests: ['B201', 'B301']

# (optional) list skipped tests here:
skips: ['B322']

### override settings - used to set settings for plugins to non-default values

any_other_function_with_shell_equals_true:
no_shell: [os.execl, os.execle, os.execlp, os.execlpe, os.execv, os.execve,
os.execvp, os.execvpe, os.spawnl, os.spawnle, os.spawnlp, os.spawnlpe,
os.spawnv, os.spawnve, os.spawnvp, os.spawnvpe, os.startfile]
shell: [os.system, os.popen, os.popen2, os.popen3, os.popen4,
popen2.popen2, popen2.popen3, popen2.popen4, popen2.Popen3,
popen2.Popen4, commands.getoutput, commands.getstatusoutput]
subprocess: [subprocess.Popen, subprocess.call, subprocess.check_call,
subprocess.check_output]
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ Changelog
=========


1.1.3 (2019-07-27)
-------------------

Changes
^^^^^^^

- Improve security


1.1.1 (2019-07-21)
-------------------

Expand Down
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ include .travis.yml
include .scrutinizer.yml
include appveyor.yml

include .bandit.yml

include .coveragerc
include tox.ini

Expand Down
13 changes: 7 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Overview
* - tests
- | |travis|
| |appveyor|
| |coveralls|
| |coverage|
| |scrutinizer_code_quality|
| |code_intelligence_status|
* - package
Expand All @@ -36,9 +36,9 @@ Overview
:alt: Appveyor Build Status
:target: https://ci.appveyor.com/project/boromir674/music-album-creator/branch/master

.. |coveralls| image:: https://coveralls.io/repos/github/boromir674/music-album-creator/badge.svg?branch=master
:alt: Coveralls Coverage Status
:target: https://coveralls.io/github/boromir674/music-album-creator?branch=master
.. |coverage| image:: https://scrutinizer-ci.com/g/boromir674/music-album-creator/badges/coverage.png?b=master
:alt: Coverage Status
:target: https://scrutinizer-ci.com/g/boromir674/music-album-creator/?branch=master

.. |scrutinizer_code_quality| image:: https://scrutinizer-ci.com/g/boromir674/music-album-creator/badges/quality-score.png?b=master
:alt: Code Quality
Expand All @@ -60,9 +60,9 @@ Overview
:alt: Supported versions
:target: https://pypi.org/project/music-album-creation

.. |commits_since| image:: https://img.shields.io/github/commits-since/boromir674/music-album-creator/v1.1.2.svg
.. |commits_since| image:: https://img.shields.io/github/commits-since/boromir674/music-album-creator/v1.1.3.svg
:alt: Commits since latest release
:target: https://github.com/boromir674/music-album-creator/compare/v1.1.2...master
:target: https://github.com/boromir674/music-album-creator/compare/v1.1.3...master


.. |supported-implementations| image:: https://img.shields.io/pypi/implementation/music-album-creator.svg
Expand Down Expand Up @@ -105,3 +105,4 @@ Development
To run the all tests run::

tox

94 changes: 46 additions & 48 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ environment:
nodejs_version: Current
ffmpeg_version: latest
matrix:

- TOXENV: check
TOXPYTHON: C:\Python35\python.exe
PYTHON_HOME: C:\Python35
PYTHON_VERSION: '3.5'
PYTHON_ARCH: '32'
platform: x86
ffmpeg_platform: win32
#
# - TOXENV: clean
# TOXPYTHON: C:\Python35\python.exe
# PYTHON_HOME: C:\Python35
# PYTHON_VERSION: '3.5'
# PYTHON_ARCH: '32'
# platform: x86
# ffmpeg_platform: win32

- TOXENV: 'py35-cover,coveralls'
TOXPYTHON: C:\Python35\python.exe
Expand All @@ -29,47 +29,39 @@ environment:
PYTHON_ARCH: '32'
platform: x86
ffmpeg_platform: win32
#
# - TOXENV: 'py35-cover'
# TOXPYTHON: C:\Python35-x64\python.exe
# PYTHON_HOME: C:\Python35-x64
# PYTHON_VERSION: '3.5'
# PYTHON_ARCH: '64'
# platform: x64
# ffmpeg_platform: win64

# - TOXENV: 'py35-nocov'
# TOXPYTHON: C:\Python35\python.exe
# PYTHON_HOME: C:\Python35
# PYTHON_VERSION: '3.5'
# PYTHON_ARCH: '32'
# platform: x86
# ffmpeg_platform: win32
#
# - TOXENV: 'py35-nocov'
# TOXPYTHON: C:\Python35-x64\python.exe
# PYTHON_HOME: C:\Python35-x64
# PYTHON_VERSION: '3.5'
# PYTHON_ARCH: '64'
# platform: x64
# ffmpeg_platform: win64

# - TOXENV: 'py36-nocov'
# TOXPYTHON: C:\Python36-x64\python.exe
# PYTHON_HOME: C:\Python36-x64
# PYTHON_VERSION: '3.6'
# PYTHON_ARCH: '64'
# platform: x64
# ffmpeg_platform: win64

- TOXENV: 'py35-cover,coveralls'
TOXPYTHON: C:\Python35-x64\python.exe
PYTHON_HOME: C:\Python35-x64
PYTHON_VERSION: '3.5'
PYTHON_ARCH: '64'
platform: x64
ffmpeg_platform: win64


- TOXENV: 'py36-cover,coveralls'
TOXPYTHON: C:\Python36\python.exe
PYTHON_HOME: C:\Python36
PYTHON_VERSION: '3.6'
PYTHON_ARCH: '32'
platform: x86
ffmpeg_platform: win32

- TOXENV: 'py36-cover,coveralls'
TOXPYTHON: C:\Python36-x64\python.exe
PYTHON_HOME: C:\Python36-x64
PYTHON_VERSION: '3.6'
PYTHON_ARCH: '64'
platform: x64
ffmpeg_platform: win64

- TOXENV: 'py37-cover,coveralls'
TOXPYTHON: C:\Python37\python.exe
PYTHON_HOME: C:\Python37
PYTHON_VERSION: '3.7'
PYTHON_ARCH: '32'
platform: x86
ffmpeg_platform: win32

- TOXENV: 'py37-cover,coveralls'
TOXPYTHON: C:\Python37-x64\python.exe
PYTHON_HOME: C:\Python37-x64
PYTHON_VERSION: '3.7'
PYTHON_ARCH: '64'
platform: x64
ffmpeg_platform: win64

init:
- ps: echo $env:TOXENV
Expand All @@ -83,11 +75,17 @@ install:
- ps: Start-FileDownload $env:ffmpeg_download$env:ffmpeg_platform/static/ffmpeg-$env:ffmpeg_version-$env:ffmpeg_platform-static.zip
- 7z x ffmpeg-%ffmpeg_version%-%ffmpeg_platform%-static.zip
- PATH=%PATH%;%cd%\ffmpeg-%ffmpeg_version%-%ffmpeg_platform%-static\bin
# - ps: $env:package_version = (Get-Content -Raw -Path package.json | ConvertFrom-Json).version
# - ps: Update-AppveyorBuild -Version "$env:package_version-$env:APPVEYOR_REPO_BRANCH-$env:APPVEYOR_BUILD_NUMBER"
- '%PYTHON_HOME%\Scripts\virtualenv --version'
- '%PYTHON_HOME%\Scripts\easy_install --version'
- '%PYTHON_HOME%\Scripts\pip --version'
- '%PYTHON_HOME%\Scripts\tox --version'
- '%PYTHON_HOME%\python --version'
# Read the encrypted file with eg a COVERALLS_REPO_TOKEN value
# - ps: iex ((New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/appveyor/secure-file/master/install.ps1'))
# - cmd: appveyor-tools\secure-file -decrypt .appveyor-coveralls-repo-token.enc -secret %COVERALLS_REPO_TOKEN%
# - sh: ./appveyor-tools/secure-file -decrypt .appveyor-coveralls-repo-token.enc -secret $COVERALLS_REPO_TOKEN


test_script:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def readme():

setup(
name='music_album_creation',
version='1.1.2',
version='1.1.3',
description='A CLI application intending to automate offline music library building.',
long_description=readme(),
keywords='music automation download youtube metadata',
Expand Down
2 changes: 1 addition & 1 deletion src/music_album_creation/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '1.0.8a'
__version__ = '1.1.3'

from .tracks_parsing import StringParser
from .metadata import MetadataDealer
Expand Down
19 changes: 13 additions & 6 deletions src/music_album_creation/album_segmentation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/python3

import time
import subprocess
import time
from tempfile import mkdtemp

from music_album_creation.tracks_parsing import StringParser

Expand All @@ -10,8 +11,11 @@ class AudioSegmenter:

args = ['ffmpeg', '-i', '-acodec', 'copy', '-ss']

def __init__(self, target_directory='/tmp'):
self._dir = target_directory
def __init__(self, target_directory=''):
if not target_directory:
self._dir = mkdtemp()
else:
self._dir = target_directory

@property
def target_directory(self):
Expand All @@ -22,6 +26,9 @@ def target_directory(self):
def target_directory(self, directory_path):
self._dir = directory_path

def temp_location(self):
self._dir = mkdtemp()

def segment_from_file(self, album_file, tracks_file, supress_stdout=True, supress_stderr=True, verbose=False, sleep_seconds=0.45):
"""
Given an album audio file and a file with track information, segments the audio file into audio tracks which get stored in the 'self.target_directory' folder.\n
Expand All @@ -37,7 +44,7 @@ def segment_from_file(self, album_file, tracks_file, supress_stdout=True, supres
list_of_lists = StringParser.parse_hhmmss_string(f.read().strip())
self.segment_from_list(album_file, list_of_lists, supress_stdout=supress_stdout, supress_stderr=supress_stderr, verbose=verbose, sleep_seconds=sleep_seconds)

def segment_from_list(self, album_file, data, supress_stdout=True, supress_stderr=True, verbose=False, sleep_seconds=0):
def segment_from_list(self, album_file, data, supress_stdout=True, supress_stderr=False, verbose=False, sleep_seconds=0):
"""
Given an album audio file and data structure with tracks information, segments the audio file into audio tracks which get stored in the 'self.target_directory' folder.\n
:param str album_file:
Expand Down Expand Up @@ -77,8 +84,8 @@ def _segment(self, *args, supress_stdout=True, supress_stderr=True, verbose=Fals
self._args = self.args[:2] + [album_file] + self.args[2:] + [start] + (lambda: ['-to', str(end)] if end else [])() + [track_file]
if verbose:
print("Segmenting with '{}'".format(' '.join(self._args)))
ro = subprocess.run(self._args, **self.__std_parameters(supress_stdout, supress_stderr))
return ro.returncode
# subprocess.call()
return subprocess.call(self._args, **self.__std_parameters(supress_stdout, supress_stderr))

@classmethod
def __std_parameters(cls, std_out_flag, std_error_flag):
Expand Down
16 changes: 10 additions & 6 deletions src/music_album_creation/create_album.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import sys
import glob
import click
import shutil
import mutagen
import subprocess
from tempfile import mkdtemp, gettempdir
from time import sleep

from . import StringParser, MetadataDealer, AudioSegmenter, FormatClassifier
Expand Down Expand Up @@ -39,10 +39,11 @@
@click.option('--url', '-u', help='the youtube video url')
def main(tracks_info, track_name, track_number, artist, album_artist, url):
# CONFIG of the 'app' #
directory = '/tmp/gav'
if os.path.isdir(directory):
shutil.rmtree(directory)
os.mkdir(directory)
mkdtemp()
directory = gettempdir()
# if os.path.isdir(directory):
# shutil.rmtree(directory)
# os.mkdir(directory)
music_dir = '/media/kostas/freeagent/m'

## Render Logo
Expand Down Expand Up @@ -105,7 +106,7 @@ def main(tracks_info, track_name, track_number, artist, album_artist, url):
if answer.startswith('Durations'):
tracks_data = StringParser.duration_data_to_timestamp_data(tracks_data)
try: # SEGMENTATION
audio_files = audio_segmenter.segment_from_list(album_file, tracks_data, supress_stdout=True, verbose=True, sleep_seconds=0.4)
audio_files = audio_segmenter.segment_from_list(album_file, tracks_data, supress_stdout=False, verbose=True, sleep_seconds=0.4)
except TrackTimestampsSequenceError as e:
print(e)
sys.exit(1)
Expand Down Expand Up @@ -162,4 +163,7 @@ def listCompleter(text, state):
readline.set_completer_delims('\t')
readline.parse_and_bind("tab: complete")
readline.set_completer(completer.pathCompleter)

# if sys.version_info.major == 2: # if interpreter is python2 somehow (it will crash anyways)

main()
42 changes: 40 additions & 2 deletions src/music_album_creation/dialogs.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
import os
import sys
import shutil

from PyInquirer import prompt, Validator, ValidationError

# __all__ = ['store_album_dialog', 'interactive_metadata_dialogs']


class InputFactory:
__instance = None

def __new__(cls, *args, **kwargs):
if not cls.__instance:
cls.__instance = super().__new__(cls)
if sys.version_info.major == 2:
cls.__instance._input = raw_input
else:
cls.__instance._input = input
return cls.__instance

def __call__(self, *args):
return self._input(*args)


ask_input = InputFactory()


#### INPUT URL
def input_youtube_url_dialog():
""""""
print('Please input a url corresponding to a music album uploaded as a youtube video.\n')
video_url = input(' video url: ')
video_url = ask_input(' video url: ')
return video_url


Expand Down Expand Up @@ -58,7 +79,7 @@ def input_lines(prompt_=None):
"""Yields input lines from user until EOFError is raised."""
while True:
try:
yield input() if prompt_ is None else input(prompt_)
yield ask_input() if prompt_ is None else ask_input(prompt_)
except EOFError:
break
else:
Expand Down Expand Up @@ -196,3 +217,20 @@ def set_metadata_panel(default_artist=artist, default_album=album, default_year=
return my_answers

return set_metadata_panel()


class InputFactory:
__instance = None
def __new__(cls, *args, **kwargs):
if not cls.__instance:
cls.__instance = super().__new__(cls)
if sys.version_info.major == 2:
cls.__instance._input = raw_input
else:
cls.__instance._input = input
return cls.__instance

def __call__(self, message):
if not message.endswith(': '):
message += ': '
return self._input(message)
3 changes: 2 additions & 1 deletion src/music_album_creation/format_classification/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def create_datapoints(album_dirs_list, nb_datapoints=None, progress_bar=False, c
feature_vectors = []
class_labels = []
i = 0
assert nb_datapoints is None or type(nb_datapoints) == int
if nb_datapoints and type(nb_datapoints) != int:
raise RuntimeError("Wrong type of 'nb_datapoints' parameter. It should either be an integer (to indicate number of datapoints to pick) or evaluate to False (to indicate taking all available datapoints). Instead '{}' was given".format(nb_datapoints))
if progress_bar:
if not nb_datapoints:
gen = tqdm(new_gen(album_dirs_list), total=len(album_dirs_list) * 2, unit='datapoint')
Expand Down
Loading

0 comments on commit 8f96527

Please sign in to comment.