1 #!/bin/bash 2 3 # 自動下載電視劇,支援按集斷點下載,正在追的電視劇新增到計劃任務每天定期執行一次即可 4 # QYN2線上網站: https://www.jjwu.net/vodplay/46471_5_1.html 5 # 使用Ubuntu系統,需要安裝的工具 6 # apt-get install -y parallel wget ffmpeg 7 8 # 建立存放影片和快取的目錄 9 mkdir -p mp4/cache 10 11 # 12 for i in `seq -w $(ls mp4 | wc -l) 36 ` 13 do 14 # 列印正在處理的劇集 15 echo -e "第 $i 集" 16 # 清空快取目錄 17 rm -rf mp4/cache/* 18 # 從m3u8檔案中除去廣告ts,獲取電視劇ts,並生成ts檔案的url儲存到file.list 19 curl -s "https://s3.bfengbf.com/video/qingyuniandierji/第$i集/index.m3u8" \ 20 | awk '/^000.*ts$/{print "https://s3.bfengbf.com/video/qingyuniandierji/第'$i'集/"$1}' \ 21 > mp4/cache/file.list 22 # 如果這一集還沒更新,那麼file.list檔案中不存在ts檔案的url,退出指令碼 23 cat mp4/cache/file.list | grep '^00.*ts$' &>/dev/null || exit 24 # 100併發下載ts檔案 25 parallel -j 100 -a mp4/cache/file.list wget --timeout=30 --tries=3 -nv -P mp4/cache 26 # 合併ts檔案 27 for j in `ls mp4/cache` 28 do 29 cat mp4/cache/$j >> mp4/cache/input.ts 30 done 31 # 將ts檔案轉換成mp4檔案 32 ffmpeg -n -loglevel quiet -i mp4/cache/input.ts -vcodec copy -acodec copy -absf aac_adtstoasc mp4/$i.mp4 33 done