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
This commit is contained in:
Miguel Piedrafita
2018-01-15 09:11:11 +01:00
committed by Ritiek Malhotra
parent e283231f8e
commit 1fe94c9896
3 changed files with 11 additions and 12 deletions

View File

@@ -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

View File

@@ -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,

View File

@@ -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')