ホーム / z - How To / ひさしぶりに SpotDL を使ったら、仕様が変わっていて少しハマった話

ひさしぶりに SpotDL を使ったら、仕様が変わっていて少しハマった話

ブログ記事を自分の記憶代わりにもしている筆者であるが、今回久しぶりにspotDLで曲をダウンロードしようとしたら、すっかり仕様が変わっていて、少しハマったので備忘録としてメモしておく。

今回ハマったポイントは以下である。

  • SpotDL は サブコマンド必須 になっていた
  • URL(query)の 置き場所が非常にシビア

それでは説明していこう。

はじめに:SpotDL、久々に触ると地味に罠がある

ちなみに以前に書いた記事はこちらである。日付を見たら3年も前だった。
内容は忘れてもなんとなく書いた記憶だけは残っている筆者である(笑)

今回は過去の記事を頼りに、以下で実施したらエラー。

$ spotdl [URL]

エラーの内容は以下である。

Your application has reached a rate/request limit
Max Retries reached
ResponseError: too many 404 error responses

一見すると、

  • Spotify API の制限?
  • YouTube 側の404?
  • ネットワーク?

と疑いたくなるが、実は根本原因はそこではなかった


SpotDL は「サブコマンド必須」になっていた

現在の SpotDL は、CLI構造がこうなっている。

spotdl {download, save, sync, meta, url} query
❯ spotdl --help
usage: spotdl [-h] [--audio [{youtube,youtube-music,soundcloud,bandcamp,piped} ...]] [--lyrics [{genius,musixmatch,azlyrics,synced} ...]] [--genius-access-token GENIUS_TOKEN]
              [--config] [--search-query SEARCH_QUERY] [--dont-filter-results] [--album-type {single,album,compilation}] [--only-verified-results] [--user-auth]
              [--client-id CLIENT_ID] [--client-secret CLIENT_SECRET] [--auth-token AUTH_TOKEN] [--cache-path CACHE_PATH] [--no-cache] [--max-retries MAX_RETRIES] [--headless]
              [--use-cache-file] [--ffmpeg FFMPEG] [--threads THREADS]
              [--bitrate {auto,disable,8k,16k,24k,32k,40k,48k,64k,80k,96k,112k,128k,160k,192k,224k,256k,320k,0,1,2,3,4,5,6,7,8,9}] [--ffmpeg-args FFMPEG_ARGS]
              [--format {mp3,flac,ogg,opus,m4a,wav}] [--save-file SAVE_FILE] [--preload] [--output OUTPUT] [--m3u [M3U]] [--cookie-file COOKIE_FILE]
              [--overwrite {skip,force,metadata}] [--restrict [{none,strict,ascii}]] [--print-errors] [--save-errors SAVE_ERRORS] [--sponsor-block] [--archive ARCHIVE]
              [--playlist-numbering] [--playlist-retain-track-cover] [--scan-for-songs] [--fetch-albums] [--id3-separator ID3_SEPARATOR] [--ytm-data] [--add-unavailable]
              [--generate-lrc] [--force-update-metadata] [--sync-without-deleting] [--max-filename-length MAX_FILENAME_LENGTH] [--yt-dlp-args YT_DLP_ARGS]
              [--detect-formats [{mp3,flac,ogg,opus,m4a,wav} ...]] [--redownload] [--skip-album-art] [--ignore-albums [IGNORE_ALBUMS ...]] [--skip-explicit] [--proxy PROXY]
              [--create-skip-file] [--respect-skip-file] [--sync-remove-lrc] [--host HOST] [--port PORT] [--keep-alive] [--allowed-origins [ALLOWED_ORIGINS ...]]
              [--web-use-output-dir] [--keep-sessions] [--force-update-gui] [--web-gui-repo WEB_GUI_REPO] [--web-gui-location WEB_GUI_LOCATION] [--enable-tls]
              [--cert-file CERT_FILE] [--key-file KEY_FILE] [--ca-file CA_FILE] [--log-level {CRITICAL,FATAL,ERROR,WARN,WARNING,INFO,MATCH,DEBUG,NOTSET}] [--simple-tui]
              [--log-format LOG_FORMAT] [--download-ffmpeg] [--generate-config] [--check-for-updates] [--profile] [--version]
              [{download,save,web,sync,meta,url}] query [query ...]

メインオプションを見ていこう

Main options:
  {download,save,web,sync,meta,url}
                        The operation to perform.
                        download: Download the songs to the disk and embed metadata.
                        save: Saves the songs metadata to a file for further use.
                        web: Starts a web interface to simplify the download process.
                        sync: Removes songs that are no longer present, downloads new ones
                        meta: Update your audio files with metadata
                        url: Get the download URL for songs
                        
  query                 Spotify/YouTube URL for a song/playlist/album/artist/etc. to download.
                        
                        For album/playlist/artist searching, include 'album:', 'playlist:', 'artist:' 
                        (ie. 'album:the album name' you can mix these options to get more accurate results).
                        
                        To download liked songs use 'saved' as the query, to download all user playlists
                        use 'all-user-playlists, to download playlists that the user has created
                        use 'all-saved-playlists', to download all user liked playlists
                        use 'all-user-followed-artists', to download all user saved albums use 'all-user-saved-albums' 
                        
                        For manual audio matching, you can use the format 'YouTubeURL|SpotifyURL'
                        You can only use album/playlist/tracks urls when downloading/matching youtube urls.
                        When using youtube url without spotify url, you won't be able to use `--fetch-albums` option.

つまり、こういうことだ。

  • download などのサブコマンドが必須
  • さらに query(URL)の位置がかなりシビア

という仕様。

昔の感覚でURLだけではダメ。
またオプションを並べて、最後にURLを書くと
普通に 「unrecognized arguments」 で怒られる。

まぁ、こんな時に頼りになるのが今の時代はAIだよねってことで、ChatGPTに聞く。

AIと言えども一発回答ではなく(笑)、CLIオプションの指定ミスや、
URLの位置の問題などを一つずつ潰していき、
最終的に「download の直後にURLを置く」という結論に至った。

そうして、いくつか失敗を重ねて試行錯誤し、
エラーを解析してもらい結果的に以下で解決に至った。
以下の実行後にブラウザ認証が走り、その後はプレイリストの一括ダウンロードが成功した。

spotdl download "https://open.spotify.com/playlist/***************" \
  --user-auth \
  --threads 1

音質の劣化が酷い

というわけで早速ダウンロードした曲を聴いてみたが、音質の劣化が酷いことに気がついた。
Spotifyで直接聞いてみて比較しても明らかにわかるレベル。
Spotify経由の方が音質は良いのだがダウンロードすると劣化していた。

この改善ができないか、AIに聞いて以下も試した。

spotdl download "URL" \
  --user-auth \
  --threads 1 \
  --format mp3 \
  --bitrate 320k
spotdl download "URL" \
  --user-auth \
  --threads 1 \
  --audio youtube-music \
  --format opus

だが、結局は音質は改善されず、という状況だ。

この理由としてspotDL は Spotify から音源を直接取得しているわけではなく、
実体としては YouTube / YouTube Music の音源を元に再エンコードしている。

そのため「元が圧縮音源 → mp3変換」という形になり、
Spotify公式再生と比べると劣化を感じやすいわけだ。

音質にこだわるとなるとYoutubeからyt-dlpで音質が良いMVを探してmp3を抜くか、
もうこれは本末転倒だが、spotify有料版を試した方が良いかもしれない。


まとめ

というわけで、今回はspotDLを久しぶりに使ったら仕様が変更になっていたが、
AIと協力して解決できたが、聞いてみたら音質は悪いのよというお話でした。

これもまた筆者の備忘録ではあるが、何かの参考になれば幸いである。