Skip to content

Commit

Permalink
Commented references to tags, covers and playlists. Reviewed the unit…
Browse files Browse the repository at this point in the history
… tests for the interface module. Updated references to the library modules to reflect their new location.
  • Loading branch information
Eduardo Ferreira committed Aug 25, 2016
1 parent 7b23cdc commit f608a9a
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 61 deletions.
18 changes: 10 additions & 8 deletions flac2mp3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
18 changes: 10 additions & 8 deletions flac2wav.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down
2 changes: 1 addition & 1 deletion library/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 22 additions & 15 deletions library/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
2 changes: 1 addition & 1 deletion tests/interface_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, [])

Expand Down
31 changes: 17 additions & 14 deletions wav2flac.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down
31 changes: 17 additions & 14 deletions wav2mp3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down

0 comments on commit f608a9a

Please sign in to comment.