Scanning for new series
Added by Hiro Protagonist over 3 years ago
Looking through an EPG for a large number of channels can be a tiresome business.
I often find myself looking in the 'Episodes' column for s01.e01 to see when a new series is coming along
that I might want to record.
However the Web UI won't sort on the 'Episodes' column, so scanning it is tedious and error prone.
I've put together a script to automate that:
newseries.sh
#!/bin/bash curl -s --user "admin:secret" --digest http://localhost:9981/api/epg/events/grid?limit=999999 | sed -e 's/^.*\"entries\":\[//' -e 's/\}]\}$/\}/' -e 's/},/}\n/g' | grep -i s01.e01 | /usr/local/bin/epgparse.py > /tmp/newseries.txt
/usr/local/bin/epgparse.py
#!/usr/bin/python import json import sys from pprint import pprint lines = sys.stdin.readlines() length = len(lines) idx = 0 while idx < length: data = json.loads(lines[idx]) print data["channelName"], " - " ,data["title"].encode('utf-8'), " - " ,data["description"].encode('utf-8'),"\n" idx += 1
These scripts pull out the entire EPG and look for Episodes s01e01 and then print the Channel, Title and Description fields.
It should be run on a crontab equal to the period your EPG extends for [e.g. if your EPG covers a week, run it weekly,
if you run it daily you'll get a lot of overlap].
Note that this will only be useful if the EPG provider puts in consistent episode numbering.
You can pull the EPG from the API with new=1 set, but I found that got me lots of stuff like news programs etc.
Replies (2)
RE: Scanning for new series - Added by Hiro Protagonist over 3 years ago
A caveat for anyone who tries this:
The sed expression 's/},/}\n/g' is used to break the JSON up into one record per line. Older versions of sed may not support this.
I'm using digest authentication for curl to access TVH. This won't work unless you have digest authentication enabled in TVH.
If you're not using digest authentication, remove '--user "admin:secret" --digest' and change the url to http://admin:secret@localhost...'
You can run this on a different device to the one running TVH by changing localhost to something else in the URL.
RE: Scanning for new series - Added by Hiro Protagonist over 3 years ago
And here it is all done in python.
This version outputs the data in (very) basic html.
newseries.py
#!/usr/bin/python import json, sys, requests, datetime from requests.auth import HTTPDigestAuth from datetime import date # Modify url if you're accessing a remote host url = "http://localhost:9981/api/epg/events/grid" query={"limit": "999999"} # Update auth parameters to match your user & password. Use HTTPBasicAuth for basic authentication req = requests.get(url, params=query, auth=HTTPDigestAuth('admin', 'secret')) if (req.status_code == 200): data = json.loads(req.text) length = data["totalCount"] idx = 0 print "<html><body><TITLE>New Series</TITLE><H1>New Series as of ", date.today(), "</H1>" while idx < length: entry = data["entries"][idx] if (entry.has_key("seasonNumber") and entry.has_key("episodeNumber") and entry.has_key("description")): if (entry["seasonNumber"] == 1 and entry["episodeNumber"] == 1): print entry["channelName"].encode('utf-8'), " - " ,entry["title"].encode('utf-8'), " - " ,entry["description"].encode('utf-8'),"<p>\n" idx += 1 print "</body></html>" else: print "HTML error ", req.status_code