Recording using HTTP download - HDHomeRun Prime
Re: Recording using HTTP download - HDHomeRun Prime
I've been looking at Serviio and it has an option to add live HTTP streams. It mentions in the documentation to use VLC to test the streams to verify they will work with Serviio. So I'm reading into this that maybe Serviio could be an easy way to deliver the HDHR streams to a remote user.
Re: Recording using HTTP download - HDHomeRun Prime
Is this rest api documented completely anywhere?
-
- Posts: 216
- Joined: Sat Jan 10, 2015 12:39 pm
Re: Recording using HTTP download - HDHomeRun Prime
This Linux script will record a stream from the requested v-channel for a duration. I modified it to add the requisite header block to display/manipulate the recording by the HDHR-DVR.
Execute this script from the system that is running your DVR so that the results will land in your correct DVR directory. The output path should be modified if you are not a DVR subscriber to save to any local path -- Kodi/Plex will ignore all the header block and play as a local file titled by channel, time and duration...
Please use and modify this work at your own whim. Do post and tell us all what you did to make this process better.
Within my HDHomeRun Directory I set up a separate path called _Utility where I keep my extra things like comskip, record rules backup, and adhoc_record. This script queries for the same path which the DVR records to and land the ad_hoc recording there...
#usage
# ./adhoc_record <_channel> <_minutes-duration> [<"Optional Program Title in Quotes that shows up in DVR">]
make sure there is a path to nohup -- WD has this in the regular path as well as standard Linux and WIN10 bash,
QNAP/Synology may have in a different place due to the OS/Processor, so one may need to execute "which nohup" and if it does not tell you a good answer, execute "find / 2>/dev/null |grep nohup" and copy nohup to a place in your path.
Execute this script from the system that is running your DVR so that the results will land in your correct DVR directory. The output path should be modified if you are not a DVR subscriber to save to any local path -- Kodi/Plex will ignore all the header block and play as a local file titled by channel, time and duration...
Please use and modify this work at your own whim. Do post and tell us all what you did to make this process better.
Within my HDHomeRun Directory I set up a separate path called _Utility where I keep my extra things like comskip, record rules backup, and adhoc_record. This script queries for the same path which the DVR records to and land the ad_hoc recording there...
#usage
# ./adhoc_record <_channel> <_minutes-duration> [<"Optional Program Title in Quotes that shows up in DVR">]
make sure there is a path to nohup -- WD has this in the regular path as well as standard Linux and WIN10 bash,
QNAP/Synology may have in a different place due to the OS/Processor, so one may need to execute "which nohup" and if it does not tell you a good answer, execute "find / 2>/dev/null |grep nohup" and copy nohup to a place in your path.
Code: Select all
#!/bin/bash
###set -vx
#$0 adhoc_record
#$1 what virtual channel to record
#$2 how many minutes to record
#$3 Optional Program title
####################################################
#
###. /share/HDHomeRun/hdhomerun.conf
RecordPath=$( wget -q -O - $( wget -O - -q myhdhomerun.com/discover|grep StorageURL|sed -e 's!^.*//!!' -e 's!/.*$!!' )/system.html|grep "Record Path"|sed -e 's/<..>//g' -e 's/<...>//g' -e 's/Record Path//')
#
####################################################
#
#usage
# ./adhoc_record <_channel> <_minutes> [<"Program Title in Quotes">]
#
# entering the command below would record channel 524 for 60 minutes
# ./adhoc_record 524 60
# and create a file called: v524_20160301_0855.mpg
# in the default record path for WD-Mycloud
#
# It will then show up in recorded section and is playable with HDHR View
###################################################
# input PARMS
_channel=${1:-10}
_minutes=${2:-1}
_title=${3:-Ad Hoc Recording}
#
###################################################
#derived from inputs/environment
let DURATION=${_minutes}*60
START=$(date +%Y%m%d-%H%M)
hdrStart=$(date -u +%s)
let hdrEnd=${hdrStart}+${DURATION}
VCHANNEL=v${_channel}
_seriesID=${_title::8}
_programID=${_seriesID}
REC_PATH=${RecordPath}/AdHoc
REC_FILE=${REC_PATH}/AdHoc_${VCHANNEL}_\[${START}\].mpg
mkdir -p ${REC_PATH}
curLOG=$(ls -1tr ${RecordPath}/20*.log | tail -1)
getTunersLocal=$(grep url ${RecordPath}/*.log|cut -f10 -d" "|sort -u|cut -f3 -d/ |cut -f1 -d:)
getTuners=$(wget -O - -q my.hdhomerun.com/discover|sed -e '/IP/!d' -e 's/[," ]//g' -e 's/.*://'|sort )
Tuners=${getTuners:-${getTunersLocal}}
#
###################################################
#
# Get the channel GuideName from lineup -- Use all Devices since some may have different lineups
# If it can not find a channel in the lineup, it could be available, but just blanked out
# such as Showtime might be marked with X (disabled) on prime, but I can still record directly...
ChannelName=$(echo ${Tuners} |sed 's/ /\n/g'|while read addr
do wget -O - -q ${addr}/lineup.xml | grep auto/${VCHANNEL}'<' |sed -e 's/.*<GuideName>//' -e 's/<.*//' -e 's/"//g'
done |sort -u)
##echo "channel name is :"${ChannelName}
if [[ 'z'${ChannelName} == 'z' ]] ; then echo;echo >&2 "The channel name was not found on Tuners - checking for signal"
foundCNT=$(echo ${Tuners} |sed 's/ /\n/g' |while read addr
do (( devCNT++))
wget -S --spider -q ${addr}:5004/auto/${VCHANNEL}; success=$?
if [[ ${success} -eq 0 ]]; then (( succCNT++ ));fi
echo >&2 signal found on ${addr}
echo ${succCNT}
done |tail -1)
if [[ ${foundCNT} -gt -0 ]] ; then ChannelName="Chnl-${_channel}"
else echo "Channel ${_channel} is not available on any tuner .";echo
exit 1
fi
fi
#######################################################################################
# An available tuner was found, so generate the header and start recording...
#######################################################################################
delim1=$(printf '\x47\x5f\xfa\x10')
delim2=$(printf '\x47\x1f\xfa\x11')
delim3=$(printf '\x47\x1f\xfa\x12')
delim4=$(printf '\x47\x1f\xfa\x13')
delim5=$(printf '\x47\x1f\xfa\x14')
hival=$(printf '\xff\xff\xff')
empty=$(for (( i=0;i<7;i++ )); do hival=${hival}${hival};done; echo ${hival})
Opener='{'
a='"ChannelName":"'${ChannelName}'","ChannelNumber":"'${_channel}'",'
##b='"DisplayGroupID":"00000000","DisplayGroupTitle":"Deprecated Groups",'
##c='"SeriesID":"0000000a","ProgramID":"0000000a","EpisodeNumber":"ad hoc",'
c='"SeriesID":"'${_seriesID}'","ProgramID":"'${_programID}'","EpisodeNumber":"ad hoc",'
d='"OriginalAirdate":'${hdrStart}',"RecordStartTime":'${hdrStart}',"StartTime":'${hdrStart}','
e='"EndTime":'${hdrEnd}',"RecordEndTime":'${hdrEnd}','
f='"EpisodeTitle":"'${_minutes}':Minutes -- Channel:'${_channel}' -- '${ChannelName}'",'
g='"Synopsis":"This is an ad hoc recording that was manually started","Title":"'${_title}'"'
Closer='}'
basehdr=${Opener}${a}${b}${c}${d}${e}${f}${g}${Closer}${empty}
##basehdr=${Opener}${a}${c}${d}${e}${f}${g}${Closer}${empty}${empty}
rec1=${delim1}${basehdr::184}
rec2=${delim2}${basehdr:184:184}
rec3=${delim3}${basehdr:368:184}
rec4=${delim4}${basehdr:552:184}
rec5=${delim5}${empty::184}
header=${rec1}${rec2}${rec3}${rec4}
echo ${header}$(for ((i=5;i<65;i++)); do printf ${rec5::${#rec5}-${#i}}${i};done)G >${REC_FILE}
##echo ${header}G >${REC_FILE}
##exit
######################################################################################
######################################################################################
# Automatic tuner selection -- Station might not be available on all devices
# or all tuners may be busy
# Must have internet connection
#
######################################################################################
tryNext=true
##wget -O - -q my.hdhomerun.com/discover|sed -e '/IP/!d' -e 's/[,"]//g'|sort |while read tag addr
echo ${Tuners} |sed 's/ /\n/g'|while read addr
do
if [ ${tryNext} == false ]; then exit
else tryNext=false
echo $(date -u +%Y%m%d-%T):$(date)" Trying channel "${VCHANNEL} "ad-hoc record on tuner " ${addr} "for " ${_minutes} " minutes."| tee -a ${currLOG}
nohup >&- 2>&- wget -c -q -O ${REC_FILE} ${addr}:5004/auto/${VCHANNEL}?duration=${DURATION} ||tryNext=true
fi
done&
sleep 2
echo
######################################################################################