Author: dmeyer
Date: Thu Mar 23 16:20:50 2006
New Revision: 1318

Modified:
   trunk/epg/src/client.py
   trunk/epg/src/program.py
   trunk/epg/src/server.py
   trunk/epg/src/source_vdr.py
   trunk/epg/src/source_xmltv.py
   trunk/epg/src/source_zap2it.py

Log:
support more attributes from the source

Modified: trunk/epg/src/client.py
==============================================================================
--- trunk/epg/src/client.py     (original)
+++ trunk/epg/src/client.py     Thu Mar 23 16:20:50 2006
@@ -66,14 +66,14 @@
 
 
     def _program_rows_to_objects(self, query_data):
-        cols = "parent_id", "start", "stop", "title", "desc", "id"#, "ratings"
+        cols = "parent_id", "id", "start", "stop", "title", "desc", \
+               "subtitle", "episode", "genre", "rating"
         results = []
         for row in db.iter_raw_data(query_data, cols):
             if row[0] not in self._channels_by_db_id:
                 continue
             channel = self._channels_by_db_id[row[0]]
-            program = Program(channel, row[1], row[2], row[3], row[4])
-            program.db_id = row[5]
+            program = Program(channel, *row[2:])
             results.append(program)
         return results
 

Modified: trunk/epg/src/program.py
==============================================================================
--- trunk/epg/src/program.py    (original)
+++ trunk/epg/src/program.py    Thu Mar 23 16:20:50 2006
@@ -2,12 +2,14 @@
 from channel import *
 
 class Program(object):
-    def __init__(self, channel, start, stop, title, description):
+    def __init__(self, channel, start, stop, title, description=u'',
+                 subtitle=u'', episode=u'', genre=u'', rating=u""):
         assert(type(channel) == Channel)
         self.channel = channel
         self.start = start
         self.stop = stop
         self.title = title
-        self.subtitle = u''
-        self.episode = u''
         self.description = description
+        self.subtitle = subtitle
+        self.episode = episode
+        self.genre = genre

Modified: trunk/epg/src/server.py
==============================================================================
--- trunk/epg/src/server.py     (original)
+++ trunk/epg/src/server.py     Thu Mar 23 16:20:50 2006
@@ -26,9 +26,12 @@
             [ ("start", "stop") ],
             title = (unicode, ATTR_KEYWORDS),
             desc = (unicode, ATTR_KEYWORDS),
-            date = (int, ATTR_SEARCHABLE),
             start = (int, ATTR_SEARCHABLE),
             stop = (int, ATTR_SEARCHABLE),
+            episode = (unicode, ATTR_SIMPLE),
+            subtitle = (unicode, ATTR_SIMPLE),
+            genre = (unicode, ATTR_SIMPLE),
+            date = (int, ATTR_SEARCHABLE),
             ratings = (dict, ATTR_SIMPLE)
         )
 
@@ -223,7 +226,7 @@
         return o["id"]
 
 
-    def _add_program_to_db(self, channel_db_id, start, stop, title, desc):
+    def _add_program_to_db(self, channel_db_id, start, stop, title, 
**attributes):
         start = int(start)
         stop = int(stop)
         
@@ -239,10 +242,10 @@
                stop == s1[0]['stop'] == s2[0]['stop']:
             # yes, update object if it is different
             prg = s1[0]
-            if prg['title'] != title and prg['desc'] != desc:
+            if prg['title'] != title:
                 log.info('update %s', title)
                 self._db.update_object(("program", prg["id"]), start = start,
-                                       stop = stop, title = title, desc = desc)
+                                       stop = stop, title = title, 
**attributes)
             return prg["id"]
 
         removed = []
@@ -261,7 +264,7 @@
         log.info('adding program: %s', title)
         o = self._db.add_object("program", parent = ("channel", channel_db_id),
                                 start = start, stop = stop, title = title, 
-                                desc = desc, ratings = 42)
+                                **attributes)
 
         if stop - start > self._max_program_length:
             self._max_program_length = stop = start

Modified: trunk/epg/src/source_vdr.py
==============================================================================
--- trunk/epg/src/source_vdr.py (original)
+++ trunk/epg/src/source_vdr.py Thu Mar 23 16:20:50 2006
@@ -136,7 +136,8 @@
                 desc = ''
 
             info.epg._add_program_to_db(chan_db_id, e.start, 
int(e.start+e.dur),
-                                        strutils.str_to_unicode(e.title), 
strutils.str_to_unicode(desc))
+                                        strutils.str_to_unicode(e.title),
+                                        
description=strutils.str_to_unicode(desc))
 
             info.cur +=1
             if info.cur % info.progress_step == 0:

Modified: trunk/epg/src/source_xmltv.py
==============================================================================
--- trunk/epg/src/source_xmltv.py       (original)
+++ trunk/epg/src/source_xmltv.py       Thu Mar 23 16:20:50 2006
@@ -89,25 +89,32 @@
     info.channel_id_to_db_id[channel_id] = [db_id, None]
 
 
+ATTR_MAPPING = {
+    'desc': 'description',
+    'sub-title': 'subtitle',
+    'episode-num': 'episode',
+    'category': 'genre' }
+
 def parse_programme(info):
     channel_id = info.node.getattr('channel')
     if channel_id not in info.channel_id_to_db_id:
         log.warning("Program exists for unknown channel '%s'" % channel_id)
         return
 
-    title = date = desc = None
-
+    title = None
+    attr = {}
+    
     for child in info.node.children:
         if child.name == "title":
             title = child.content
-        elif child.name == "desc":
-            desc = child.content
         elif child.name == "date":
             fmt = "%Y-%m-%d"
             if len(child.content) == 4:
                 fmt = "%Y"
-            date = time.mktime(time.strptime(child.content, fmt))
-
+            attr['date'] = int(time.mktime(time.strptime(child.content, fmt)))
+        elif child.name in ATTR_MAPPING.keys():
+            attr[ATTR_MAPPING[child.name]] = child.content
+            
     if not title:
         return
 
@@ -119,13 +126,13 @@
         # XXX This only works in sorted files. I guess it is ok to force the
         # user to run tv_sort to fix this. And IIRC tv_sort also takes care of
         # this problem.
-        last_start, last_title, last_desc = last_prog
-        info.epg._add_program_to_db(db_id, last_start, start, last_title, 
last_desc)
+        last_start, last_title, last_attr = last_prog
+        info.epg._add_program_to_db(db_id, last_start, start, last_title, 
**last_attr)
     if not info.node.getattr("stop"):
-        info.channel_id_to_db_id[channel_id][1] = (start, title, desc)
+        info.channel_id_to_db_id[channel_id][1] = (start, title, attr)
     else:
         stop = timestr2secs_utc(info.node.getattr("stop"))
-        info.epg._add_program_to_db(db_id, start, stop, title, desc)
+        info.epg._add_program_to_db(db_id, start, stop, title, **attr)
  
 
 class UpdateInfo:

Modified: trunk/epg/src/source_zap2it.py
==============================================================================
--- trunk/epg/src/source_zap2it.py      (original)
+++ trunk/epg/src/source_zap2it.py      Thu Mar 23 16:20:50 2006
@@ -153,7 +153,7 @@
     d["rating"] = str_to_unicode(node.prop("tvRating"))
 
     info.epg._add_program_to_db(info.stations_by_id[d["station_id"]]["db_id"], 
d["start"],
-                           d["stop"], d.get("title"), d.get("desc"))
+                           d["stop"], d.get("title"), 
description=d.get("desc"))
 
 
 def parse_program(node, info):


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to