share/Scripts/m3u8-download/withkey.sh

77 lines
1.6 KiB
Bash
Raw Permalink Normal View History

2021-09-24 09:13:42 +00:00
#!/bin/bash
# the directory of the script
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# the temp directory used, within $DIR
# omit the -p parameter to create a temporal directory in the default location
WORK_DIR=`mktemp -d -p "$DIR"`
# check if tmp dir was created
if [[ ! "$WORK_DIR" || ! -d "$WORK_DIR" ]]; then
echo "Could not create temp dir"
exit 1
fi
# deletes the temp directory
function cleanup {
rm -rf "$WORK_DIR"
echo "Deleted temp working directory $WORK_DIR"
}
# register the cleanup function to be called on the EXIT signal
2021-09-24 09:35:46 +00:00
trap cleanup EXIT
2021-09-24 09:13:42 +00:00
2021-09-27 06:36:44 +00:00
echo "請輸入key網址: ( copy as cURL(bash) )"
read key
echo
2021-09-24 09:13:42 +00:00
echo "請輸入m3u8網址: ( copy as cURL(bash) )"
read m3u8
2021-09-24 09:35:46 +00:00
echo
2021-09-24 09:13:42 +00:00
echo "請輸入其中一個ts的網址: ( copy as cURL(bash) )"
read BASE
2021-09-24 09:35:46 +00:00
echo
2021-09-27 06:36:44 +00:00
echo "請輸入下載檔案名稱[video.mp4]:"
2021-09-24 09:35:46 +00:00
read output
2021-09-27 06:36:44 +00:00
output=${output:-video.mp4}
2021-09-24 09:35:46 +00:00
echo
echo "下載開始...."
2021-09-24 09:13:42 +00:00
2021-09-27 06:36:44 +00:00
key="${key} -o key"
2021-09-24 09:13:42 +00:00
m3u8="${m3u8} -o index.m3u8"
cd $WORK_DIR
# echo $(pwd)
2021-09-27 06:36:44 +00:00
eval " $key"
2021-09-24 09:13:42 +00:00
eval " $m3u8"
origin=$(echo $BASE | sed -e "s/[^']*'\([^\?^']*\).*'.*/\1/" )
file=${origin##*/}
file=$(echo $file | sed 's/[\*\.\&\?]/\\&/g')
2021-09-24 09:52:18 +00:00
# echo BASE: $BASE
# echo origin: $origin
# echo file: $file
2021-09-24 09:13:42 +00:00
2021-09-27 06:36:44 +00:00
echo 請確認或修改index.m3u8
read dummy
2021-09-24 09:13:42 +00:00
while read p; do
if [[ $p != "#"* ]]; then
pp=$(echo $p | sed 's/[\*\.\&\?]/\\&/g')
2021-09-26 10:57:35 +00:00
echo $p
2021-09-24 09:39:58 +00:00
ts="$(echo $BASE | sed "s,$file,$pp,") -o $p -w '%{http_code}'"
2021-09-24 09:13:42 +00:00
2021-09-24 09:39:58 +00:00
status_code=$(eval " $ts")
if [ $status_code != "200" ]; then
echo
echo ERROR: $status_code, 下載失敗.
cat $p
exit 1
fi
2021-09-24 09:13:42 +00:00
fi
done <index.m3u8
2021-09-27 06:36:44 +00:00
ffmpeg -allowed_extensions ALL -i "index.m3u8" -codec copy ../$output