一键下载M3U8/HLS 并保存为TS文件

下载m3u8 并存成一个TS的脚本, 试过优酷的可以,但如果m3u8 里面有多种清晰度的TS片参杂,那就要再写一点逻辑来控制下载哪些啦:


#!/bin/bash

#howToUse: ./down_m3u8.sh url output.ts

#检测参数
if [ $# != 2 ] ; then 
echo "USAGE: $0 url output.ts" 
exit 1; 
fi 

input_m3u8=$1
output_ts=$2
temp_m3u8=temp.m3u8
n=1;

if echo "$input_m3u8" | grep -E '^http' >/dev/null ;then
    wget $input_m3u8 -O $temp_m3u8
else
    temp_m3u8=$input_m3u8
fi

echo "Download segments:"

#1. 这种方法简便,但没有下载"..."提示,容易误以为卡住了
#wget -q -i $temp_m3u8 -O $output_ts

#2. 这种方法麻烦,但有下载"..."提示
rm $output_ts
cat $temp_m3u8 | while read myline
do 
  if echo "$myline" | grep -E '^http' >/dev/null ;then
    echo -n "."
    wget -q "$myline" -O "$output_ts.t";
    cat "$output_ts.t" >> $output_ts
    let "n = $n + 1"
  fi
done
rm "$output_ts.t"
echo "Done"







  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值