From adf5b2c60f7644fe807ed9fcccc8e01862dbfcef Mon Sep 17 00:00:00 2001 From: Evan Chen Date: Fri, 24 Sep 2021 17:13:42 +0800 Subject: [PATCH] feat: add m3u8 download script --- m3u8下載/dl.sh | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ m3u8下載/test.sh | 33 +++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 m3u8下載/dl.sh create mode 100644 m3u8下載/test.sh diff --git a/m3u8下載/dl.sh b/m3u8下載/dl.sh new file mode 100644 index 0000000..7a9cc88 --- /dev/null +++ b/m3u8下載/dl.sh @@ -0,0 +1,54 @@ +#!/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 +# trap cleanup EXIT + +echo "請輸入m3u8網址: ( copy as cURL(bash) )" +read m3u8 + +echo "請輸入其中一個ts的網址: ( copy as cURL(bash) )" +read BASE + +m3u8="${m3u8} -o index.m3u8" +cd $WORK_DIR +# echo $(pwd) +eval " $m3u8" + +origin=$(echo $BASE | sed -e "s/[^']*'\([^\?^']*\).*'.*/\1/" ) +file=${origin##*/} +file=$(echo $file | sed 's/[\*\.\&\?]/\\&/g') + +echo BASE: $BASE +echo origin: $origin +echo file: $file + +while read p; do + if [[ $p != "#"* ]]; then + pp=$(echo $p | sed 's/[\*\.\&\?]/\\&/g') + ts="$(echo $BASE | sed "s,$file,$pp,") -o $p" + + eval " $ts" + + fi +done