Last active
February 26, 2025 18:45
-
-
Save slayerlab/6bc839845c5b2e580107630345e6ff2a to your computer and use it in GitHub Desktop.
HTTP Live Streaming -- Transport Stream Video Download
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 | |
file=$(sed -e 's/[[:space:]]/_/g' <<< $1) | |
desc=$2 | |
echo " | |
$desc | |
" > Practica_6/$file.txt | |
#EOF |
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 | |
trim_name=$(sed -e 's/[[:space:]]/_/g' <<< $3) | |
echo "[+] Downloading video $trim_name" | |
bash download.bash "Practica_6/$trim_name" $1 $2 "$trim_name" | |
#EOF |
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 | |
$1 $2 $3 | |
$0 Pratica3-Limite <URL_PLAYLIST> <URL_SEGMENT> | |
------- | |
# Note: | |
+ I don't know why it happens | |
# TODO: | |
- [ ] Add empty parameter check | |
- [ ] Make more reliable | |
USAGE | |
# Exercise directory: | |
# + $exrc to make this script more reliable. | |
exrc=$1 | |
plstd="$exrc/playlist" | |
# Create playlist directory only when necessary... | |
[[ -d "$plstd" ]] || mkdir -p "$plstd" | |
# Playlist URL: This does the dirty hack to increase the video quality from 520px to 720px. | |
# + Is there a way to assign the value to "urlp" without create "_urlp"? | |
# + If caught "(standard_in) 1: syntax error": You missed the URL PLAYLIST. | |
_urlp=$2 && urlp="https://$(cut -d '/' -f3-8 <<<${_urlp})" | |
#"https://$("$_urlp" | cut -d "/" -f3-8)" | |
# ${_urlp:0:161}$(bc -l <<< ${_urlp: -23:-14})${_urlp: -14} | |
# Pratica3-Limite/playlist/playlist.m3u8 | |
plst="$plstd/playlist.m3u8" | |
# Download PLAYLIST | |
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) | |
# URL Segment | |
# + Is there a way to assign the value to "urls" without create "_urls"? | |
# + If caught "(standard_in) 1: syntax error": You missed the URL SEGMENT TS. | |
_urls=$3 && urls="https://$(cut -d '/' -f3-8 <<<${_urls})" | |
#urls="https://$($_urls | cut -d "/" -f3-8)" | |
#urls=${_urls:0:161}$(bc -l <<< ${_urls: -27:-18})${_urls: -18:-12} | |
# chop directory | |
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 | |
# The loop status is respective from last executed command | |
[[ 0 -eq $? ]] && \ | |
(# Remaining two more commands to complete the video download | |
out=$4 | |
sed -i "/^#EXT/! s/^\(chop.*\)/file \'\.\.\/\1\'/g" "$plst" \ | |
&& ffmpeg -f concat -safe 0 -i "$plst" -c copy "$exrc/$out.mp4" | |
) | |
#EOF |
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 | |
$1 $2 $3 | |
$0 Pratica3-Limite <URL_PLAYLIST> <URL_SEGMENT> | |
------- | |
# Note: | |
+ I don't know why it happens | |
# TODO: | |
- [ ] Add empty parameter check | |
- [ ] Make more reliable | |
USAGE | |
# Exercise directory: | |
# + $exrc to make this script more reliable. | |
exrc=$1 | |
plstd="$exrc/playlist" | |
# Create playlist directory only when necessary... | |
[[ -d "$plstd" ]] || mkdir -p "$plstd" | |
# Playlist URL: This does the dirty hack to increase the video quality from 520px to 720px. | |
# + Is there a way to assign the value to "urlp" without create "_urlp"? | |
# + If caught "(standard_in) 1: syntax error": You missed the URL PLAYLIST. | |
_urlp=$2 && urlp="https://$(cut -d '/' -f3-8 <<<${_urlp})" | |
#"https://$("$_urlp" | cut -d "/" -f3-8)" | |
# ${_urlp:0:161}$(bc -l <<< ${_urlp: -23:-14})${_urlp: -14} | |
# Pratica3-Limite/playlist/playlist.m3u8 | |
plst="$plstd/playlist.m3u8" | |
# Download PLAYLIST | |
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) | |
# URL Segment | |
# + Is there a way to assign the value to "urls" without create "_urls"? | |
# + If caught "(standard_in) 1: syntax error": You missed the URL SEGMENT TS. | |
_urls=$3 && urls="https://$(cut -d '/' -f3-8 <<<${_urls})" | |
#urls="https://$($_urls | cut -d "/" -f3-8)" | |
#urls=${_urls:0:161}$(bc -l <<< ${_urls: -27:-18})${_urls: -18:-12} | |
# chop directory | |
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 | |
# The loop status is respective from last executed command | |
[[ 0 -eq $? ]] && \ | |
(# Remaining two more commands to complete the video download | |
out=$4 | |
sed -i "/^#EXT/! s/^\(chop.*\)/file \'\.\.\/\1\'/g" "$plst" \ | |
&& ffmpeg -f concat -safe 0 -i "$plst" -c copy "$exrc/$out.mp4" | |
) | |
#EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Public after 4 years.