-
Notifications
You must be signed in to change notification settings - Fork 4
/
mergets.sh
executable file
·64 lines (56 loc) · 1.28 KB
/
mergets.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
blue='\033[0;34m'
purple='\033[0;35m'
cyan='\033[0;36m'
white='\033[0;37m'
end='\033[0m'
log(){
printf " $1\n"
}
log_error(){
printf "$red $1 $end\n"
}
log_info(){
printf "$green $1 $end\n"
}
log_warn(){
printf "$yellow $1 $end\n"
}
url_decode(){
url=$1
printf $(echo -n $url | sed 's/\\/\\\\/g;s/\(%\)\([0-9a-fA-F][0-9a-fA-F]\)/\\x\2/g')
}
download(){
url=$(url_decode $1)
current=$2
file="$current.mp4"
echo "$file $url" >> download.log
ffmpeg -i $url -headers $'\r\n' -c copy -bsf:a aac_adtstoasc $file
log_info "\n\n\tfinished $file \n\n"
}
help(){
printf "Run:$red sh mergets.sh $green<verb> $yellow<args>$end\n"
printf "\nDescription:\n\t Download .ts file and merge as .mp4.\n\n"
format=" $green%-4s $yellow%-6s$end%-20s\n"
printf "$format" "-h" "" "help"
printf "$format" "-du" "" "decode url "
printf "$format" "" "url" "url of m3u8 file"
}
case $1 in
-h)
help ;;
-du)
url=$(url_decode $2)
log_info $url
;;
*)
if test $# -lt 1;then
log_error 'Input valid URL'
exit 0
fi
current=$(date "+%Y%m%d-%H%M%S")
(download $1 $current &) > $current.log 2>&1
;;
esac