#!/bin/bash if [ -z $1 ]; then echo Usage $0 m3u8 url fi m3u8_url=$1 m3u8_file=/tmp/m3u8.$$ https_file=/tmp/https.$$ # 下載m3u8文件 wget -q -O $m3u8_file ${m3u8_url} # 從m3u8文件中提取ts連接 cat $m3u8_file | awk '{ if(index($0, "https://") > 0) {print $0} }' > $https_file echo removeing ts files rm out*.ts -f 2> /dev/null # 定義頭部信息 headers="--header='Host: cdn-2-dx.cdnpan.com' --header='User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0' --header='Accept: */*' --header='Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2' --header='Accept-Encoding: gzip, deflate, br' --header='Origin: https://baiduyunbo.com' --header='Connection: keep-alive'" # 遍歷ts連接,並一個個下載 count=1 while read url; do echo downloading $url out_file=$(printf "%03d" $count) # wget -q $headers -t 0 $url; wget -q -t 0 -O out${out_file}.ts $url; let count+=1; done< $https_file # 合成ts片斷文件。合成後的文件就是一個連貫的能夠播放的文件 echo merge ts files cat out*.ts > all_$$.ts # 最終刪除臨時文件 rm $m3u8_file $https_file -f 2> /dev/null echo Done!