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.03k stars 1.56k forks source link

Allow specifying which format id to download and allow transcoding for Opus #2079

Closed Ciancy28 closed 1 month ago

Ciancy28 commented 4 months ago

Requested Feature

currently, when m4a or Opus is set as format in config.json, the highest quality version available is chosen and (in case of opus) the "bitrate" field is ignored (despite the documentation suggesting otherwise). This has become a problem for me now that youtube is starting to roll out 256 kbps Opus (format id 774) to youtube music uploads even for non-premium users, as spotdl now downloads these needlessly bloated files (opus is already beyond transparency at 128 kbps for most people including me), and there's no easy way of lossy to lossy transcoding either (which wouldn't be ideal anyways for obvious reasons). There might also be a need for some people to download lower quality audio such as 64 kbps opus/he-aac (maybe for playback on storage-constrained mobile devices), which again, doesn't seem to be possible currently. Another edge case were this is a problem would be people using premium cookies for access to songs unavailable without music premium (very few but there are some) but without the need for 256 kbps aac, from my understanding, in this case you would be forced to get 256 kbps aac audio even if you are perfectly happy with 128 kbps opus and prefer that format. I've been trying to get format 251 back for the past two hours with no luck, even using yt-dlp args, but the software just keeps downloading format 774 no matter what (trying to download this album: https://open.spotify.com/album/0qws44dIANrXaaErn7kGCW, which apparently has every track available in this new format).

Possible implementation

add a "format_id": field to config.json and make "bitrate": functional for opus transcoding (only seems to work for m4a) or maybe add a "high_quality": true/false field instead, which enables/disables downloading of format 774/141, this would make sense disabled by default imo.

Ciancy28 commented 4 months ago

Looks like youtube removed access to format 774 for non premium users today, but I'm keeping the issue open as most of it is still relevant

jnxr commented 4 months ago

Yeah, a format ID priority feature would be awesome. eg:

--format-id-priority 774,141,251

This would be mine for example^

jnxr commented 4 months ago

It would for example try to download format 774 at first, if no 774 is found, then switch to 141, if no 141, then 251, and so on.

EDIT: I briefly mentioned it in #1845 as Format Priority. This would ensure that people get their preferred format.

xnetcat commented 1 month ago

I've been trying to get format 251 back for the past two hours with no luck, even using yt-dlp args, but the software just keeps downloading format 774 no matter what

I have just fixed yt-dlp-args. It was created with this situation in mind, yt-dlp can already handle this in wayyyy better way then I could ever implement.

--format-id-priority 774,141,251

--yt-dlp-args "--format 774/141/251/bestaudio" # bestaudio is a fallback format

image


PS C:\Users\jakub\OneDrive\Documents\GitHub\spotify-downloader> spotdl --format opus --bitrate "auto" open.spotify.com/track/2xUsXYIiK18wSnv2SXFGtj --overwrite force --yt-dlp-args "--format 69/251/bestaudio" --log-level DEBUG
[02:21:18] DEBUG    MainThread - Downloader settings: {'audio_providers': ['youtube-music'], 'lyrics_providers': ['genius', 'azlyrics', 'musixmatch'], 'playlist_numbering': False, downloader.py:131
                    'scan_for_songs': False, 'm3u': None, 'output': '{artists} - {title}.{output-ext}', 'overwrite': 'force', 'search_query': None, 'ffmpeg': 'ffmpeg', 'bitrate':  
                    'auto', 'ffmpeg_args': None, 'format': 'opus', 'save_file': None, 'filter_results': True, 'album_type': None, 'threads': 4, 'cookie_file': None, 'restrict':    
                    None, 'print_errors': False, 'sponsor_block': False, 'preload': False, 'archive': None, 'load_config': True, 'log_level': 'DEBUG', 'simple_tui': False,
                    'fetch_albums': False, 'id3_separator': '/', 'ytm_data': False, 'add_unavailable': False, 'generate_lrc': False, 'force_update_metadata': False,
                    'only_verified_results': False, 'sync_without_deleting': False, 'max_filename_length': None, 'yt_dlp_args': '--format 69/251/bestaudio', 'detect_formats':      
                    None, 'save_errors': None, 'ignore_albums': None, 'proxy': None, 'skip_explicit': False, 'log_format': None, 'redownload': False, 'skip_album_art': False,      
                    'create_skip_file': False, 'respect_skip_file': False, 'sync_remove_lrc': False}
[02:21:18] DEBUG    MainThread - FFmpeg path: ffmpeg                                                                                                                                downloader.py:149
[02:21:18] DEBUG    MainThread - Found 0 known songs                                                                                                                                downloader.py:184
[02:21:20] DEBUG    MainThread - Archive: 0 urls                                                                                                                                    downloader.py:231
[02:21:20] DEBUG    MainThread - Downloader initialized                                                                                                                             downloader.py:233
[02:21:20] INFO     MainThread - Processing query: open.spotify.com/track/2xUsXYIiK18wSnv2SXFGtj                                                                                        search.py:137
[02:21:20] DEBUG    MainThread - Found 1 songs in 0 lists                                                                                                                               search.py:339
[02:21:20] DEBUG    MainThread - Downloading 1 songs                                                                                                                                downloader.py:280
[02:21:21] DEBUG    asyncio_0 - Genius failed to find lyrics for NTO - Invisible - Paul Kalkbrenner Remix                                                                           downloader.py:406
[02:21:22] DEBUG    asyncio_0 - AzLyrics failed to find lyrics for NTO - Invisible - Paul Kalkbrenner Remix                                                                         downloader.py:406
[02:21:23] DEBUG    asyncio_0 - MusixMatch failed to find lyrics for NTO - Invisible - Paul Kalkbrenner Remix                                                                       downloader.py:406
[02:21:23] DEBUG    asyncio_0 - No lyrics found for NTO - Invisible - Paul Kalkbrenner Remix, lyrics providers: Genius, AzLyrics, MusixMatch                                        downloader.py:568
[02:21:23] DEBUG    asyncio_0 - [2xUsXYIiK18wSnv2SXFGtj] Searching for nto, paul kalkbrenner - invisible - paul kalkbrenner remix                                                         base.py:168
[02:21:23] DEBUG    asyncio_0 - [2xUsXYIiK18wSnv2SXFGtj] Found 1 results for ISRC FR9W12104641                                                                                            base.py:181
[02:21:23] DEBUG    asyncio_0 - [2xUsXYIiK18wSnv2SXFGtj] Filtered to 1 ISRC results                                                                                                       base.py:193
[02:21:23] DEBUG    asyncio_0 - [2xUsXYIiK18wSnv2SXFGtj] Best ISRC result is https://music.youtube.com/watch?v=vGKDEPiYnuE with score 100.0                                               base.py:202
[02:21:23] DEBUG    asyncio_0 - Downloading NTO - Invisible - Paul Kalkbrenner Remix using https://music.youtube.com/watch?v=vGKDEPiYnuE                                            downloader.py:656
[02:21:31] INFO     asyncio_0 - Downloaded "NTO - Invisible - Paul Kalkbrenner Remix": https://music.youtube.com/watch?v=vGKDEPiYnuE                                                downloader.py:830
[02:21:31] DEBUG    MainThread - Took 11 seconds                                                                                                                                   entry_point.py:182

PS C:\Users\jakub\OneDrive\Documents\GitHub\spotify-downloader> ffprobe.exe '.\NTO, Paul Kalkbrenner - Invisible - Paul Kalkbrenner Remix.opus'
ffprobe version 6.0-full_build-www.gyan.dev Copyright (c) 2007-2023 the FFmpeg developers
  built with gcc 12.2.0 (Rev10, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libaribb24 --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libvpl --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
  libavutil      58.  2.100 / 58.  2.100
  libavcodec     60.  3.100 / 60.  3.100
  libavformat    60.  3.100 / 60.  3.100
  libavdevice    60.  1.100 / 60.  1.100
  libavfilter     9.  3.100 /  9.  3.100
  libswscale      7.  1.100 /  7.  1.100
  libswresample   4. 10.100 /  4. 10.100
  libpostproc    57.  1.100 / 57.  1.100
[ogg @ 000002a161ef6b00] 9106 bytes of comment header remain
Input #0, ogg, from '.\NTO, Paul Kalkbrenner - Invisible - Paul Kalkbrenner Remix.opus':
  Duration: 00:07:37.07, start: 0.007500, bitrate: 143 kb/s
  Stream #0:0(eng): Audio: opus, 48000 Hz, stereo, fltp
    Metadata:
      encoder         : Lavf60.3.100
      artist          : NTO;Paul Kalkbrenner
      album_artist    : NTO
      title           : Invisible - Paul Kalkbrenner Remix
      date            : 2021-04-14
      encodedby       : AllPoints
      album           : Invisible (Paul Kalkbrenner Remix)
      genre           : Deep Euro House
      copyright       : 2021 AllPoints
      comment         : https://music.youtube.com/watch?v=vGKDEPiYnuE
      disc            : 1
      disctotal       : 1
      tracktotal      : 1
      track           : 1
      woas            : https://open.spotify.com/track/2xUsXYIiK18wSnv2SXFGtj
      isrc            : FR9W12104641
  Stream #0:1: Video: mjpeg (Baseline), yuvj444p(pc, bt470bg/unknown/unknown), 640x640 [SAR 72:72 DAR 1:1], 90k tbr, 90k tbn (attached pic)
    Metadata:
      comment         : Cover (front)
      title           : Cover
PS C:\Users\jakub\OneDrive\Documents\GitHub\spotify-downloader> yt-dlp -F https://music.youtube.com/watch?v=vGKDEPiYnuE
[youtube] Extracting URL: https://music.youtube.com/watch?v=vGKDEPiYnuE 
[youtube] vGKDEPiYnuE: Downloading webpage
[youtube] vGKDEPiYnuE: Downloading ios player API JSON 
[youtube] vGKDEPiYnuE: Downloading ios music player API JSON 
[youtube] vGKDEPiYnuE: Downloading web music client config 
[youtube] vGKDEPiYnuE: Downloading player 0e90208b 
[youtube] vGKDEPiYnuE: Downloading web music player API JSON 
[youtube] vGKDEPiYnuE: Downloading m3u8 information 
[youtube] vGKDEPiYnuE: Downloading m3u8 information 
[info] Available formats for vGKDEPiYnuE: 
ID  EXT   RESOLUTION FPS CH │    FILESIZE   TBR PROTO │ VCODEC          VBR ACODEC      ABR ASR MORE INFO
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────
sb3 mhtml 48x27        0    │                   mhtml │ images                                  storyboard
sb2 mhtml 45x45        0    │                   mhtml │ images                                  storyboard
sb1 mhtml 90x90        0    │                   mhtml │ images                                  storyboard
sb0 mhtml 180x180      0    │                   mhtml │ images                                  storyboard
233 mp4   audio only        │                   m3u8  │ audio only          unknown             Default
234 mp4   audio only        │                   m3u8  │ audio only          unknown             Default
139 m4a   audio only      2 │     2.66MiB   49k https │ audio only          mp4a.40.5   49k 22k low, m4a_dash
249 webm  audio only      2 │     2.96MiB   54k https │ audio only          opus        54k 48k low, webm_dash
250 webm  audio only      2 │     3.91MiB   72k https │ audio only          opus        72k 48k low, webm_dash
140 m4a   audio only      2 │     7.06MiB  130k https │ audio only          mp4a.40.2  130k 44k medium, m4a_dash
251 webm  audio only      2 │     7.81MiB  143k https │ audio only          opus       143k 48k medium, webm_dash
602 mp4   144x144     13    │ ~   3.70MiB   68k m3u8  │ vp09.00.10.08   68k video only
394 mp4   144x144     25    │  1003.90KiB   18k https │ av01.0.00M.08   18k video only          144p, mp4_dash
269 mp4   144x144     25    │ ~   3.48MiB   64k m3u8  │ avc1.4D400B     64k video only
160 mp4   144x144     25    │   362.75KiB    7k https │ avc1.4D400B      7k video only          144p, mp4_dash
603 mp4   144x144     25    │ ~   4.69MiB   86k m3u8  │ vp09.00.11.08   86k video only
278 webm  144x144     25    │   678.67KiB   12k https │ vp9             12k video only          144p, webm_dash
395 mp4   240x240     25    │     1.85MiB   34k https │ av01.0.00M.08   34k video only          240p, mp4_dash
229 mp4   240x240     25    │ ~   3.76MiB   69k m3u8  │ avc1.4D400C     69k video only
133 mp4   240x240     25    │   445.15KiB    8k https │ avc1.4D400C      8k video only          240p, mp4_dash
604 mp4   240x240     25    │ ~   7.08MiB  130k m3u8  │ vp09.00.20.08  130k video only
242 webm  240x240     25    │     1.31MiB   24k https │ vp9             24k video only          240p, webm_dash
396 mp4   360x360     25    │     3.30MiB   61k https │ av01.0.00M.08   61k video only          360p, mp4_dash
230 mp4   360x360     25    │ ~   8.94MiB  164k m3u8  │ avc1.4D4015    164k video only
134 mp4   360x360     25    │   604.99KiB   11k https │ avc1.4D4015     11k video only          360p, mp4_dash
18  mp4   360x360     25  2 │ ≈   7.62MiB  140k https │ avc1.42001E         mp4a.40.2       44k 360p
605 mp4   360x360     25    │ ~  15.38MiB  282k m3u8  │ vp09.00.21.08  282k video only
243 webm  360x360     25    │     2.33MiB   43k https │ vp9             43k video only          360p, webm_dash
397 mp4   480x480     25    │     6.41MiB  118k https │ av01.0.01M.08  118k video only          480p, mp4_dash
231 mp4   480x480     25    │ ~   9.88MiB  181k m3u8  │ avc1.4D401E    181k video only
135 mp4   480x480     25    │   892.84KiB   16k https │ avc1.4D401E     16k video only          480p, mp4_dash
606 mp4   480x480     25    │ ~  22.75MiB  418k m3u8  │ vp09.00.30.08  418k video only
244 webm  480x480     25    │     4.37MiB   80k https │ vp9             80k video only          480p, webm_dash
398 mp4   720x720     25    │    16.32MiB  300k https │ av01.0.04M.08  300k video only          720p, mp4_dash
232 mp4   720x720     25    │ ~  11.53MiB  212k m3u8  │ avc1.4D401F    212k video only
136 mp4   720x720     25    │     1.34MiB   25k https │ avc1.4D401F     25k video only          720p, mp4_dash
609 mp4   720x720     25    │ ~  44.84MiB  823k m3u8  │ vp09.00.31.08  823k video only
247 webm  720x720     25    │    10.55MiB  194k https │ vp9            194k video only          720p, webm_dash
399 mp4   1080x1080   25    │    29.97MiB  550k https │ av01.0.08M.08  550k video only          1080p, mp4_dash
270 mp4   1080x1080   25    │ ~  52.64MiB  966k m3u8  │ avc1.640020    966k video only
137 mp4   1080x1080   25    │    11.72MiB  215k https │ avc1.640020    215k video only          1080p, mp4_dash
614 mp4   1080x1080   25    │ ~  89.22MiB 1638k m3u8  │ vp09.00.40.08 1638k video only
248 webm  1080x1080   25    │    15.92MiB  292k https │ vp9            292k video only          1080p, webm_dash
616 mp4   1080x1080   25    │ ~  99.89MiB 1834k m3u8  │ vp09.00.40.08 1834k video only          Premium

Keep in mind you have to use correct format/bitrate combination to get the wanted file.

Check spotdl --help / --bitrate for more info. And https://spotdl.readthedocs.io/en/latest/usage/#youtube-music-premium

jnxr commented 1 month ago

@xnetcat , About the yt-dlp args -> when --format is not specified, it defaults to mp3. Doesn't use the args specified. And when --format is specified, it again ignores the yt-dlp format priority args & just downloads the format specified. How do you get it to fallback according to the format priority args? eg. [--yt-dlp-args "--format 774/141/251/bestaudio"]