Last active
February 26, 2025 18:44
-
-
Save slayerlab/acf863e5341c37008d71feeb91394aa6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
:<<'USAGE' | |
$exrc $urlp $urls $out | |
$1 $2 $3 $4 | |
$0 Pratica3-Limite <URL_PLAYLIST> <URL_SEGMENT> <OUTPUT_MP4> | |
USAGE | |
exrc=$1 | |
plstd="$exrc/playlist" | |
[[ -d "$plstd" ]] || mkdir -p "$plstd" | |
_urlp=$2 && urlp="https://$(cut -d '/' -f3-8 <<<${_urlp})" | |
plst="$plstd/playlist.m3u8" | |
wget "$urlp" -O "$plst" -q --show-progress | |
[[ -f "$PWD/$plst" ]] && last_ts_number=$(grep -oP "^[^#].*-\K([0-9]+)" "$plst" | tail -1) \ | |
|| (echo "[!] File \"$plst\" not found." && exit 1) | |
_urls=$3 && urls="https://$(cut -d '/' -f3-8 <<<${_urls})" | |
chpd="$exrc/chop" | |
[[ -d "$chpd" ]] || mkdir "$chpd" | |
for i in $(seq 1 $last_ts_number); do | |
tsf="segment-$i.ts" | |
[[ -e "$chpd/$tsf" ]] && \ | |
(# TRUE: overwrite the ts file if it exists. | |
echo "[-] The file already exists, so overwriting him: \"$tsf\"" \ | |
&& wget "$urls/$tsf" -O "$chpd/$tsf" -q --show-progress | |
) || ( | |
# FALSE: perform a regular ts file download. | |
echo "[+] Downloading the file: segment-$i.ts" \ | |
&& wget "$urls/$tsf" -P "$chpd" -q --show-progress | |
) | |
case "$?" in | |
1) echo "[!] An error occurred, turn debug on and check it. Program aborted." | |
exit $?;; | |
esac | |
done | |
[[ 0 -eq $? ]] && \ | |
( | |
out=$4 | |
sed -i "/^#EXT/! s/^\(chop.*\)/file \'\.\.\/\1\'/g" "$plst" \ | |
&& ffmpeg -f concat -safe 0 -i "$plst" -c copy "$exrc/$out" | |
) | |
#EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Public after 4 years.