Python TV-Guide development?
#1
i think that for the tv guide requests to have any hope of succeeding, the ty guide script needs to be implmented in two parts.

one part is a reusable tv guide display which can be used for all tv guides with language etc. this module will allow the user to select which tv guide they want, time, date, channel lists etc.

the other module will be a script which grabs the appropriate tv guide from somewhere. this part needs to be replacable for different areas, and should be easily implemented so that we can get the maximum amount of people implmenting it for their part of the world. possibly it would consist of just a couple of functions that will take a date and time (span?) and retrieve all shows for that time. their might be an info method that would return information on the channels covered and the number of channels
eg
tvgrabinfo->region = "gotham city"
tvgrabinfo->type = "free to air"
tvgrabinfo->number = 7

the grabber would return xml with all shows it can get and the time span covered. caching would be nice in the main module.

any thoughts from anyone?
Reply
#2
nlemoz,

i'm currently working on tv guide script that works like this:

the first is a daemon written in perl that resides on a linux/windows server, and reads in the xmltv file twice a day. in this way the xmltv file can be acquired as is normal on linux (using whatever script what is available via xmltv.org in a crontab.)

the second part is a python plugin frontend for xmbc, which connects to the server and gets all its data from the perl daemon, already nicely parsed.

it's almost finished, tvguide works ok, currently testing the recording stuff (you can put items in a recording queue, and the perl deamon will run mencoder at the appropriate time with the apprioprate channel etc.).

this will not help for people who don't have a server. maybe someone could run the perl deamon on a public internet server for specific languages/regions for xbox's to connect to via internet (don't know how fast this would be though..) (and disabling the recording option ofcourse Wink.

when i think the script is tested ok, and releasable Wink, i'll post i link to the stuff here.

dop
Reply
#3
i started a tv guide in python using the listing.xml used in xbmp tv guide.
but i decided to stop it so i may share my work later for people who want to continue it
Reply
#4
for some reason i must have turned reply notification off, so i didn't see your replies until now.

both of these projects sound very interesting. between the last time i checked this forum and now, i made a python script that grabs a tv listing for my area (australia) and prints out xml data to a (windows text) console. i haven't worked out how to make it a module so it could be called from a front-end because this is my first day with python (although i have adequate experience with other languages).

i noticed that there is already a perl based xmltv grabber for my area, but i wanted one in python for the xbox so i built it. still needs a bit of error checking and doco, and of course an xbox front end, but we'll see.

i would be very interested to see what you guys have so far.
maybe you could add an option to run a local (python) xmltv grabber and/or read in a local xml file.
Reply
#5
here's my script for yahoo tv. it still needs some work, for instance:
details grabbing
caching
more error checking
could make the extraction more robust
make it more xmltv like

noticed before that tabs don't work that well in this bb... had to replace them with spaces. it prints out an xml version of
yahoo tv aus
for the current time and date.
should not take too much work to adapt it to other yahoo regions (eg us etc)

Quote:# project : tv guide
import urllib
import string
from datetime import date,timedelta
import time

# request the page
def geturl(serveradr,pagepath):
    import urllib
    opener = urllib.fancyurlopener({})
    doc = opener.open('http://' + serveradr + pagepath)
    data = doc.read()  # read file
    doc.close()
    return data


#extract program data to list of lists
def extractdata(in_string, start_chan_desc, end_chan_desc):
    #separate channels and drop the top part
    channels=in_string.split('venueresults.html')
    channels.pop(0)

    tv_data = []
   
    for i in channels:
         try:
              # get channel names
              start_index = string.index(i,start_chan_desc)+len(start_chan_desc)
              end_index = string.index(i,end_chan_desc,start_index)
              current_chan = i[start_index:end_index]
         except:
              continue
         
         start_pos = end_index
         while (1):
              try:
                   prog_data = []
                   
                   #find time
                   start_pos = string.index(i,':',start_pos)-2
                   end_pos = string.index(i,'<br>',start_pos)
                   prog_hour = i[start_pos:start_pos+2].strip().zfill(2)
                   prog_min = i[start_pos+3:start_pos+5].strip()
                   if i[start_pos+5:start_pos+7] == "pm":
                        prog_hour = str(string.atoi(prog_hour)+12)
                   
                   #find name
                   start_pos = string.index(i,'event.html',end_pos)++len('event.html')
                   start_pos = string.index(i,'\">',start_pos)++len('\">')
                   end_pos = string.index(i,'</a>',start_pos)
                   program = i[start_pos:end_pos]
                   start_pos = end_pos
                   
                   
                   prog_data.append(current_chan)
                   prog_data.append(prog_hour+prog_min)
                   prog_data.append(program)
                   
                   tv_data.append(prog_data)

              except:
                   break
    return tv_data #return slice

#handle the returned stuff and generate a new page
def get_guide(tv_date, tv_time):
   
    # get guide info
    serveradr='au.tv.yahoo.com'
    region = '94'
    pagepath='/results.html/results.html?rg='+region+'&vn=&dt=' + str(tv_date.year) + '-' + str(tv_date.month) + '-'  + str(tv_date.day) + '&ts=' + tv_time
    #print 'http://'+serveradr+pagepath
    rawdata=geturl(serveradr, pagepath)
   
    # process data
    start_chan_desc = 'target=_parent>'
    end_chan_desc = '</a>'
    v=extractdata(rawdata, start_chan_desc, end_chan_desc)
   
    # return result and extract programs
    xmldata = "<tv>\n"

    for i in v:
         xmldata += '\t<programme channel='+ str(i[0]) + ' start=\"' + str(tv_date.year) + str(tv_date.month).zfill(2)
         xmldata += str(tv_date.day).zfill(2) + i[1]+ ' aest\">\n'
         xmldata += '\t\t<title>'+i[2]+'</title>\n'
         xmldata += '\t</programme>\n'
         
    xmldata += "</tv>"
    return xmldata
   
def main():
    now_date = date.today()
    now_time = time.localtime()
    output = get_guide(now_date, str(now_time[3]).zfill(2))
    print output
   
#call main function
main()
Reply
#6
have written the almost all of the backend, now porting to the xbox (from windows) and writing the gui.

i have a couple of questions:

sys.argv[0] doesn't seem to be defined??
if it isn't, how else can i find dircetory that script was launched from?

import xml.parsers.expat fails with "no module named pyexpat", do i need to manually add, update from cvs, use a different parser or what?
Reply
#7
found that post by darkie that says he has implemnted pyexpat and added it to cvs.
the post was in feb, but the last python.rar was in jan Huh
must be that anon cvs update issue he was talking about.
Reply
#8
nlemoz: i tried to use the xml parsers that python normally supports without much luck as well when i started work on my scripts. i ended up writing a quick and dirty parser class using some regular expressions. you're welcome to use it if it will save you some time... you can grab it from the python/lib dir in the archive in this directory. it is called simplexml.py and it has some documentation at the top of the file (run pydoc on it).
Reply
#9
Quote:found that post by darkie that says he has implemnted pyexpat and added it to cvs.
the post was in feb, but the last python.rar was in jan
must be that anon cvs update issue he was talking about.
pyexpat is not added to python.rar but hard coded into the xbmc source code. so you need to build xbmc yourself from cvs
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#10
a little status update.
i have almost finished an alpha of the tv guide.
it now works reasonably well (imho)

things to do:
allow reordering of channels in display
vertical spacing of shows by time/duration

to make this whole thing work, i will need to build more listing grabbers. here is a smal spec for a grabber:

requirements:
can have any name ending in grabber.py

must have a function getinfo() that returns a list with a grabber description and channel names

eg
def getinfo():
return [["aus fta renmark"],["abc","win","sbs"]]

must have a function
getguide(tv_date, tv_time, sel_channels)

which takes a python date(tv_date), an integer indicating the hout in 24 hour format, and a list of strings (taht have been returned from getinfo() ) indicating channels that should be grabbed for this date and time.

it must return a text string consisting of xml as follows:

<programme channel="win" start="200404060400">
<title>"justice league"</title>
</programme>
<programme channel="win" start="200404060430">
<title>"good morning america"</title>
</programme>
<programme channel="sbs" start="200404061250">
<title>"pol pot and the khmer rouge"</title>
</programme>

where numbers like 200404061250 indicate date and time of the program <span style='color:red'>in gmt</span>. this is very close to the mythtv format, so i am hoping it would be easy to adapt current grabbers.

i have avoided specifying that the duration of the show should be in the returned text, as this makes writing the grabber a lot easier. i have also left off the description category, as most grabbers that get all descriptions cause far too many hits on the target website. i may put in an optional field that can be returned that might be used by the guide to get the grabber to retrieve details for one show, but it would be optional.

anyway, what do people think, will anybody be interested in coding these for their own region?
Reply
#11
i probably should also mention that almost all of the grabbers should be able to be coded and debugged on a pc (or a mac etc) without going near an xbox. this should also make life easier for potential coders. i can also provide people with a few sample grabbers that can be modified.
Reply
#12
hi, nlemoz i really appreciate what your doing, i just have one question, does the parser you're working on support wa and foxtel? :)

also, i like to use yourtv.com.au as my internet tv guide, but i've heard the objecting to projects like this using their guide for some reason.
Reply
#13
the current grabbers use yahoo australia's tv guides. they lists just about everything, so only minor modifications would be needed for different regions. they list optus, foxtel and free to air.

i will build a grabber for each of foxtel optus and fta and provide a readme for the simple modification to set it for your region. the way it would work is, you download a grabber, change it for your region if necessary following simple instructions, and then ftp it to a directory on the xbox. the tv guide will then display it in its settings as a selection for guide grabbing. you can have as many grabbers as you want and the guide will pick them up automatically. all this is done now.

i suppose people will want to look at the app before they decide if it's worth it to write a grabber. the problem is i can't write a grabber for every region on the planet on my own.
Reply
#14
im in the aussie region and would love to try out this new tvguide code. reckon you can post it
Reply

Logout Mark Read Team Forum Stats Members Help
Python TV-Guide development?0