spotDL / spotify-downloader

Download your Spotify playlists and songs along with album art and metadata (from YouTube if a match is found).
https://spotdl.readthedocs.io/en/latest/
MIT License
17.6k stars 1.61k forks source link

Question: How to download music with the highest possible quality with spotdl 4.0.1? #1642

Closed ghost closed 2 years ago

ghost commented 2 years ago

Requested Feature

Hi developers! I recently updated spotdl to version 4.0.1 with python-pip And I've noticed that the way to download music with the highest possible quality has changed. As an example I have a song downloaded with spotdl 3.9.6 with 240 kbps (spotdl <url>) Now that same song using this new version has 128 kbps (spotdl download <url>)

Also in 3.9.6 this command was invoked using yt-dlp: yt-dlp -x --audio-format mp3 --audio-quality 0 <url> But in 4.0.1 this doesn't seem to be the case.

Could any of you help me with this. Thanks!

Possible implementation

No response

pascalandy commented 2 years ago

+1

I confirm the bitrate is at 128kbps. I used docker spotdl/spotify-downloader download

StarrKiss commented 2 years ago

Same issue with me - before it was at auto-highest. How do I fix this or do I need to downgrade?

xnetcat commented 2 years ago

Spotdl never downloads songs in bitrate higher than 128kbps (you can get 256 kbps with ytmusic premium and m4a output format).

In V3 spotdl would re-encode the song with variable bitrate (FFmpeg option -q:a 0). I’ve removed this option in V4 because bitrate option was added so now users can specify the bitrate that they want.

StarrKiss commented 2 years ago

Spotdl never downloads songs in bitrate higher than 128kbps (you can get 256 kbps with ytmusic premium and m4a output format).

In V3 spotdl would re-encode the song with variable bitrate (FFmpeg option -q:a 0). I’ve removed this option in V4 because bitrate option was added so now users can specify the bitrate that they want.

yt-dlp with the best audio option ( yt-dlp -x --audio-format mp3 --audio-quality 0 ) can generate noticeable better AND higher bit rate songs. Also, I don't think that that's the case, since the bitrate seems to vary between songs semi-randomly, not stay at 128kpbs in my library - image

ghost commented 2 years ago

Spotdl never downloads songs in bitrate higher than 128kbps (you can get 256 kbps with ytmusic premium and m4a output format).

In V3 spotdl would re-encode the song with variable bitrate (FFmpeg option -q:a 0). I’ve removed this option in V4 because bitrate option was added so now users can specify the bitrate that they want.

I confirm, you can use this command to download your music at 320k kbps (only conversion format not download): spotdl --bitrate 320k download <url>

ghost commented 2 years ago

Also, I don't think that that's the case, since the bitrate seems to vary between songs semi-randomly, not stay at 128kpbs in my library -

I think this is due to ffmpeg. audio-quality 0 performs a higher bit conversion. However this doesn't seem to affect the source (128k, 192k or 256k).

xnetcat commented 2 years ago

Spotdl never downloads songs in bitrate higher than 128kbps (you can get 256 kbps with ytmusic premium and m4a output format). In V3 spotdl would re-encode the song with variable bitrate (FFmpeg option -q:a 0). I’ve removed this option in V4 because bitrate option was added so now users can specify the bitrate that they want.

yt-dlp with the best audio option ( yt-dlp -x --audio-format mp3 --audio-quality 0 ) can generate noticeable better AND higher bit rate songs. Also, I don't think that that's the case, since the bitrate seems to vary between songs semi-randomly, not stay at 128kpbs in my library - image

--audio-quality 0 basically just adds -q:a 0 to ffmpeg options for post-processing step.

I can re-add add option to use variable bitrate when re-encoding the songs, but I won't set is as default because I don't want to mislead users into believing that they are getting better quality songs because the bitrate is higher.

ghost commented 2 years ago

I can re-add add option to use variable bitrate when re-encoding the songs

That sound good! To be honest, I feel more comfortable with that option :D The --bitrate <kbps> option is also nice, please don't remove it, just consider re-adding by default the variable bitrate when calling spotdl download <url>

xnetcat commented 2 years ago

I can re-add add option to use variable bitrate when re-encoding the songs

That sound good! To be honest, I feel more comfortable with that option :D The --bitrate <kbps> option is also nice, please don't remove it, just consider re-adding by default the variable bitrate when calling spotdl download <url>

I will add the vbr option to the bitrate flag (I wasn't planning to remove it). I am not sure if I want to set is as default option for FFmpeg encoding, because producing higher bitrate files that are 2x bigger and don't have any significant change in quality isn't worth it in my opinion. Besides you can use config file to change the bitrate permanently.

ghost commented 2 years ago

I will add the vbr option to the bitrate flag (I wasn't planning to remove it).

Cool! The config file is a great idea. I guess it's okay to add the vbr as a tag, I have no problem with it. Thanks for taking it into account! :D

pascalandy commented 2 years ago

I confirm it works :

docker run --rm -v $(pwd):/music spotdl/spotify-downloader --bitrate 320k download \
https://open.spotify.com/playlist/xyz
pascalandy commented 2 years ago

Would it be possible to keep the vorbis format without any conversion to mp3 ?

xnetcat commented 2 years ago

Would it be possible to keep the vorbis format without any conversion to mp3 ?

What do you mean by this, the files we download from youtube are either webm/m4a. If you don't want any conversion you can use --format flac/m4a because they don't re-encode the files (also they are way faster because ffmpeg only copies the audio stream from one file to another)

pascalandy commented 2 years ago

What do you mean by this, the files we download from youtube are either webm/m4a. If you don't want any conversion you can use --format flac/m4a because they don't re-encode the files (also they are way faster because ffmpeg only copies the audio stream from one file to another)

I thought this app was downloading files from Spotify :-p . My bad.

xnetcat commented 2 years ago

Variable bitrate option has been added in v4.0.2, also now files should have slightly better bitrate in some cases than in the previous versions.

jicart commented 1 year ago

Would it be possible to keep the vorbis format without any conversion to mp3 ?

What do you mean by this, the files we download from youtube are either webm/m4a. If you don't want any conversion you can use --format flac/m4a because they don't re-encode the files (also they are way faster because ffmpeg only copies the audio stream from one file to another)

Just found your comment. Yesterday I opened an feature request because I couldn't find a way to avoid the ffmpeg conversion. I did try using "--format m4a" and not specifying bitrate, but conversion is made anyway. Could this be a bug?

ghost commented 1 year ago

Have you tried changing "ffmpeg" to "false" in the config.json file? (Linux path: $HOME/.spotdl)

jicart commented 1 year ago

Have you tried changing "ffmpeg" to "false" in the config.json file? (Linux path: $HOME/.spotdl)

Just did. Setting it to "false" gives me an error: FFmpegError: FFmpeg is not installed. Please run spotdl --download-ffmpeg to install it, or spotdl --ffmpeg /path/to/ffmpeg to specify the path to ffmpeg.

Setting it to false (unquoted) returns: TypeError: expected str, bytes or os.PathLike object, not bool

I'm on Windows, python 3.11, spotdl 4.0.5. command is: spotdl download {link} --format "m4a"

I've also tried on spotdl 3.9.5 and by setting the format as "m4a" it does skip conversion.

ghost commented 1 year ago

I did a search in the repository and found this thread. Basically there are no plans to implement this option; spotdl will always use ffmpeg. You can edit "format": "mp3" to "m4a", if you want to get this format.

If you don't know what changes you made in config.json, I recommend to use: spotdl --generate-config, to return to default values and edit only this option.

I hope this is helpful.

jicart commented 1 year ago

Thank you for your answer. Looking at the code I think I understand what's happening. Because of the if statement on: https://github.com/spotDL/spotify-downloader/blob/8f7cb2a7ab13f1244d1b9abc6635ccaa14b01ba7/spotdl/download/downloader.py#L448

self.bitrate is being set at 129k. This means when the function convert is called, bitrate has a value. So https://github.com/spotDL/spotify-downloader/blob/8f7cb2a7ab13f1244d1b9abc6635ccaa14b01ba7/spotdl/utils/ffmpeg.py#L285 is False, so the args that tells ffmpeg to copy the stream are not being passed.

I've commented out the if statement on line 448 in downloader.py, and conversion is now being disabled (since I specify "m4a" as the format).

I'm not sure if this change breaks something else, but it is working for me.

ghost commented 1 year ago

Great! I guess this would be a temporary solution. Let's see what happens, and as you say hopefully the change won't break the code.

xnetcat commented 1 year ago

Would it be possible to keep the vorbis format without any conversion to mp3 ?

What do you mean by this, the files we download from youtube are either webm/m4a. If you don't want any conversion you can use --format flac/m4a because they don't re-encode the files (also they are way faster because ffmpeg only copies the audio stream from one file to another)

Just found your comment. Yesterday I opened an feature request because I couldn't find a way to avoid the ffmpeg conversion. I did try using "--format m4a" and not specifying bitrate, but conversion is made anyway. Could this be a bug?

That's a bug, next version will add --preserve-audio option to skip the conversion step for m4a and opus files.

Converted007 commented 1 year ago

Variable bitrate option has been added in v4.0.2, also now files should have slightly better bitrate in some cases than in the previous versions.

Hi, im using the .exe 406 windows file but besides the mp3 option i cant change the bitrate to 320kbps? When using cli there isnt an options choice... And the download only downloads 128kbps files. Is this normal or can this be changed?

xnetcat commented 1 year ago

Variable bitrate option has been added in v4.0.2, also now files should have slightly better bitrate in some cases than in the previous versions.

Hi, im using the .exe 406 windows file but besides the mp3 option i cant change the bitrate to 320kbps? When using cli there isnt an options choice... And the download only downloads 128kbps files. Is this normal or can this be changed?

what does spotdl --help return?

Converted007 commented 1 year ago

Variable bitrate option has been added in v4.0.2, also now files should have slightly better bitrate in some cases than in the previous versions.

Hi, im using the .exe 406 windows file but besides the mp3 option i cant change the bitrate to 320kbps? When using cli there isnt an options choice... And the download only downloads 128kbps files. Is this normal or can this be changed?

what does spotdl --help return?

Found it. Changed bitrate to 320K in the config file. Thanks