数据流补全脚本

线上缓存流经常由于网络问题导致数据同步不完成,需要手动一条条下载,现在通过脚本来完成下载,但需要传入三个参数即:频道名,开始时间,结束时间。

#!/bin/bash 
#Author: hudaohng
#Date:
#Version:1.2

read -p "please input English Channel Name:" channel
read -p "please input startTime:'1970-01-01 00:00:00' "  Starttime
read -p "please input endTime:'1970-01-01 00:00:00' " Endtime

starttime=`date --date="$Starttime" +%s 2> /dev/null`
endtime=`date --date="$Endtime" +%s 2>/dev/null`
echo $channel,$starttime,$endtime
Year=`date --date="$Starttime" +%Y 2> /dev/null`
Month=`date --date="$Starttime" +%m 2> /dev/null`
Date=`date --date="$Starttime" +%d 2> /dev/null` 
basicDir=/opt/online01/stream
codetype250=2500000
codetype150=1500000
#codetype256=256000
codetype512=512000
#codetype800=800000
TmpM3u8File=/tmp/stream.m3u8

links -dump  "http://xxx.lives.lonining.com/approve/vod?type=ipsd&channel=$channel&starttime=$starttime&endtime=$endtime" | grep http > $TmpM3u8File || {
	echo  "please check Channel:$channel,Check Time:$Starttime and $Endtime"
	exit 3
}

stream () {

for file in `cat $TmpM3u8File`
	do
		localfile=$basicDir/`echo $file | awk -F stream/ '{print $2}'`
		if [ -e $localfile ];then
			echo $localfile already exists
		else
			if [ -e $basicDir/$1/$channel/$Year/$Month/$Date ];then
				wget $file   -P $basicDir/$1/$channel/$Year/$Month/$Date &> /dev/null && echo "$file down sucessfully"
			else
				echo $basicDir/$1/$channel/$Year/$Month/$Date not exists && exit 12
			fi

		fi	
	done
}

RETVAL=`expr $channel :  .*HD\$`
if [ $RETVAL -ne 0 ];then
	stream $codetype250
else
	stream $codetype150
fi

仅作为自己学习参数

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章