mirror of
https://github.com/CoolnsX/hls_downloader.git
synced 2025-12-20 07:15:21 +05:30
feat:subtitles support
This commit is contained in:
@@ -13,11 +13,14 @@ Options:
|
|||||||
-r select highest resolution automatically
|
-r select highest resolution automatically
|
||||||
-n set maximum number of connections (default : 36)
|
-n set maximum number of connections (default : 36)
|
||||||
-f skip ffmpeg file conversion (used to enable the video file to run on any video player)
|
-f skip ffmpeg file conversion (used to enable the video file to run on any video player)
|
||||||
|
-s subtitles url or path
|
||||||
|
|
||||||
|
Note: if subtitles url is passed using [-s] along with skip ffmpeg [-f] then the script will download subtitle file with same name instead of burning it in video file
|
||||||
```
|
```
|
||||||
|
|
||||||
# Increase/Decrease Parallel Downloads..
|
# Increase/Decrease Parallel Downloads..
|
||||||
|
|
||||||
Currently its set to 36 in [line 23](https://github.com/CoolnsX/hls_downloader/blob/main/hls#L23) in script
|
Currently its set to 36 in [line 26](https://github.com/CoolnsX/hls_downloader/blob/main/hls#L26) in script
|
||||||
You can Increase/Decrease it by using ```-n <no. of connections>```
|
You can Increase/Decrease it by using ```-n <no. of connections>```
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|||||||
24
hls
24
hls
@@ -16,6 +16,9 @@ help_text () {
|
|||||||
-r select highest resolution automatically
|
-r select highest resolution automatically
|
||||||
-n set maximum number of connections (default : 36)
|
-n set maximum number of connections (default : 36)
|
||||||
-f skip ffmpeg file conversion (used to enable the video file to run on any video player)
|
-f skip ffmpeg file conversion (used to enable the video file to run on any video player)
|
||||||
|
-s subtitles url or path
|
||||||
|
|
||||||
|
Note: if subtitles url is passed using [-s] along with skip ffmpeg [-f] is then the script will download subtitle file with same name instead of burning it in video file
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,12 +28,13 @@ file="video"
|
|||||||
tmpdir="${XDG_CACHE_HOME:-$HOME/.cache}/hls-temp"
|
tmpdir="${XDG_CACHE_HOME:-$HOME/.cache}/hls-temp"
|
||||||
jobdir="${XDG_CACHE_HOME:-$HOME/.cache}/hls-jobs"
|
jobdir="${XDG_CACHE_HOME:-$HOME/.cache}/hls-jobs"
|
||||||
|
|
||||||
while getopts 'o:rfhn:' OPT; do
|
while getopts 'o:rfhn:s:' OPT; do
|
||||||
case $OPT in
|
case $OPT in
|
||||||
o) file=$OPTARG ;;
|
o) file=$OPTARG ;;
|
||||||
n) n=$OPTARG ;;
|
n) n=$OPTARG ;;
|
||||||
f) skip_ffmpeg=1;;
|
f) skip_ffmpeg=1;;
|
||||||
r) skip_res=1;;
|
r) skip_res=1;;
|
||||||
|
s) subs=$OPTARG;;
|
||||||
*|h)
|
*|h)
|
||||||
help_text
|
help_text
|
||||||
exit 0
|
exit 0
|
||||||
@@ -64,11 +68,7 @@ fi
|
|||||||
key_uri="$(printf "%s" "$resp" | sed -nE 's/^#EXT-X-KEY.*URI="([^"]*)"/\1/p')"
|
key_uri="$(printf "%s" "$resp" | sed -nE 's/^#EXT-X-KEY.*URI="([^"]*)"/\1/p')"
|
||||||
[ -z "$key_uri" ] || iv_uri="$(printf "%s" "$resp" | sed -nE 's/^#EXT-X-IV.*URI="([^"]*)"/\1/p')"
|
[ -z "$key_uri" ] || iv_uri="$(printf "%s" "$resp" | sed -nE 's/^#EXT-X-IV.*URI="([^"]*)"/\1/p')"
|
||||||
data="$(printf "%s" "$resp" | sed '/#/d')"
|
data="$(printf "%s" "$resp" | sed '/#/d')"
|
||||||
if printf "%s" "$data" | grep -q "http";then
|
printf "%s" "$data" | grep -q "http" && relative_url='' || relative_url=$(printf "%s" "$url" | sed 's_[^/]*$__')
|
||||||
relative_url=''
|
|
||||||
else
|
|
||||||
relative_url=$(printf "%s" "$url" | sed 's_[^/]*$__')
|
|
||||||
fi
|
|
||||||
range=$(printf "%s\n" "$data" | wc -l)
|
range=$(printf "%s\n" "$data" | wc -l)
|
||||||
|
|
||||||
#for encrypted stream only
|
#for encrypted stream only
|
||||||
@@ -82,7 +82,7 @@ fi
|
|||||||
printf "\033[2K\r\033[1;35mpieces : $range\n\033[1;33mDownloading.."
|
printf "\033[2K\r\033[1;35mpieces : $range\n\033[1;33mDownloading.."
|
||||||
#downloading .ts data asynchronously
|
#downloading .ts data asynchronously
|
||||||
for i in $(seq $range); do
|
for i in $(seq $range); do
|
||||||
curl -s "${relative_url}$(printf "%s" "$data" | sed -n "${i}p")" > "$tmpdir/$(printf "%04d" "$i").ts" && printf "\033[2K\r\033[1;32m ✓ $i / $range done" &
|
curl -s "${relative_url}$(printf "%s" "$data" | sed -n "${i}p")" > "$tmpdir/$(printf "%05d" "$i").ts" && printf "\033[2K\r\033[1;32m ✓ $i / $range done" &
|
||||||
jobs -p > "$jobdir"
|
jobs -p > "$jobdir"
|
||||||
while [ "$(cat "$jobdir" | wc -l)" -ge $n ];do jobs > "$jobdir";sleep 0.05;done
|
while [ "$(cat "$jobdir" | wc -l)" -ge $n ];do jobs > "$jobdir";sleep 0.05;done
|
||||||
done
|
done
|
||||||
@@ -93,7 +93,7 @@ if [ -n "$key_uri" ];then
|
|||||||
#decrypting while concatenating..
|
#decrypting while concatenating..
|
||||||
printf "\033[2K\r\033[1;36m Decrypting and Concatenating pieces into single file.."
|
printf "\033[2K\r\033[1;36m Decrypting and Concatenating pieces into single file.."
|
||||||
for i in "$tmpdir"/*;do
|
for i in "$tmpdir"/*;do
|
||||||
cat "$i" | openssl aes-128-cbc -d -K "$key" -iv "$iv" -nopad >> "$file.ts"
|
openssl aes-128-cbc -d -K "$key" -iv "$iv" -nopad >> "$file.ts" < "$i"
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
printf "\033[2K\r\033[1;36m Concatenating pieces into single file.."
|
printf "\033[2K\r\033[1;36m Concatenating pieces into single file.."
|
||||||
@@ -102,7 +102,13 @@ fi
|
|||||||
|
|
||||||
rm -rdf $tmpdir $jobdir
|
rm -rdf $tmpdir $jobdir
|
||||||
#conversion of allts file to mp4 video using ffmpeg..
|
#conversion of allts file to mp4 video using ffmpeg..
|
||||||
[ -z "$skip_ffmpeg" ] && printf "\033[2K\r\033[1;36mEncoding file to mp4 video..\n\033[0m" && ffmpeg -i "$file.ts" -loglevel error -stats -c copy "$file.mp4" || mv "$file.ts" "$file.mp4"
|
if [ -z "$skip_ffmpeg" ];then
|
||||||
|
printf "\033[2K\r\033[1;36mEncoding file to mp4 video..\n\033[0m"
|
||||||
|
[ -z "$subs" ] && ffmpeg -i "$file.ts" -loglevel error -stats -c copy "$file.mp4" || ffmpeg -i "$file.ts" -i "$subs" -loglevel error -stats -c copy -c:s mov_text "$file.mp4"
|
||||||
|
else
|
||||||
|
mv "$file.ts" "$file.mp4"
|
||||||
|
[ -z "$subs" ] || curl -s "$subs" -o "$file.srt"
|
||||||
|
fi
|
||||||
|
|
||||||
#cleanup..
|
#cleanup..
|
||||||
rm -f "$file".ts
|
rm -f "$file".ts
|
||||||
|
|||||||
Reference in New Issue
Block a user