winlin

add script check_hls_backup.sh to research hls.

  1 +if [[ $# -lt 2 ]]; then
  2 + echo "Usage: $0 <hls0> <hls1> [keep_ts]"
  3 + echo " keep_ts to keep the download ts, default is off"
  4 + echo "For example:"
  5 + echo " $0 http://192.168.1.137:1980/hls/live/stone/live.m3u8 http://192.168.1.137:1984/hls/live/stone/live.m3u8"
  6 + echo " $0 http://192.168.1.137:1980/hls/live/livestream/live.m3u8 http://192.168.1.137:1984/hls/live/livestream/live.m3u8"
  7 + echo " $0 http://ossrs.net:1984/hls/live/livestream/live.m3u8 http://ossrs.net:1996/hls/live/livestream/live.m3u8"
  8 + exit 1
  9 +fi
  10 +
  11 +hls0=$1
  12 +hls1=$2
  13 +keep_ts=NO
  14 +if [[ $# -gt 2 ]]; then
  15 + keep_ts=YES
  16 +fi
  17 +#echo "check hls backup of $hls0 vs $hls1, keep_ts=$keep_ts"
  18 +
  19 +hls0_tss=`curl $hls0 2>/dev/null |grep "\.ts"`
  20 +hls1_tss=`curl $hls1 2>/dev/null |grep "\.ts"`
  21 +
  22 +hls0_prefix=`dirname $hls0`
  23 +hls1_prefix=`dirname $hls1`
  24 +work_dir="./hbt_temp_`date +%s`"
  25 +
  26 +md5_tool="md5"
  27 +`md5sum --version >/dev/null 2>&1` && md5_tool="md5sum"
  28 +#echo "use md5 tool: $md5_tool"
  29 +
  30 +CHECKED=NO
  31 +OK=YES
  32 +for ts in $hls0_tss; do
  33 + match=NO
  34 + for ts1 in $hls1_tss; do
  35 + if [[ $ts == $ts1 ]]; then
  36 + #echo "check ts $ts"
  37 + match=YES
  38 + break
  39 + fi
  40 + done
  41 + #echo "check ts $ts, match=$match"
  42 +
  43 + if [ $match = NO ]; then
  44 + echo "skip $ts"
  45 + continue
  46 + fi
  47 +
  48 + ts0_uri=$hls0_prefix/$ts
  49 + ts1_uri=$hls1_prefix/$ts
  50 + ts0_tmp=$work_dir/hls0/`basename $ts`
  51 + ts1_tmp=$work_dir/hls1/`basename $ts`
  52 + #echo "start check $ts0_uri($ts0_tmp) vs $ts1_uri($ts1_tmp)"
  53 +
  54 + mkdir -p `dirname $ts0_tmp` &&
  55 + curl $ts0_uri >$ts0_tmp 2>/dev/null &&
  56 + ret=$?; if [[ $ret -ne 0 ]]; then echo "download $ts0_uri to $ts0_tmp failed. ret=$ret"; exit $ret; fi
  57 +
  58 + mkdir -p `dirname $ts1_tmp` &&
  59 + curl $ts1_uri >$ts1_tmp 2>/dev/null &&
  60 + ret=$?; if [[ $ret -ne 0 ]]; then echo "download $ts1_uri to $ts1_tmp failed. ret=$ret"; exit $ret; fi
  61 +
  62 + if [[ $md5_tool == "md5" ]]; then
  63 + ts0_cs=`$md5_tool $ts0_tmp|awk '{print $4}'`
  64 + else
  65 + ts0_cs=`$md5_tool $ts0_tmp|awk '{print $1}'`
  66 + fi
  67 + #echo "hls0: md5sum($ts0_tmp)=$ts0_cs"
  68 +
  69 + if [[ $md5_tool == "md5" ]]; then
  70 + ts1_cs=`$md5_tool $ts1_tmp|awk '{print $4}'`
  71 + else
  72 + ts1_cs=`$md5_tool $ts1_tmp|awk '{print $1}'`
  73 + fi
  74 + #echo "hls1: md5sum($ts1_tmp)=$ts1_cs"
  75 +
  76 + if [[ $ts0_cs != $ts1_cs ]]; then
  77 + echo "$ts0_uri($ts0_cs) not equals to $ts1_uri($ts1_cs)"
  78 + OK=NO
  79 + fi
  80 + CHECKED=YES
  81 +done
  82 +
  83 +if [ $keep_ts = NO ]; then
  84 + #echo "clenaup work dir $work_dir"
  85 + rm -rf $work_dir
  86 +else
  87 + echo "keep work dir $work_dir"
  88 +fi
  89 +
  90 +#echo "====================================================="
  91 +if [[ $OK = YES && $CHECKED = YES ]]; then
  92 + echo "OK"
  93 + exit 0
  94 +else
  95 + echo "FAILED"
  96 + exit 1
  97 +fi
  98 +
  99 +exit 0