Save file names using a custom format specifiers (#205)

* Use custom formats to generate file name

* Do not mess up search term

* Fix tests

* Fix conflicting names

* Fix subprocess call on file paths with spaces

* Create directories and keep spaces as defaults

* Fix config merge

* Remove underscores from default file format

* Remove debug info

* Show possible formats in usage help
This commit is contained in:
Ritiek Malhotra
2018-01-19 13:58:27 +05:30
committed by GitHub
parent ed235610ad
commit fcfebc55e6
11 changed files with 145 additions and 95 deletions

View File

@@ -28,8 +28,7 @@ def check_exists(music_file, raw_song, meta_tags):
os.remove(os.path.join(const.args.folder, song))
continue
# check if any song with similar name is already present in the given folder
file_name = internals.sanitize_title(music_file)
if song.startswith(file_name):
if song.startswith(music_file):
log.debug('Found an already existing song: "{}"'.format(song))
if internals.is_spotify(raw_song):
# check if the already downloaded song has correct metadata
@@ -152,23 +151,24 @@ def grab_single(raw_song, number=None):
songname = content.title
if meta_tags is not None:
refined_songname = internals.generate_songname(meta_tags)
refined_songname = internals.generate_songname(const.args.file_format, meta_tags)
log.debug('Refining songname from "{0}" to "{1}"'.format(songname, refined_songname))
if not refined_songname == ' - ':
songname = refined_songname
else:
log.warning('Could not find metadata')
songname = internals.sanitize_title(songname)
if const.args.dry_run:
return
file_name = internals.sanitize_title(songname)
if not check_exists(file_name, raw_song, meta_tags):
if youtube_tools.download_song(file_name, content):
input_song = file_name + const.args.input_ext
output_song = file_name + const.args.output_ext
if not check_exists(songname, raw_song, meta_tags):
# deal with file formats containing slashes to non-existent directories
songpath = os.path.join(const.args.folder, os.path.dirname(songname))
os.makedirs(songpath, exist_ok=True)
if youtube_tools.download_song(songname, content):
input_song = songname + const.args.input_ext
output_song = songname + const.args.output_ext
print('')
try:
@@ -178,7 +178,7 @@ def grab_single(raw_song, number=None):
encoder = 'avconv' if const.args.avconv else 'ffmpeg'
log.warning('Could not find {0}, skipping conversion'.format(encoder))
const.args.output_ext = const.args.input_ext
output_song = file_name + const.args.output_ext
output_song = songname + const.args.output_ext
if not const.args.input_ext == const.args.output_ext:
os.remove(os.path.join(const.args.folder, input_song))
@@ -186,10 +186,6 @@ def grab_single(raw_song, number=None):
if not const.args.no_metadata and meta_tags is not None:
metadata.embed(os.path.join(const.args.folder, output_song), meta_tags)
if const.args.preserve_spaces and "_" in output_song:
song_path = os.path.join(const.args.folder, output_song.replace('_', ' '))
os.rename(os.path.join(const.args.folder, output_song), song_path)
else:
log.error('No audio streams available')