Settings format changed (muxes' services)
Added by Renato Riolino over 8 years ago
Hi.
I have some scripts that I use to extract some data from services (basically service name and service id).
The scripts scan all muxes on ~/.hts/tvheadend/input/dvb/networks/***MY_NETWORK_ID***/muxes and then read the services info from the files inside the subfolder "services".
Now I have updated my tvh (running 4.1-2088~g321fcc1~trusty now) and the "services" folder doesn't exist anymore inside the muxes folders. Looks like the file format is changed.
How can I get by shell script the service name and service ID from channels now?
Thanks
Replies (3)
RE: Settings format changed (muxes' services) - Added by Renato Riolino over 8 years ago
Sorry for asking again, but I still have not found a way to extract some data that I need.
Just to resume: I need to extract the "service name" and "service id" and the mux frequency and polarization for every channel.
Previously I could read this data from ~/.hts/tvheadend/input/dvb/networks/***MY_NETWORK_ID***/muxes in a subfolder "services". But this is not possible anymore.
Can anyone help me?
RE: Settings format changed (muxes' services) - Added by James Simpson over 8 years ago
Hi Renato,
I've been using the API via Python in order to gain information on the services. When using the API a JSON object is returned which you can parse and get the information.
http://<ip_for_tvh>:9981/api/service/list
That should return the JSON object for you. Below is a function from the script that I've written that will parse the JSON response and return the services that were found in last number of given days. It's part of a larger script that I use to email me if new services are found. It will inform me of the type of service and give me links to either map or disable the service from that email.
def getNew(self, offsetDays): ret = [] if self.services is None: self.get() if not self.services is None: for s in self.services['entries']: p = s['params'] svc = None for idx, val in enumerate(p): if val['id'] == 'created' and 'value' in val: c = val['value'] e = int(time.time()) o = e - (offsetDays * 24 * 60 * 60) if c > o: #new service so get the name and when it was found name = [val['value'] for idx, val in enumerate(p) if val['id'] == 'svcname' and 'value' in val] if len(name): svctype = [val['value'] for idx, val in enumerate(p) if val['id'] == 'dvb_servicetype' and 'value' in val] svctype = Services.DVBServiceType[svctype[0]] if Services.DVBServiceType.has_key(svctype[0]) else svctype[0] multiplex = [val['value'] for idx, val in enumerate(p) if val['id'] == 'multiplex' and 'value' in val][0] if '.m3u - ' in multiplex: svctype += ' (from playlist)' mapdata = urllib.urlencode({'node': json.dumps({'services': [s['uuid']], 'encrypted': False, 'merge_same_name': True}, separators=(',', ':'))}) disabledata = urllib.urlencode({'node': json.dumps([{'enabled': False, 'uuid': s['uuid']}], separators=(',', ':'))}) svc = (name[0], svctype, Mail.getDateTimeFromEpoch(c), (self.rest.getURL('/api/service/mapper/save', creds=True), mapdata), (self.rest.getURL('/api/idnode/save', creds=True), disabledata)) break if svc: ret.append(svc) if len(ret) == 0: ret = None else: ret = sorted(ret, key=itemgetter(1), reverse=True) return ret
Hope that helps.
RE: Settings format changed (muxes' services) - Added by Renato Riolino over 8 years ago
Thank you so much!!!
I didn't know about this JSON API.
Now I changed my shell script to parse from it all the data I needed.
If anyone is interested, here it is:
#!/bin/bash TVH_URL="http://tv_url:9981" TVH_USER="tvh_login" TVH_PASS="tvh_password" NETWORK_NAME="network_name_to_parse" JQ="`type -P jq`" if [ "$JQ" == "" ]; then echo "jq utility is needed!" exit 0 fi WGET="`type -P wget`" if [ "$WGET" == "" ]; then echo "wget utility is needed!" exit 0 fi SERVICE_FILE="`mktemp --tmpdir create_twin2cs_chinfo.XXXXXXXXXX`" $WGET --user $TVH_USER --password $TVH_PASS ${TVH_URL}/api/service/list -O $SERVICE_FILE 2>/dev/null ENTRIES=0 while ! [ "`${JQ} \".entries[${ENTRIES}]\" $SERVICE_FILE`" == "null" ]; do if [ "`${JQ} \".entries[${ENTRIES}].params\" $SERVICE_FILE`" == "null" ]; then ENTRIES=$[ $ENTRIES + 1 ] continue fi ID_ENABLED=$[ `${JQ} ".entries[${ENTRIES}].params[].id" $SERVICE_FILE | grep -n "enabled" | awk -F':' ' { print $1 } '` - 1 ] if ! [ "`${JQ} \".entries[${ENTRIES}].params[${ID_ENABLED}].value\" $SERVICE_FILE`" == "true" ]; then ENTRIES=$[ $ENTRIES + 1 ] continue fi ID_ENCRYPTED=$[ `${JQ} ".entries[${ENTRIES}].params[].id" $SERVICE_FILE | grep -n "encrypted" | awk -F':' ' { print $1 } '` - 1 ] if ! [ "`${JQ} \".entries[${ENTRIES}].params[${ID_ENCRYPTED}].value\" $SERVICE_FILE`" == "true" ]; then ENTRIES=$[ $ENTRIES + 1 ] continue fi ID_NETWORK=$[ `${JQ} ".entries[${ENTRIES}].params[].id" $SERVICE_FILE | grep -n "network" | awk -F':' ' { print $1 } '` - 1 ] if ! [ "`${JQ} \".entries[${ENTRIES}].params[${ID_NETWORK}].value\" $SERVICE_FILE`" == "\"${NETWORK_NAME}\"" ]; then ENTRIES=$[ $ENTRIES + 1 ] continue fi if [ "`${JQ} \".entries[${ENTRIES}].params[].id\" $SERVICE_FILE | grep -n \"caid\"`" == "" ]; then ENTRIES=$[ $ENTRIES + 1 ] continue fi ID_CAID=$[ `${JQ} ".entries[${ENTRIES}].params[].id" $SERVICE_FILE | grep -n "caid" | grep -v "force_caid" | awk -F':' ' { print $1 } '` - 1 ] CAID=`${JQ} ".entries[${ENTRIES}].params[${ID_CAID}].value" $SERVICE_FILE | awk -F'"' ' { print $2 } '` ID_SID=$[ `${JQ} ".entries[${ENTRIES}].params[].id" $SERVICE_FILE | grep -n "sid" | awk -F':' ' { print $1 } '` - 1 ] SID=`${JQ} ".entries[${ENTRIES}].params[${ID_SID}].value" $SERVICE_FILE` ID_MULTIPLEX=$[ `${JQ} ".entries[${ENTRIES}].params[].id" $SERVICE_FILE | grep -n "multiplex" | grep -v "multiplex_uuid" | awk -F':' ' { print $1 } '` - 1 ] MULTIPLEX=`${JQ} ".entries[${ENTRIES}].params[${ID_MULTIPLEX}].value" $SERVICE_FILE | awk -F'"' ' { print $2 } '` ID_SVCNAME=$[ `${JQ} ".entries[${ENTRIES}].params[].id" $SERVICE_FILE | grep -n "svcname" | awk -F':' ' { print $1 } '` - 1 ] SVCNAME=`${JQ} ".entries[${ENTRIES}].params[${ID_SVCNAME}].value" $SERVICE_FILE | awk -F'"' ' { print $2 } '` printf "%s:%04X:0B54:%04X.80 \"${SVCNAME}\"\n" ${CAID} ${SID} `echo ${MULTIPLEX//[A-Z]/}` ENTRIES=$[ $ENTRIES + 1 ] done rm $SERVICE_FILE exit 0
[]'s
Renato