From f608a9a79b9f6a597a03863ebcae8321f87a46d6 Mon Sep 17 00:00:00 2001 From: Eduardo Ferreira Date: Thu, 25 Aug 2016 20:30:01 +0100 Subject: [PATCH] Commented references to tags, covers and playlists. Reviewed the unit tests for the interface module. Updated references to the library modules to reflect their new location. --- flac2mp3.py | 18 ++++++++++-------- flac2wav.py | 18 ++++++++++-------- library/audio.py | 2 +- library/interface.py | 37 ++++++++++++++++++++++--------------- tests/interface_test.py | 2 +- wav2flac.py | 31 +++++++++++++++++-------------- wav2mp3.py | 31 +++++++++++++++++-------------- 7 files changed, 78 insertions(+), 61 deletions(-) diff --git a/flac2mp3.py b/flac2mp3.py index fa4e375..83d57d0 100755 --- a/flac2mp3.py +++ b/flac2mp3.py @@ -9,27 +9,29 @@ """ # Module import -# ------------------------------------------------------------------------------------------------- -from audio import encode_flac_mp3 -from general import keyboard_interrupt -from interface import get_options +# -------------------------------------------------------------------------------------------------- +from library.audio import encode_flac_mp3 +from library.general import keyboard_interrupt +from library.interface import get_options # Constants -# ------------------------------------------------------------------------------------------------- +# -------------------------------------------------------------------------------------------------- PROGRAM = 'flac2mp3' DESCRIPTION = 'Encodes FLAC files into the MP3 format with the maximum compression level' # Methods :: Execution and boilerplate -# ------------------------------------------------------------------------------------------------- +# -------------------------------------------------------------------------------------------------- if __name__ == '__main__': try: - (files, destination, cover, tags, playlist) = get_options(PROGRAM, DESCRIPTION, True) + #(files, destination, cover, tags, playlist) = get_options(PROGRAM, DESCRIPTION, True) + (files, destination) = get_options(PROGRAM, DESCRIPTION, True) output_files = [] for item in files: - output_file = encode_flac_mp3(item, destination, cover, tags) + #output_file = encode_flac_mp3(item, destination, cover, tags) + output_file = encode_flac_mp3(item, destination) if output_file: output_files.append(output_file) diff --git a/flac2wav.py b/flac2wav.py index 7619bda..c7f414d 100755 --- a/flac2wav.py +++ b/flac2wav.py @@ -9,27 +9,29 @@ """ # Module import -# ------------------------------------------------------------------------------------------------- -from audio import decode_flac_wav, write_tags -from general import keyboard_interrupt -from interface import get_options +# -------------------------------------------------------------------------------------------------- +from library.audio import decode_flac_wav, write_tags +from library.general import keyboard_interrupt +from library.interface import get_options # Constants -# ------------------------------------------------------------------------------------------------- +# -------------------------------------------------------------------------------------------------- PROGRAM = 'flac2wav' DESCRIPTION = 'Decodes FLAC files into the WAV format' # Methods :: Execution and boilerplate -# ------------------------------------------------------------------------------------------------- +# -------------------------------------------------------------------------------------------------- if __name__ == '__main__': try: - (files, destination, cover, tags, playlist) = get_options(PROGRAM, DESCRIPTION, True) + #(files, destination, cover, tags, playlist) = get_options(PROGRAM, DESCRIPTION, True) + (files, destination) = get_options(PROGRAM, DESCRIPTION, True) output_files = [] for item in files: - output_file = decode_flac_wav(item, destination, cover, tags) + #output_file = decode_flac_wav(item, destination, cover, tags) + output_file = decode_flac_wav(item, destination) if output_file: output_files.append(output_file[0]) diff --git a/library/audio.py b/library/audio.py index 3027bf2..c3b81f4 100755 --- a/library/audio.py +++ b/library/audio.py @@ -10,7 +10,7 @@ # Module import # -------------------------------------------------------------------------------------------------- -from general import is_string_empty, update_extension, update_path +from library.general import is_string_empty, update_extension, update_path from enum import Enum from json import dump, load diff --git a/library/interface.py b/library/interface.py index a2b13f0..24e698f 100755 --- a/library/interface.py +++ b/library/interface.py @@ -23,6 +23,7 @@ ERROR = "{} '{}' is not available (doesn't exist or no privileges to access it)!" ERROR_INVALID = "{} '{}' is invalid!" ERROR_INVALID_LIST = 'The list of input files is invalid!' +ERROR_EMPTY_LIST = 'The list of input files is empty!' # Project information @@ -113,18 +114,19 @@ def parse_options(program, description, decode=False): parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + __version__) # TODO: keeping only the parameters for input files and output location because they will only # be tackled in a future version - #parser.add_argument('-p', '--playlist', action='store_true', default='False', - # help='create playlist file') - #tags_help = '{} ID3 tags'.format('extract' if decode else 'add') - #parser.add_argument('-t', '--tags', action='store_true', help=tags_help) - #cover_help = '{} album art' - #if decode: - # parser.add_argument('-c', '--cover', action='store_true', - # help=cover_help.format('extract')) - #else: - # parser.add_argument('-c', '--cover', metavar='IMG', dest='cover', - # help=cover_help.format('add')) - + """ + parser.add_argument('-p', '--playlist', action='store_true', default='False', + help='create playlist file') + tags_help = '{} ID3 tags'.format('extract' if decode else 'add') + parser.add_argument('-t', '--tags', action='store_true', help=tags_help) + cover_help = '{} album art' + if decode: + parser.add_argument('-c', '--cover', action='store_true', + help=cover_help.format('extract')) + else: + parser.add_argument('-c', '--cover', metavar='IMG', dest='cover', + help=cover_help.format('add')) + """ group = parser.add_argument_group('options') group.add_argument('-f', '--files', nargs='+', metavar='FILES', dest='input_files', help='input files', required=True) @@ -148,14 +150,19 @@ def get_options(program, description, decode=False): # Checks the input files files = get_input_files(args.input_files) if len(files) == 0: - _logger.error('No files were provided!') + _logger.error(ERROR_EMPTY_LIST) sys.exit(1) # TODO: this bit needs to be completely reviewed! # Checks the output directory, cover and tag parameters + """ if not (directory_exists(args.output_dir) and not ( not decode and args.cover is not None and not file_exists(args.cover))): sys.exit(1) + """ + if not directory_exists(args.output_dir): + _logger.error(ERROR.format('Directory', args.output_dir)) + sys.exit(1) - return files, args.output_dir, args.cover, args.tags, args.playlist - + #return files, args.output_dir, args.cover, args.tags, args.playlist + return files, args.output_dir diff --git a/tests/interface_test.py b/tests/interface_test.py index 045d607..2d62652 100755 --- a/tests/interface_test.py +++ b/tests/interface_test.py @@ -60,7 +60,7 @@ def test_get_input_files_int(self): result = interface.get_input_files(123) self.assertEqual(result, []) - def test_get_input_files_int(self): + def test_get_input_files_boolean(self): result = interface.get_input_files(True) self.assertEqual(result, []) diff --git a/wav2flac.py b/wav2flac.py index a1d8dc6..608ff71 100755 --- a/wav2flac.py +++ b/wav2flac.py @@ -9,37 +9,40 @@ """ # Module import -# ------------------------------------------------------------------------------------------------- -from audio import encode_wav_flac, read_tags -from general import WARNING_NO_JSON_FILE, keyboard_interrupt -from interface import get_options -import logging +# -------------------------------------------------------------------------------------------------- +from library.audio import encode_wav_flac, read_tags +from library.general import WARNING_NO_JSON_FILE, keyboard_interrupt +from library.interface import get_options +#import logging # Logger -# ---------------------------------------------------------------------------------------------------------------------- -_logger = logging.getLogger(__name__) +# -------------------------------------------------------------------------------------------------- +#logging.basicConfig(level=logging.INFO) +#_logger = logging.getLogger(__name__) # Constants -# ------------------------------------------------------------------------------------------------- +# -------------------------------------------------------------------------------------------------- PROGRAM = 'wav2flac' DESCRIPTION = 'Encodes WAV files into the FLAC format with the maximum compression level' # Methods :: Execution and boilerplate -# ------------------------------------------------------------------------------------------------- +# -------------------------------------------------------------------------------------------------- if __name__ == '__main__': try: - (files, destination, cover, tags, playlist) = get_options(PROGRAM, DESCRIPTION) + #(files, destination, cover, tags, playlist) = get_options(PROGRAM, DESCRIPTION) + (files, destination) = get_options(PROGRAM, DESCRIPTION, True) output_files = [] for item in files: - file_tags = read_tags(item) if tags else None - if tags and not file_tags: - _logger.warn(WARNING_NO_JSON_FILE) + #file_tags = read_tags(item) if tags else None + #if tags and not file_tags: + # _logger.warn(WARNING_NO_JSON_FILE) - output_file = encode_wav_flac(item, destination, cover, file_tags) + #output_file = encode_wav_flac(item, destination, cover, file_tags) + output_file = encode_wav_flac(item, destination) if output_file: output_files.append(output_file[0]) diff --git a/wav2mp3.py b/wav2mp3.py index 22dab05..56dacc5 100755 --- a/wav2mp3.py +++ b/wav2mp3.py @@ -9,37 +9,40 @@ """ # Module import -# ------------------------------------------------------------------------------------------------- -from audio import encode_wav_mp3, read_tags -from general import WARNING_NO_JSON_FILE, keyboard_interrupt -from interface import get_options -import logging +# -------------------------------------------------------------------------------------------------- +from library.audio import encode_wav_mp3, read_tags +from library.general import WARNING_NO_JSON_FILE, keyboard_interrupt +from library.interface import get_options +#import logging # Logger -# ---------------------------------------------------------------------------------------------------------------------- -_logger = logging.getLogger(__name__) +# -------------------------------------------------------------------------------------------------- +#logging.basicConfig(level=logging.INFO) +#_logger = logging.getLogger(__name__) # Constants -# ------------------------------------------------------------------------------------------------- +# -------------------------------------------------------------------------------------------------- PROGRAM = 'wav2mp3' DESCRIPTION = 'Encodes WAV files into the MP3 format with the maximum compression level' # Methods :: Execution and boilerplate -# ------------------------------------------------------------------------------------------------- +# -------------------------------------------------------------------------------------------------- if __name__ == '__main__': try: - (files, destination, cover, tags, playlist) = get_options(PROGRAM, DESCRIPTION) + #(files, destination, cover, tags, playlist) = get_options(PROGRAM, DESCRIPTION) + (files, destination) = get_options(PROGRAM, DESCRIPTION, True) output_files = [] for item in files: - file_tags = read_tags(item) if tags else None - if tags and not file_tags: - _logger.warn(WARNING_NO_JSON_FILE) + #file_tags = read_tags(item) if tags else None + #if tags and not file_tags: + # _logger.warn(WARNING_NO_JSON_FILE) - output_file = encode_wav_mp3(item, destination, cover, file_tags) + #output_file = encode_wav_mp3(item, destination, cover, file_tags) + output_file = encode_wav_mp3(item, destination) if output_file: output_files.append(output_file[0])