local lastUsedSegment="" lastUsedStreamTime=0 # Stored for use of recording previous segment when seeing ad block
local doRecord=0 doStopRecord=0
local syncMode=-1 # (-1=get first, x=saw last at, 0=synched) In syncmode we try to request every second until we see a change to get a more precise time sync
-
- real_time=$(date +%s)
-
- if [ -n "$streamDelay" ]; then
- stream_time=$(($real_time - $streamDelay))
- pretty_time=$($DATE${stream_time%.*} +"%Y-%m-%d %H:%M:%S")
- echo >&2 "NOTICE: Using time-offset of -$streamDelay seconds so time is $pretty_time, real time is $(date ${realtime} +"%Y-%m-%d %H:%M:%S")"
- else
- stream_time="$real_time"
- pretty_time=$($DATE${stream_time%.*} +"%Y-%m-%d %H:%M:%S")
- fi
+ local stream_time="" # unknown
echo >&2 "$pretty_time: INFO: Started monitoring using: $stream"
starttime=$(date +%s)
warn_not_a_playlist=1
+ # Set time to real time first request
+ if [ -z "$stream_time" ]; then
+ if [ -n "$streamDelay" ]; then
+ stream_time=$(($starttime - $streamDelay))
+ pretty_time=$($DATE${stream_time%.*} +"%Y-%m-%d %H:%M:%S")
+ echo >&2 "NOTICE: Using time-offset of -${streamDelay}s. Stream time is $pretty_time, real time is $(date ${realtime} +"%Y-%m-%d %H:%M:%S")"
+ else
+ stream_time="$starttime"
+ pretty_time=$($DATE${stream_time%.*} +"%Y-%m-%d %H:%M:%S")
+ echo >&2 "NOTICE: Setting stream time to real time: $pretty_time"
+ fi
+ fi
+
TMPFILE=$(mktemp) || fatal "Can not write tmp-file"
curl $BASIC_CURL_PARAMS -o "$TMPFILE" "$stream"
if [ $? -eq 0 ]; then
stream_time=$(echo "$stream_time + $nextSegmentLength" | bc)
pretty_time=$($DATE${stream_time%.*} +"%Y-%m-%d %H:%M:%S")
if [[ $curSeq -ne $nextSeq ]]; then
- echo >&2 "$pretty_time: WARN: Lost segments ($curSeq > $nextSeq)... resetting..."
- failed=10
+ echo >&2 "$pretty_time: WARN: Lost segments ($curSeq > $nextSeq)."
+ stream_time=
+ syncMode=-1
fi
#echo >&2 "$pretty_time: Current mode length: $curLength"
nextSeq=$(($curSeq + 1))