From 1fe94c9896a236ce9edd8cadc978941b4c6a0b50 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Mon, 15 Jan 2018 09:11:11 +0100 Subject: [PATCH] Add a config option to preserve spaces in file names (#201) * Add a config option to preserve spaces in file names * Typo * Fix replacing in path --- README.md | 14 ++------------ core/handle.py | 5 +++++ spotdl.py | 4 ++++ 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 0f4dd57..67ca491 100755 --- a/README.md +++ b/README.md @@ -129,6 +129,8 @@ optional arguments: -d, --dry-run Show only track title and YouTube URL (default: False) -mo, --music-videos-only Search only for music on Youtube (default: False) + -ps, --preserve-spaces + Preserve spaces on file names (default: False) -ll {INFO,WARNING,ERROR,DEBUG}, --log-level {INFO,WARNING,ERROR,DEBUG} set log verbosity (default: INFO) ``` @@ -244,18 +246,6 @@ If you don't want to download all the songs to the `Music/` folder relative to t E.g. `$ python3 spotdl.py -s "adele hello" -f "/home/user/Music/"`. This works with both relative and absolute paths. -#### Preserve Spaces in File Names - -Beside some other characters, spaces will be replaced by underscores. -There's no option to change this behavior in spotify-downloader itself, -but on Unix-based operating systems you can issue the following bash -command after downloading is done: -``` -$ find . -type f -name "*.mp3" -exec bash -c 'mv "$0" "${0//_/ }"' {} \; -``` - -Just make sure your working directory is the one you have the music files in. - ## Config File At first run, this tool will generate a `config.yml` in root directory diff --git a/core/handle.py b/core/handle.py index e705710..2a6c7b2 100644 --- a/core/handle.py +++ b/core/handle.py @@ -19,6 +19,7 @@ default_conf = { 'spotify-downloader': 'download-only-metadata' : False, 'dry-run' : False, 'music-videos-only' : False, + 'preserve-spaces' : False, 'log-level' : 'INFO' } } @@ -107,6 +108,10 @@ def get_arguments(to_group=True, raw_args=None): '-mo', '--music-videos-only', default=config['music-videos-only'], help='Search only for music on Youtube', action='store_true') + parser.add_argument( + '-ps', '--preserve-spaces', default=config['preserve-spaces'], + help='Preserve spaces on file names', + action='store_true') parser.add_argument( '-ll', '--log-level', default=config['log-level'], choices=_LOG_LEVELS_STR, diff --git a/spotdl.py b/spotdl.py index 66ded32..4dbc405 100755 --- a/spotdl.py +++ b/spotdl.py @@ -186,6 +186,10 @@ 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')