python version: Python 3.6.3OSX 10.13Im very particular when it comes to file naming and was hoping to see an option to replace the separator from _ to a regular space.
eg:
Would like to see: Borgeous - Zero Gravity.mp3
instead of: Borgeous_-_Zero_Gravity.mp3
Having spaces in filenames is arguably bad style, because you then need to put filenames in "" when passing them to some shell command. (Just one of probably more cons).
The name conversion is done here: https://github.com/ritiek/spotify-downloader/blob/237b4cca7e78e679c8dee6a902bec72ac5be2005/core/misc.py#L91
You could simply comment out it there.
I don't think this is a feature we should implement right now, let's ask @ritiek.
I dont mind commenting out that line in the script if im in the minority on this. Is it worth, perhaps, having an option flag to choose the desired separator? Otherwise, my issue is solved based on commenting out Line 91. Thanks @linusg
If you could provide a PR we would most likely merge it, shouldn't be too hard to implement. But @ritiek is the boss in here anyway, so it's not my turn doing the final decisions :wink:
I'd accept a PR that adds an option to retain spaces in file name.
As much as i am "around" code, i'm not a coder myself (aside from bash scripting) so I wouldn't have the skillset to make that tweak :). Also, I spoke too soon on as far as my issue being resolved. Commenting out Line 91 removes the _ from the namespace but slugify removes spaces regardless. Trying to figure out how to make slugify allow a space:
slugify(title, ok='-_()[]{}', lower=False)
Shot in the dark: Adding a space to the string argument ok?
slugify(title, ok='-_()[]{} ', lower=False)
Adding a space there has no effect. Here is sample output:
Filename: Atmozfears-Release-Radio-Edit.mp3
With line 91 and 95 commented out i get the following output. I dont want to waste anyone else's time on this. Ultimately i just created a find/exec/move command that replaced the _ with a space for all the files within the output directory. Im sure a sed replacement command after conversion would solve this as well.
Mikes-MacBook-Pro-2:spotify-downloader MMelo$ python3 spotdl.py --list=hardstyle.txt -f "hardstyle/"
Total songs in list: 41 songs
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/mutagen/_util.py", line 218, in _openfile
fileobj = open(filename, "rb+" if writable else "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'hardstyle/Hardwell - Wake Up Call.mp3'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "spotdl.py", line 439, in
grab_list(text_file=args.list)
File "spotdl.py", line 306, in grab_list
grab_single(raw_song, number=number)
File "spotdl.py", line 414, in grab_single
metadata.embed(os.path.join(args.folder, output_song), meta_tags)
File "/Users/MMelo/github/spotify-downloader/core/metadata.py", line 36, in embed
return embed_mp3(music_file, meta_tags)
File "/Users/MMelo/github/spotify-downloader/core/metadata.py", line 45, in embed_mp3
audiofile = EasyID3(music_file)
File "/usr/local/lib/python3.6/site-packages/mutagen/easyid3.py", line 170, in __init__
self.load(filename)
File "/usr/local/lib/python3.6/site-packages/mutagen/_util.py", line 158, in wrapper
return func(args, *kwargs)
File "/usr/local/lib/python3.6/site-packages/mutagen/_util.py", line 128, in wrapper
writable, create) as h:
File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/contextlib.py", line 81, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.6/site-packages/mutagen/_util.py", line 227, in _openfile
raise MutagenError(e)
mutagen.MutagenError: [Errno 2] No such file or directory: 'hardstyle/Hardwell - Wake Up Call.mp3'
Spaces can be retained by replacing the slugify command with:
slugify(title, ok='-_()[]{}', lower=False, spaces=True)
However, this may not be as easy as it seems. One also needs to tweak the FFmpeg and avconv commands used for converting the song to .mp3 otherwise you'll get the file not found error.
Post conversion, I run this command manually on OS X within the Music output folder:
find . -type f -name "*.mp3" -exec bash -c 'mv "$0" "${0//_/ }"' {} \;
This replaces the default _ with a space.
Seems like a good option for all of us. I still think updating the code for allowing the spaces would be overkill, but we might mention this bash code in the README.md so others might use it too. @mmelosinewave @ritiek what do you think?
That should be fine. I think it's fairly universal across all *nix platforms. The above command assumes the user is within the same directory as the .mp3's.
Here we go: https://github.com/ritiek/spotify-downloader/blob/master/README.md#preserve-spaces-in-file-names
Amendment made to README to include a shell command that may be used to change all instances of _ in filenames with spaces.
If no other issues have arisen, close?
Probably a good idea. Done.
Most helpful comment
I'd accept a PR that adds an option to retain spaces in file name.