今天发现you-get下载速度好慢,还得调用debug模式看着它在干嘛,索性写成脚本

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
input_file=video_url.txt

duration_format(){
res=""
ds=$1
if [ $ds -ge 3600 ]; then
hs=$((ds/3600))
ds=$((ds%3600));
res=$res$hs"h"
fi
if [ $ds -ge 60 ]; then
ms=$((ds/60))
ds=$((ds%60))
res=$res$ms"m"
fi
res=$res$ds"s"
}

total=$(cat $input_file|wc -l)
count=0
while read line
do
st=$(date +%s)
you-get -o . ${line%?} --debug
let count+=1
et=$(date +%s)
duration=$((et-st))
rest_duration=$((duration*(total-count)))
duration_format $duration
duration_str=$res
duration_format $rest_duration
rest_duration_str=$res
echo "==============="$count"/"$total","${line%?}", cost "$duration_str", rest "$rest_duration_str
done < $input_file

值得注意的是shell函数只能返回数字,所以在shell函数里赋值某一特定名称的变量,在函数执行后取出我们想要的值,shell函数没有参数,在函数体里$1这样去取输入的参数值。数学运算用$(( ))符号,整除是/,模是%。windows下文本文件\r\n,所以上述程序要取到文本文件里的所有行的值,需要在有值的最后一行再按一次回车,使得文本文件最后一行为空行。${line%?}是win下去除掉换行符这个不必要的符号要写的式子,linux下直接取line就行。代码借鉴自/mblogs/210707_0706_afternoon_learning_notes.html

2310291918