
各動画サイトのダウンロードに、Clibgrubと共に愛用しているyoutube-dlのYoutubeでのダウンロードがとても遅いことに気づき、公式サイトをチェックしてみると最近はあまりアップデートが無い状態に。そこで本家から派生して熱心に開発が続いているyt-dlpを試してみました。
youtube-dlの近況
以前、YoutubeやTVerなどの動画ダウンロード用に導入したyoutube-dlですが、いつの頃からかダウンロード速度が使い物にならないほど遅くなっていました。
1 2 3 4 5 |
$ youtube-dl -f best https://www.youtube.com/watch?v=########### [youtube] ###########: Downloading webpage [download] Destination: ###########.mp4 [download] 0.5% of 1.53GiB at 51.88KiB/s ETA 08:33:13^C ERROR: Interrupted by user |
Ubuntu 18.04のyoutube-dl
こうした場合にまず更新がリリースされていないか確認するものですが、その前に今、Ubuntu 18.04で使っているyoutube-dlのバージョンを確認します。
実はこのマシンには前回、youtube-dlのGitHubから手動インストールしたバイナリの他に、LaunchpadレポジトリにあるUbuntu謹製のパッケージ版も混在しており、実際に両者のバージョンを確認してみると、前者の方が新しいものの、それでも半年程度前のリリースでした。
1 2 3 4 |
$ /usr/bin/youtube-dl --version #Ubuntu謹製版 2018.03.14 $ /usr/local/bin/youtube-dl --version #公式GitHub版 2021.06.06 |
yt-dlpを導入
youtube-dlの公式GitHubにも以降にリリースされた更新も無いことから、対処方法を調べていたところ、同じくYoutubeからのダウンロード時における速度に不満が挙がっていたこちらのフォーラムで、yt-dlpを勧める声がいくつも見受けられました。
yt-dlpはyoutube-dlのフォークであるyoutube-dlcからさらにフォークアウトしたもので、そのオプション体系は源流であるyoutube-dlに準じているのが何より嬉しいところ。更新が止まってしまったyoutube-dl ver.2021.06.06をベースに、Youtube向けにもさまざまな改善を織り込んでいるようです。
Linux版は、GitHubのリリースページにある拡張子のないバイナリファイルをダウンロードして、実行権限を付与するだけで取り敢えず試してみることができます。
本記事冒頭で、youtube-dlでは8時間程度掛かる見込みとされていたYoutube動画が、yt-dlpでは20分程度で完走してしまいました。
1 2 3 4 5 6 7 |
$ ./yt-dlp -f best https://www.youtube.com/watch?v=########### [youtube] ###########: Downloading webpage [youtube] ###########: Downloading android player API JSON [youtube] ###########: Downloading player f3c4e04d [info] ###########: Downloading 1 format(s): 22 [download] Destination: ###########.mp4 [download] 100% of 1.53GiB in 19:55 |
きちんとインストールするのであれば、GitHubのINSTALLATION項に解説されているようにyoutube-dlの時同様、 curl コマンドなどで /usr/local/bin/ へバイナリをダウンロードして、実行権限を付与します(管理者権限にて)。
1 2 3 4 5 6 7 8 9 10 11 |
$ sudo curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /usr/local/bin/yt-dlp % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 134 100 134 0 0 549 0 --:--:-- --:--:-- --:--:-- 549 100 645 100 645 0 0 2128 0 --:--:-- --:--:-- --:--:-- 0 100 2205k 100 2205k 0 0 935k 0 0:00:02 0:00:02 --:--:-- 1441k $ sudo chmod a+rx /usr/local/bin/yt-dlp $ ls -l /usr/local/bin/yt* -rwxr-xr-x 1 root root 2258760 Dec 16 13:17 /usr/local/bin/yt-dlp $ yt-dlp --version 2021.12.01 |
TVerのダウンロードにも対応
もちろん、YoutubeのみならずTVerのダウンロードにも対応しています。TVerは日本国外からブラウザでは「tver player_err_geo_restricted」と出て再生することが出来ませんが、再生2時間程度の番組動画を途中のタイムアウトにも粘り強いリトライを経て、1時間強で完走しました。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
$ yt-dlp -f best https://tver.jp/corner/######## [TVer] Downloading JSON metadata [TVer] ########: Downloading JSON metadata [brightcove:new] ref:########-####-####-####-############: Downloading JSON metadata [brightcove:new] ref:########-####-####-####-############: Downloading JSON metadata [brightcove:new] ref:########-####-####-####-############: Downloading m3u8 information [brightcove:new] ref:########-####-####-####-############: Downloading m3u8 information [brightcove:new] ref:########-####-####-####-############: Downloading m3u8 information [brightcove:new] ref:########-####-####-####-############: Downloading m3u8 information [brightcove:new] ref:########-####-####-####-############: Downloading m3u8 information [brightcove:new] ref:########-####-####-####-############: Downloading m3u8 information [brightcove:new] ref:########-####-####-####-############: Downloading MPD manifest [brightcove:new] ref:########-####-####-####-############: Downloading MPD manifest [info] ref:########-####-####-####-############: Downloading 1 format(s): hls-3171-5 [hlsnative] Downloading m3u8 manifest [hlsnative] Total fragments: 601 [download] Destination: ########################.mp4 [download] 70.7% of ~2.11GiB at 471.65KiB/s ETA 19:43 (frag 425/601)[download] Got server HTTP error: The read operation timed out. Retrying (attempt 1 of 10) ... [download] 76.7% of ~2.11GiB at 351.18KiB/s ETA 15:47 (frag 460/601)[download] Got server HTTP error: The read operation timed out. Retrying (attempt 1 of 10) ... [download] 89.1% of ~2.11GiB at 5.98KiB/s ETA 07:43 (frag 535/601)[download] Got server HTTP error: The read operation timed out. Retrying (attempt 1 of 10) ... [download] 91.2% of ~2.11GiB at 7.83KiB/s ETA 06:23 (frag 548/601)[download] Got server HTTP error: Downloaded 965282 bytes, expected 3441536 bytes. Retrying (attempt 1 of 10) ... [download] 98.8% of ~2.11GiB at 233.27KiB/s ETA 00:49 (frag 594/601)[download] Got server HTTP error: The read operation timed out. Retrying (attempt 1 of 10) ... [download] 100% of 2.11GiB in 01:10:39 [FixupM3u8] Fixing MPEG-TS in MP4 container of "########################.mp4" |
yt-dlpの自己更新チェック
最新に保つことがことさら重要なダウンローダ、yt-dlpにはアップデート用のオプションも用意されていて便利です。
1 2 3 4 5 6 7 8 9 10 11 |
$ yt-dlp --version 2021.12.01 $ sudo yt-dlp -U Latest version: 2021.12.27, Current version: 2021.12.01 Current Build Hash 5c37c8f9aaf8cc12faea034de96deb5794b7177f071425ce69dad3f315335559 Updating to version 2021.12.27 ... Updated yt-dlp to version 2021.12.27; Restart yt-dlp to use the new version $ yt-dlp --version 2021.12.27 |
Aria2との連携
以前、Baidu Panからのダウンロードに使ったり、Synology NASへ導入したこともあるマルチダウンローダ 、Aria2をyt-dlpの外部ダウンローダとして指定することが出来るようなので、両者の連携による高速複数同時ダウンロードを試してみましょう。
yt-dlpで指定するオプションは以下の2つ、外部ダウンローダ名とそのオプション文字列のみ。もちろん、システムに既にAria2がインストールされていることが前提です。aria2cへ渡しているオプションの詳細については、以前の記事を参照ください。
1 2 |
--downloader aria2c --downloader-args aria2c:"-x16 -s16 --retry-wait=1" |
Youtubeにある再生時間2時間弱の動画を例に、早速yt-dlp+aria2cによる高速複数同時ダウンロードを実行してみると、平均して1MB/s前後の速度を維持して22分で完走。
1 2 3 4 5 6 7 8 9 |
$ yt-dlp -f b --downloader aria2c --downloader-args aria2c:"-x16 -s16 --retry-wait=1" https://www.youtube.com/watch?v=########### [youtube] ###########: Downloading webpage [youtube] ###########: Downloading android player API JSON [youtube] ###########: Downloading MPD manifest [youtube] ###########: Downloading MPD manifest [info] ###########: Downloading 1 format(s): 22 [download] Destination: ######################.mp4 [aria2c] Downloaded 1299820031 bytes870KiB] [download] 100% of 1.21GiB in 22:30 |
同じ動画をyt-dlp単体でダウンロードしてみると倍の時間が掛かったことから、aria2を外部ダウンローダとすることによる高速化は十分有効であると言ってよいでしょう。
1 2 3 4 5 6 7 8 |
$ yt-dlp -f b https://www.youtube.com/watch?v=########### [youtube] ###########: Downloading webpage [youtube] ###########: Downloading android player API JSON [youtube] ###########: Downloading MPD manifest [youtube] ###########: Downloading MPD manifest [info] ###########: Downloading 1 format(s): 22 [download] Destination: ######################.mp4 [download] 100% of 1.21GiB in 48:55 |
しかしながらダウンロード先によっては帯域制限を喰らうことにもなりかねないことや、単体でも十分な速度が得られることから、「こういう使い方もある」と知っておく程度にしておいた方が良さそうです。
ClipGrabもyt-dlpをサポート
ちなみに、以前よりyoutube-dlをバックグラウンドのダウンローダとしてサポートしていた、ClipGrab(AppImage版 ver.3.9.7)もyt-dlpに対応しているようで、ある日の起動時に必要なバイナリをダウンロードするよう促されました。
2022.04追記
2022年4月1日のTVerサイト大幅リニューアル以降、新しい構造のURLを付与すると Unsupported URL でエラー終了するようになりました。
1 2 3 4 5 6 7 8 |
$ yt-dlp --version 2022.03.08.1 $ yt-dlp https://tver.jp/episodes/########## [generic] ##########: Requesting header WARNING: [generic] Falling back on generic information extractor. [generic] ##########: Downloading webpage [generic] ##########: Extracting information ERROR: Unsupported URL: https://tver.jp/episodes/########## |
4月4日現在、まだバイナリはリリースされていませんが、GitHubではTVer向けスクリプトを改修が進んでいたので、別途こちらの記事で試してみました。