Last active
February 16, 2021 17:04
-
-
Save Winding6636/697ca33708b6f356cc79d90f85031d78 to your computer and use it in GitHub Desktop.
abema_tv streamlink script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Abema TV Download Script | |
# | |
# require streamlink | |
# 作品ページ: https://abema.tv/video/title/{作品ID} | |
# 各話ページ: https://abema.tv/video/episode/{作品ID}_s1_p{話数ID} | |
# チャンネル見逃し配信: https://abema.tv/channels/abema-anime-2(チャンネルID)/slots/{動画ID} | |
# 無料もののみ またその判定はしていない。トークンを有料垢にすれば多分動く | |
# ./abemadl.sh URL {-f|-t title} | |
# | |
#set -Ce | |
IFS_Orig=$IFS | |
token='' #bearer token | |
strlnk="/usr/sbin/streamlink" | |
abeuri="https://abema.tv/video/" | |
abetitle="title" | |
abeps="episode" | |
abeslots="slots" | |
override=false | |
download() { | |
mkdir -p ./"$title" 2>/dev/null | |
path=./$title/$title"_"ep$epn.mp4 | |
if "${override}"; then | |
echo Download: $uri $path | |
$strlnk $uri best -o $path -f | |
elif [ -e $path ]; then | |
echo "[SKIP: File Exists. $path]" | |
else | |
echo Download: $uri $path | |
$strlnk $uri best -o $path | |
fi | |
} | |
help() { | |
#Usage Message | |
echo ' Usage: ./abemadl.sh AbemaTVURL [option]' | |
echo ' option: "-t TITLE" SaveTitleSet' | |
echo ' "-f" override files' | |
echo ' "-sp" SpecialEpisode DLSelect (default skip)' | |
echo '' | |
} | |
echo | |
if [ -e $1 ]; then | |
help | |
read -a uri -p "AbemaTitleURL: " url | |
else | |
uri=$1 | |
fi | |
#if [ "$2" = "-f" ]; then | |
if [ "$2" = "-f" -o "$4" = "-f" ]; then | |
override=true | |
fi | |
if [ "$2" = "-t" -o "$3" = "-t" ]; then | |
stitle=$3 | |
fi | |
echo Target: ${uri[@]} | |
IFS='/' | |
array=(${uri[@]}) | |
IFS=$IFS_Orig | |
videoid=${array[5]} | |
if [ ${array[0]} != "https:" ]; then | |
echo URLを入力してください。 | |
exit 1 | |
elif [ ${array[2]} != 'abema.tv' ]; then | |
echo AbemaTVではありません。 | |
exit 1 | |
elif [ ${array[4]} = $abetitle ]; then | |
eval response=(`curl "https://api.abema.io/v1/video/series/$videoid" -H "authorization: bearer $token" -H 'User-Agent: AbemaConteInfoExtractor.CLI' -H "referer: https://abema.tv/video/title/$videoid" --compressed 2>/dev/null | jq '.version, .seasons[0].id, .title, .version' `) | |
if [ ${response[1]} = 'null' ]; then | |
response=`curl "https://api.abema.io/v1/video/series/$videoid/programs?seriesVersion=${response[3]}&seasonId=&offset=0&order=seq&limit=40" -H "authorization: bearer $token" -H 'User-Agent: AbemaConteInfoExtractor.CLI' -H "referer: https://abema.tv/video/title/$videoid" --compressed 2>/dev/null` | |
else | |
response=`curl "https://api.abema.io/v1/video/series/$videoid/programs?seriesVersion=${response[3]}&seasonId=${response[1]}&offset=0&order=seq&limit=40" -H "authorization: bearer $token" -H 'User-Agent: AbemaConteInfoExtractor.CLI' -H "referer: https://abema.tv/video/title/$videoid" --compressed 2>/dev/null` | |
fi | |
echo '' | |
if [ "$2" = "-t" ]; then | |
title=$3 | |
else | |
title=${response[2]} | |
fi | |
episodes=(`echo $response | jq -r .programs[].id`) | |
for i in "${!episodes[@]}" | |
do | |
epn=(`epn=$((i + 1));seq -f %02g $epn`) | |
epn=${epn[-1]} | |
uri=$abeuri$abeps/${episodes[$i]} | |
title=(`echo $title | sed 's/ /_/g' | sed 's/ /_/g'`) | |
#echo $uri | |
#echo $title | |
#echo $epn | |
if [ "$2" != '-sp' ]; then | |
if [ ${uri##*_} = "p100" -o ${uri##*_} = "p101" -o ${uri##*_} = "p102" -o ${uri##*_} = "p103" ]; then | |
echo SpecialEP_Skip. | |
else | |
download | |
fi | |
else | |
download | |
fi | |
done | |
elif [ ${array[4]} = $abeps ]; then | |
response=(`curl "https://api.abema.io/v1/video/programs/$videoid" -H "authorization: bearer $token" -H 'User-Agent: AbemaConteInfoExtractor.CLI' -H "referer: https://abema.tv/video/title/$videoid" --compressed 2>/dev/null | jq '.episode.number, .series.title' `) | |
epn=(`seq -f '%02g' ${response[0]}`) | |
epn=${epn[-1]} | |
if [ -e $title ]; then | |
title=${response[1]} | |
fi | |
title=(`echo $title | sed 's/ /_/g' | sed 's/ /_/g'`) | |
download | |
elif [ ${array[5]} = $abeslots ]; then | |
videoid=${array[6]} | |
response=(`curl "https://api.abema.io/v1/media/slots/$videoid" -H "authorization: bearer $token" -H 'User-Agent: AbemaConteInfoExtractor.CLI' -H "referer: ${uri[@]}" --compressed 2>/dev/null | jq -r '.slot.programs[].episode.sequence, .slot.title'`) | |
title=(`echo ${response[1]} | sed 's/ //g' | sed 's/ //g'`) | |
epn=(`seq -f %02g ${response[0]}`) | |
epn=(${epn[-1]}_`echo ${response[2]} | sed 's/ //g' | sed 's/ //g'`) | |
#response=(`curl "https://api.abema.io/v1/video/series/${response[3]}" -H "authorization: bearer $token" -H 'User-Agent: AbemaConteInfoExtractor.CLI' -H "referer: ${uri[@]}" --compressed 2>/dev/null | jq -r '.title'`) | |
download | |
else | |
echo 🤔 :thinking_face: 🤔 | |
echo | |
exit 1 | |
fi | |
echo | |
echo Script END. | |
echo | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment