New XMLTVID stuff (was Re: [mythtvnz] Warning- XMLTV ID class - Sky Movie Greats and TV One)

Hadley Rich mythtvnz@lists.linuxnut.co.nz
Wed, 4 Jul 2007 16:05:25 +1200


--Boundary-00=_FyxiGlw8HUZiyKt
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

On Wed, 04 Jul 2007 15:26:45 Chris Manning wrote:
> Is there any progress on this? It would be good to be able to have movie
> greats etc available. I've noticed that there is a listings-new.xml.gz
> file on the server that has the right stuff in it. Is this usable
> currently?

Hi Chris,

I've been doing a little work on this this morning actually. I have removed 
listings-new.xml.gz from the server and added listings-sky.xml.gz (this is to 
differentiate from freeview if we decide to put one up).

I am now using this data on my own box and it appears to be working fine. It 
will be updated each day with the listings.xml.gz file.

As I'm not quite finished with the new epgsnoop (nearly!) I can't guarantee it 
will be quite as stable as the old feed but since I'm using it myself it will 
be fixed in a timely mannor if something does go wrong.

If you want to use it you'll need to update your database for the new 
xmltvid's, I've attached a script to do this and the channels.conf file to go 
with it. Run the script as a user that can run mythfrontend and it should 
pickup the database access automatically.

NOTE: The script will update 1035 to movie-greats etc. i.e. it assums you are 
using the Sky PIDs and not the freeview ones. If you are you will need to 
adjust things or it will break stuff.

hads

-- 
http://nicegear.co.nz
New Zealand's VoIP supplier

--Boundary-00=_FyxiGlw8HUZiyKt
Content-Type: application/x-python;
  name="update-xmltvids.py"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="update-xmltvids.py"

#!/usr/bin/python

# By hads <epgsnoop@nice.net.nz>

import os, sys
import shlex

try:
	import MySQLdb
except:
	sys.stderr.write("MySQLdb (python-mysqldb) is required but is not found.\n")
	sys.exit(1)

if len(sys.argv) != 2:
	sys.stderr.write('\nUsage: %s /path/to/channels.conf\n\n' % sys.argv[0])
	sys.exit(1)

channels = {}
channels_conf = sys.argv[1]

class Channel(object):
	xmltvid = None
	name = None
	icon = None
	url = None
	
	def __init__(self, pid):
		self.pid = pid

def get_db_connection():
	"""
	A connection to the mythtv database.
	"""
	config_files = [
		'/usr/local/share/mythtv/mysql.txt',
		'/usr/share/mythtv/mysql.txt',
		'/usr/local/etc/mythtv/mysql.txt',
		'/etc/mythtv/mysql.txt',
		os.path.expanduser('~/.mythtv/mysql.txt'),
	]
	if 'MYTHCONFDIR' in os.environ:
		config_locations.append('%s/mysql.txt' % os.environ['MYTHCONFDIR'])

	found_config = False
	for config_file in config_files:
		try:
			config = shlex.shlex(open(config_file))
		except:
			continue

		token = config.get_token()
		db_host = db_user = db_password = db_name = None
		while  token != config.eof and (db_host == None or db_user == None or db_password == None or db_name == None):
			if token == "DBHostName":
				if config.get_token() == "=":
					db_host = config.get_token()
			elif token == "DBUserName":
				if config.get_token() == "=":
					db_user = config.get_token()
			elif token == "DBPassword":
				if config.get_token() == "=":
					db_password = config.get_token()
			elif token == "DBName":
				if config.get_token() == "=":
					db_name = config.get_token()

			token = config.get_token()
		found_config = True
		break

	if not found_config:
		raise Exception("Unable to find MythTV configuration file")
	return MySQLdb.connect(user=db_user, host=db_host, passwd=db_password, db=db_name)

if os.path.isfile(channels_conf):
	channel_file_ok = False
	channel_info = []
	f = open(channels_conf)
	for line in f:
		channel_info.append(line.strip())
	f.close()
	for line in channel_info:
		if line == '# CHANNEL_ID|XMLTVID|NAME|ICON|WEBSITE':
			channel_file_ok = True
	if not channel_file_ok:
		sys.stderr.write('channels.conf appears to be out of date\n')
		sys.exit(1)

	for chan in channel_info:
		chan = chan.strip()
		if chan and chan[0] != '#':
			fields = chan.split('|')
			channel = Channel(fields[0])
			try:
				channel.xmltvid = fields[1]
			except IndexError:
				pass
			try:
				channel.name = fields[2]
			except IndexError:
				pass
			try:
				channel.icon = fields[3]
			except IndexError:
				pass
			try:
				channel.url = fields[4]
			except IndexError:
				pass
			channels['%s.dvb.guide' % fields[0]] = channel
else:
	sys.stderr.write('channels.conf not found\n')
	sys.exit(1)

db = get_db_connection()

db_channels = []
c = db.cursor()
c.execute("""SELECT DISTINCT xmltvid FROM channel""")
row = c.fetchone()
while row is not None:
	db_channels.append(row[0])
	row = c.fetchone()

for db_channel in db_channels:
	try:
		print '%s -> %s' % (db_channel, channels[db_channel].xmltvid)
		c.execute("""UPDATE channel SET xmltvid = %s WHERE xmltvid = %s""", (channels[db_channel].xmltvid, db_channel))
	except KeyError:
		print 'Channel not found in channels.conf (%s)' % db_channel
c.close()

--Boundary-00=_FyxiGlw8HUZiyKt
Content-Type: text/x-diff;
  charset="iso-8859-1";
  name="channels.conf"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="channels.conf"

###
#
# channels.conf
#
# This file is part of epgsnoop
#
# Entries are in the format show below;
#
# ***********************************
# *** The line below is important ***
# *** it is used by epgsnoop.     ***
# ***********************************
# CHANNEL_ID|XMLTVID|NAME|ICON|WEBSITE
#
# Channel packages
# - Sky
# - Sky Movies
# - Sky Rialto Channel
# - Sky Sport
# - Sky Rugby Channel
# - Sky Digital Music
# - Sky Playin'TV Games
# - Sky Arts Channel
# - Sky MindGames
# - Sky WTV
# - Sky Star Plus
# - Freeview
# - Prime
# - Maori TV
# - ?
###

#205|maori-tv.sky.co.nz|Maori TV|http://www.maoritelevision.com/

#319|preview.sky.co.nz|Preview||http://www.sky.co.nz/
#330||EPG Background Audio

#624||Grooves iTV
#678|playin-tv.sky.co.nz|Playin'TV|playing_tv.jpg
#679|weather-channel.sky.co.nz|Weather|weather_channel.jpg
#680|mindgames.sky.co.nz|MindGames|mind_games.jpg
#683||Panasonic
#684||Hell Pizza
#685||eMuse

#1000|preview.sky.co.nz|Preview||http://www.sky.co.nz/
1001|sky1.sky.co.nz|SKY 1|sky1.jpg
1002|movies1.sky.co.nz|SKY Movies 1|sky_movies1.jpg
1003|uktv.sky.co.nz|UKTV|uktv.jpg
1004|mgm.sky.co.nz|MGM|mgm.jpg
1005|rugby.sky.co.nz|Rugby Channel|rugby_channel.jpg
1006|cartoon-network.sky.co.nz|Cartoon Network|cartoon_network.jpg
1007|juice.sky.co.nz|Juice TV|juice_tv.jpg
1008|sport1.sky.co.nz|SKY Sport 1|sky_sport1.jpg
1009|sport2.sky.co.nz|SKY Sport 2|sky_sport2.jpg

1010|espn.sky.co.nz|ESPN|espn.jpg
1011|trackside.sky.co.nz|Trackside|trackside.jpg
1012|nat-geographic.sky.co.nz|Nat Geographic|national_geographic.jpg
1013|discovery.sky.co.nz|Discovery|discovery_channel.jpg
1014|animal-plant.sky.co.nz|Animal Planet|animal_planet.jpg
1015|cnn.sky.co.nz|CNN|cnn.jpg
1016|history-channel.sky.co.nz|History Channel|history_channel.jpg
1017|sky-news.sky.co.nz|SKY News|sky_news.jpg
1018|prime.sky.co.nz|Prime|prime.jpg|http://www.primetv.co.nz/
1019|j2.sky.co.nz|J2|j2.jpg

1020|rialto.sky.co.nz|Rialto|rialto.jpg|http://www.rialtochannel.co.nz/
1021|e.sky.co.nz|E!|e.jpg|
1022|living-channel.sky.co.nz|Living Channel|living_channel.jpg|http://www.livingchannel.co.nz/
1023|movies2.sky.co.nz|SKY Movies 2|sky_movies2.jpg
1024|nickelodeon.sky.co.nz|Nickelodeon|nick.jpg
1025|maori-tv.sky.co.nz|Maori TV|maori_tv.jpg
1026|bbc-world.sky.co.nz|BBC World|bbc_world.jpg
1027|disney-channel.sky.co.nz|Disney Channel|disney_channel.jpg
1028|cuetv.sky.co.nz|CUE TV|southland_tv.jpg|http://www.cuetv.co.nz/
1029|arts-channel.sky.co.nz|Arts Channel|arts_channel.jpg|http://www.theartschannel.co.nz/

#1030||AUX
1031|tv1.sky.co.nz|TV One|1.jpg|http://www.tv1.sky.co.nz/
1032|tv2.sky.co.nz|TV 2|2.jpg|http://www.tv2.sky.co.nz/
1033|tv3.sky.co.nz|TV 3|3.jpg|http://www.tv3.sky.co.nz/
1034|c4.sky.co.nz|C4|c4.jpg|http://www.c4.sky.co.nz/
1035|movie-greats.sky.co.nz|Sky Movie Greats|sky_movie_greats.jpg|http://www.sky.co.nz/
1036|sport-highlights.sky.co.nz|Sky Sport Highlights||http://www.sky.co.nz/
1037|prime.sky.co.nz|Prime|prime.jpg|http://www.primetv.co.nz/
1038|prime.sky.co.nz|Prime|prime.jpg|http://www.primetv.co.nz/
1039|mtv.sky.co.nz|MTV|mtv.jpg|http://www.mtv.co.nz/

1040|alttv.co.nz|Alt TV|alt_tv.jpg|http://www.alttv.co.nz/
1044|tcm.sky.co.nz|TCM|tcm.jpg
1045|playhouse.sky.co.nz|Playhouse|playhouse.jpg
1048|sport3.sky.co.nz|SKY Sport 3|sky_sport3.jpg
1049|mysky-preview.sky.co.nz|MY SKY Preview

#1050|preview.sky.co.nz|Preview|http://www.sky.co.nz/
1052|food-tv.sky.co.nz|Food Television|food_tv.jpg|http://www.foodtv.co.nz/
1057|fox-news.sky.co.nz|Fox News|fox_news.jpg
1059|documentary.sky.co.nz|Documentary|documentary.jpg

1060|box-office.sky.co.nz|SKY Box Office|sky_box_office.jpg|http://www.sky.co.nz/
1061|box-office201.sky.co.nz|SKY Box Office|sky_box_office.jpg|http://www.sky.co.nz/
1062|box-office202.sky.co.nz|SKY Box Office|sky_box_office.jpg|http://www.sky.co.nz/
1063|box-office203.sky.co.nz|SKY Box Office|sky_box_office.jpg|http://www.sky.co.nz/
1064|box-office204.sky.co.nz|SKY Box Office|sky_box_office.jpg|http://www.sky.co.nz/
1065|box-office205.sky.co.nz|SKY Box Office|sky_box_office.jpg|http://www.sky.co.nz/
1066|box-office206.sky.co.nz|SKY Box Office|sky_box_office.jpg|http://www.sky.co.nz/
1067|box-office207.sky.co.nz|SKY Box Office|sky_box_office.jpg|http://www.sky.co.nz/
1068|box-office208.sky.co.nz|SKY Box Office|sky_box_office.jpg|http://www.sky.co.nz/
1069|box-office209.sky.co.nz|SKY Box Office|sky_box_office.jpg|http://www.sky.co.nz/

1070|box-office210.sky.co.nz|SKY Box Office|sky_box_office.jpg|http://www.sky.co.nz/
1071|box-office211.sky.co.nz|SKY Box Office|sky_box_office.jpg|http://www.sky.co.nz/
1072|box-office212.sky.co.nz|SKY Box Office|sky_box_office.jpg|http://www.sky.co.nz/
1073|box-office213.sky.co.nz|SKY Box Office|sky_box_office.jpg|http://www.sky.co.nz/
1074|box-office214.sky.co.nz|SKY Box Office|sky_box_office.jpg|http://www.sky.co.nz/
1075|playboy.sky.co.nz|Playboy|playboy_tv.jpg|http://www.playboytv.co.nz/
1076|fresh.sky.co.nz|Fresh!|fresh.jpg|http://www.freshtelevision.co.nz/
1077|spice-excess.sky.co.nz|Spice Xcess|spice_excess.jpg|http://www.spicexcess.co.nz/
1078|ktv1.sky.co.nz|KTV 1|ktv1.jpg|http://www.ktv.co.nz
1079|ktv2.sky.co.nz|KTV 2|ktv2.jpg|http://www.ktv.co.nz

1080|jtv.sky.co.nz|JTV|jtv.jpg|http://www.wtv.co.nz/
1081|ctv1.sky.co.nz|CTV 1|ctv1.jpg|http://www.wtv.co.nz/
1082|ctv2.sky.co.nz|CTV 2|ctv2.jpg|http://www.wtv.co.nz/
1083|ctv3.sky.co.nz|CTV 3|ctv3.jpg|http://www.wtv.co.nz/
1084|ctv4.sky.co.nz|CTV 4|ctv4.jpg|http://www.wtv.co.nz/
1085|ctv5.sky.co.nz|CTV 5|ctv5.jpg|http://www.wtv.co.nz/
1086|ctv6.sky.co.nz|CTV 6|ctv6.jpg|http://www.wtv.co.nz/
1087|ctv7.sky.co.nz|CTV 7|ctv7.jpg|http://www.wtv.co.nz/
1088|real-good-life.sky.co.nz|Real Good Life||http://www.wtv.co.nz/
1089|new-supremo.sky.co.nz|New Supremo||http://www.wtv.co.nz/

1091|star-plus-hindi.sky.co.nz|Star Plus Hindi
1093|cctv9.sky.co.nz|CCTV-9|cctv9.jpg|
1099|shine.sky.co.nz|Shine|shine.jpg|http://www.shinetv.co.nz/

1101|national.radio.sky.co.nz|National Radio|national_radio.jpg
1102|concert-fm.radio.sky.co.nz|Concert FM|concert_fm.jpg
1103|nui-fm.radio.sky.co.nz|Niu FM|niu_fm.jpg
1104|george-fm.radio.sky.co.nz|George FM|george_fm.jpg
1105|tahu-fm.radio.sky.co.nz|Tahu FM|tahu_fm.jpg
1107|calvary.radio.sky.co.nz|Calvary|calvary.jpg

1100|kiwi.music.sky.co.nz|Kiwi|digital_music.jpg|http://www.sky.co.nz/
1120|nz-chart.music.sky.co.nz|NZ Chart|digital_music.jpg|http://www.sky.co.nz/
1121|pop.music.sky.co.nz|Pop|digital_music.jpg|http://www.sky.co.nz/
1122|smooth.music.sky.co.nz|Smooth|digital_music.jpg|http://www.sky.co.nz/
1123|grooves.music.sky.co.nz|Grooves|digital_music.jpg|http://www.sky.co.nz/
1124|jazz.music.sky.co.nz|Jazz|digital_music.jpg|http://www.sky.co.nz/
1125|house.music.sky.co.nz|House|digital_music.jpg|http://www.sky.co.nz/
1126|fifties-sixties.music.sky.co.nz|50's & 60's|digital_music.jpg|http://www.sky.co.nz/
1127|party.music.sky.co.nz|Party|digital_music.jpg|http://www.sky.co.nz/
1128|rock.music.sky.co.nz|Rock|digital_music.jpg|http://www.sky.co.nz/
1129|country.music.sky.co.nz|Country|digital_music.jpg|http://www.sky.co.nz/

1130|classical.music.sky.co.nz|Classical|digital_music.jpg|http://www.sky.co.nz/
1131|kids.music.sky.co.nz|Kids|digital_music.jpg|http://www.sky.co.nz/
1132|blues.music.sky.co.nz|Blues|digital_music.jpg|http://www.sky.co.nz/
1133|special.music.sky.co.nz|Special|digital_music.jpg|http://www.sky.co.nz/

1191|playin-tv.sky.co.nz|Playin'TV|playing_tv.jpg
1192|weather-channel.sky.co.nz|Weather|weather_channel.jpg
1193|mindgames.sky.co.nz|MindGames|mind_games.jpg
#1197||Ad Tracks
#1198||Auxiliary
#1199||VCR SCART Input

#1203||My Interaction
#1222||Panasonic
#1294||Hell Pizza

#1485||eMuse

#1901||Test 1
#1902||Test 2
#1903||Test 3
#1904||Test 4

1911|firecall.sky.co.nz|Firecall
#1912||Ambulance
#1920|tv3.sky.co.nz|TV 3|3.jpg|http://www.tv3.sky.co.nz/
#1921|c4.sky.co.nz|C4|c4.jpg|http://www.c4.sky.co.nz/
#1929||Radio NZ National
#1930||Radio NZ Concert

--Boundary-00=_FyxiGlw8HUZiyKt--