AbemaTV の動画をダウンロードしたい

ABEMA | テレビ&ビデオエンターテインメント大友克洋AKIRA が配信されるという。期間限定で、見る時間がない。後で見たいのでダウンロードしたい。Streamlink を使うとできるようだ。Windows 版については詳しい解説がある (AbemaTVをStreamlinkで直接録画・ダウンロードする | つくみ島だより)。

環境は MacOS 10.11.6 El Capitan である。

Streamlink をインストールする方法が案内されているが (Installation — Streamlink 1.4.1 documentation)、以下のように SSL のエラーが出てしまう。

$ sudo easy_install -U streamlink
Searching for streamlink
Reading https://pypi.python.org/simple/streamlink/
Download error on https://pypi.python.org/simple/streamlink/: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590) -- Some packages may not be found!
Couldn't find index page for 'streamlink' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.python.org/simple/
Download error on https://pypi.python.org/simple/: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590) -- Some packages may not be found!
No local packages or download links found for streamlink
error: Could not find suitable distribution for Requirement.parse('streamlink')

Homebrew でのインストール方法もあるが試していない。今のところ MacPorts には登録がなかった。

$ sudo port install streamlink
Error: Port streamlink not found

諦めようと思ったが、pip で成功した。

pip install streamlink
Defaulting to user installation because normal site-packages is not writeable
Collecting streamlink
  Downloading streamlink-1.4.1-py2.py3-none-any.whl (382 kB)
     |████████████████████████████████| 382 kB 7.0 MB/s 
...
Successfully built iso-639
Installing collected packages: isodate, iso-639, websocket-client, pycryptodome, iso3166, PySocks, certifi, chardet, idna, requests, streamlink
Successfully installed PySocks-1.7.1 certifi-2020.4.5.1 chardet-3.0.4 idna-2.9 iso-639-0.4.5 iso3166-1.0.1 isodate-0.6.0 pycryptodome-3.9.7 requests-2.23.0 streamlink-1.4.1 websocket-client-0.57.0

streamlink コマンドの一番簡単な使い方は次の通り (GitHub - streamlink/streamlink: Streamlink is a CLI utility which pipes video streams from various services into a video player)。このようにオプションをつけないで起動すると、ローカルの動画プレーヤー (例えば VLC) が起動する。

$ streamlink STREAMURL best

STREAMURL には動画の URL を入力する。最後の best は画質の指定で、配信されている画質の中から指定する。例えば、streamlink でダウンロードを始めると Available streams: 180p (worst), 240p, 360p, 480p, 720p, 1080p (best) のように表示されるので、この中から選択する。best は最高画質ということで、この場合は 1080p と指定するのと同じである。配信によって最高画質は異なる。2時間の映画の場合、1080p だと容量が 2 GB 超えしてしまうので、720p 程度にしている。このあたりはお好みで。

オプション -o とファイル名をつければ、そのファイル名でダウンロードできる。AbemaTV は TS フォーマットで配信されているので、ファイル名の拡張子には「.ts」をつけている。

$ streamlink https://abema.tv/video/episode/13-116_s0_p1 best -o "AKIRA.ts"

720p でダウンロードしたところ、容量は 1.01 GB になった。