]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Filled out a bit more of the EPG metadata parsing in pyepg and fixed a problem with...
authorAdam Sutton <dev@adamsutton.me.uk>
Wed, 20 Jun 2012 15:16:06 +0000 (16:16 +0100)
committerAdam Sutton <dev@adamsutton.me.uk>
Mon, 30 Jul 2012 14:50:40 +0000 (15:50 +0100)
src/epg.c
src/epg.h
src/epggrab/pyepg.c
src/epggrab/xmltv.c
src/epggrab/xmltv.h

index ee7bcf90742f80131f4549ddbf1ac15437f6f9b1..12f7010f8ec4c314dbae052daaff1b3bb8bbbf31 100644 (file)
--- a/src/epg.c
+++ b/src/epg.c
@@ -1082,6 +1082,12 @@ int epg_episode_set_genre_str ( epg_episode_t *ee, const char **gstr )
   return epg_episode_set_genre(ee, genre, gcnt);
 }
 
+int epg_episode_set_is_bw ( epg_episode_t *e, uint8_t bw )
+{
+  if (!e) return 0;
+  return _epg_object_set_u8(e, &e->is_bw, bw);
+}
+
 static void _epg_episode_add_broadcast 
   ( epg_episode_t *episode, epg_broadcast_t *broadcast )
 {
@@ -1182,6 +1188,8 @@ htsmsg_t *epg_episode_serialize ( epg_episode_t *episode )
     htsmsg_add_str(m, "brand", episode->brand->uri);
   if (episode->season)
     htsmsg_add_str(m, "season", episode->season->uri);
+  if (episode->is_bw)
+    htsmsg_add_u32(m, "is_bw", 1);
   return m;
 }
 
@@ -1226,6 +1234,8 @@ epg_episode_t *epg_episode_deserialize ( htsmsg_t *m, int create, int *save )
     if ( (eb = epg_brand_find_by_uri(str, 0, NULL)) )
       *save |= epg_episode_set_brand(ee, eb);
   
+  *save |= epg_episode_set_is_bw(ee, htsmsg_get_u32_or_default(m , "is_bw", 0));
+
   return ee;
 }
 
@@ -1461,12 +1471,6 @@ int epg_broadcast_set_is_hd ( epg_broadcast_t *b, uint8_t hd )
   return _epg_object_set_u8(b, &b->is_hd, hd);
 }
 
-int epg_broadcast_set_is_bw ( epg_broadcast_t *b, uint8_t bw )
-{
-  if (!b) return 0;
-  return _epg_object_set_u8(b, &b->is_bw, bw);
-}
-
 int epg_broadcast_set_lines ( epg_broadcast_t *b, uint16_t lines )
 {
   if (!b) return 0;
@@ -1532,8 +1536,6 @@ htsmsg_t *epg_broadcast_serialize ( epg_broadcast_t *broadcast )
     htsmsg_add_u32(m, "is_widescreen", 1);
   if (broadcast->is_hd)
     htsmsg_add_u32(m, "is_hd", 1);
-  if (broadcast->is_bw)
-    htsmsg_add_u32(m, "is_widescreen", 1);
   if (broadcast->lines)
     htsmsg_add_u32(m, "lines", broadcast->lines);
   if (broadcast->aspect)
@@ -1589,8 +1591,6 @@ epg_broadcast_t *epg_broadcast_deserialize
     (*ebc)->is_widescreen = 1;
   if (!htsmsg_get_u32(m, "is_hd", &u32))
     (*ebc)->is_hd = 1;
-  if (!htsmsg_get_u32(m , "is_bw", &u32))
-    (*ebc)->is_bw = 1;
   if (!htsmsg_get_u32(m, "lines", &u32))
     (*ebc)->lines = u32;
   if (!htsmsg_get_u32(m, "aspect", &u32))
index a973a9f4c05fb03af4eb0079b25da43c8aa19fd0..5927b60b4a211f2647e22369867d7cb5d663cf3b 100644 (file)
--- a/src/epg.h
+++ b/src/epg.h
@@ -205,7 +205,9 @@ struct epg_episode
   // Note: do not use epnum directly! use the accessor routine
   char                      *image;         ///< Episode image
 
+  uint8_t                    is_bw;            ///< Is black and white
   // TODO: certification and rating
+  // TODO: film/year
 
   LIST_ENTRY(epg_episode)    blink;         ///< Brand link
   LIST_ENTRY(epg_episode)    slink;         ///< Season link
@@ -246,6 +248,8 @@ int epg_episode_set_genre_str    ( epg_episode_t *e, const char **s )
   __attribute__((warn_unused_result));
 int epg_episode_set_image        ( epg_episode_t *e, const char *i )
   __attribute__((warn_unused_result));
+int epg_episode_set_is_bw ( epg_episode_t *b, uint8_t bw )
+  __attribute__((warn_unused_result));
 
 // Note: this does NOT strdup the text field
 void epg_episode_get_epnum
@@ -293,7 +297,6 @@ struct epg_broadcast
   /* Some quality info */
   uint8_t                    is_widescreen;    ///< Is widescreen
   uint8_t                    is_hd;            ///< Is HD
-  uint8_t                    is_bw;            ///< Is black and white
   uint16_t                   lines;            ///< Lines in image (quality)
   uint16_t                   aspect;           ///< Aspect ratio (*100)
 
@@ -326,8 +329,6 @@ int epg_broadcast_set_is_widescreen ( epg_broadcast_t *b, uint8_t ws )
   __attribute__((warn_unused_result));
 int epg_broadcast_set_is_hd ( epg_broadcast_t *b, uint8_t hd )
   __attribute__((warn_unused_result));
-int epg_broadcast_set_is_bw ( epg_broadcast_t *b, uint8_t bw )
-  __attribute__((warn_unused_result));
 int epg_broadcast_set_lines ( epg_broadcast_t *b, uint16_t lines )
   __attribute__((warn_unused_result));
 int epg_broadcast_set_aspect ( epg_broadcast_t *b, uint16_t aspect )
index 7276083895eb1b6254100f27e7643c6e66850b7e..a5e71030b0c1d2b805df4a6bb54abae0eb9d960b 100644 (file)
@@ -26,6 +26,7 @@
 #include "spawn.h"
 #include "epg.h"
 #include "epggrab/pyepg.h"
+#include "epggrab/xmltv.h"
 #include "channels.h"
 
 static epggrab_channel_tree_t _pyepg_channels;
@@ -293,7 +294,9 @@ static int _pyepg_parse_episode ( htsmsg_t *data, epggrab_stats_t *stats )
     save |= epg_episode_set_genre(episode, genre, genre_cnt);
   }
 
-  /* TODO: extra metadata */
+  /* Content */
+  if ((htsmsg_get_map(tags, "blackandwhite")))
+    save |= epg_episode_set_is_bw(episode, 1);
 
   if (save) stats->episodes.modified++;
 
@@ -304,11 +307,12 @@ static int _pyepg_parse_broadcast
   ( htsmsg_t *data, channel_t *channel, epggrab_stats_t *stats )
 {
   int save = 0;
-  htsmsg_t *attr;//, *tags;
+  htsmsg_t *attr, *tags;
   epg_episode_t *episode;
   epg_broadcast_t *broadcast;
   const char *id, *start, *stop;
   time_t tm_start, tm_stop;
+  uint32_t u32;
 
   if ( data == NULL || channel == NULL ) return 0;
 
@@ -316,6 +320,7 @@ static int _pyepg_parse_broadcast
   if ((id      = htsmsg_get_str(attr, "episode")) == NULL) return 0;
   if ((start   = htsmsg_get_str(attr, "start")) == NULL ) return 0;
   if ((stop    = htsmsg_get_str(attr, "stop")) == NULL ) return 0;
+  if ((tags    = htsmsg_get_map(data, "tags")) == NULL) return 0;
 
   /* Find episode */
   if ((episode = epg_episode_find_by_uri(id, 1, &save)) == NULL) return 0;
@@ -333,8 +338,23 @@ static int _pyepg_parse_broadcast
   /* Set episode */
   save |= epg_broadcast_set_episode(broadcast, episode);
 
-  /* TODO: extra metadata */
-  
+  /* Quality */
+  u32 = htsmsg_get_map(tags, "hd") ? 1 : 0;
+  save |= epg_broadcast_set_is_hd(broadcast, u32);
+  u32 = htsmsg_get_map(tags, "widescreen") ? 1 : 0;
+  save |= epg_broadcast_set_is_widescreen(broadcast, u32);
+  // TODO: lines, aspect
+
+  /* Accessibility */
+  // Note: reuse XMLTV parse code as this is the same
+  xmltv_parse_accessibility(broadcast, tags);
+
+  /* New/Repeat */
+  u32 = htsmsg_get_map(tags, "new") || htsmsg_get_map(tags, "premiere");
+  save |= epg_broadcast_set_is_new(broadcast, u32);
+  u32 = htsmsg_get_map(tags, "repeat") ? 1 : 0;
+  save |= epg_broadcast_set_is_repeat(broadcast, u32);
+
   if (save) stats->broadcasts.modified++;  
 
   return save;
index fa29e02f9ae358929cdbe9f9f01ba20e85456632..2cfb52988e1fe13d6d561835abeef024e539af8f 100644 (file)
@@ -211,7 +211,7 @@ get_episode_info
  *       job
  */
 static int
-parse_vid_quality ( epg_broadcast_t *ebc, htsmsg_t *m )
+parse_vid_quality ( epg_broadcast_t *ebc, epg_episode_t *ee, htsmsg_t *m )
 {
   int save = 0;
   int hd = 0, lines = 0, aspect = 0;
@@ -219,7 +219,7 @@ parse_vid_quality ( epg_broadcast_t *ebc, htsmsg_t *m )
   if (!ebc || !m) return 0;
 
   if ((str = htsmsg_xml_get_cdata_str(m, "colour")))
-    save |= epg_broadcast_set_is_bw(ebc, strcmp(str, "no") ? 0 : 1);
+    save |= epg_episode_set_is_bw(ee, strcmp(str, "no") ? 0 : 1);
   if ((str = htsmsg_xml_get_cdata_str(m, "quality"))) {
     if (strstr(str, "HD")) {
       hd    = 1;
@@ -259,8 +259,8 @@ parse_vid_quality ( epg_broadcast_t *ebc, htsmsg_t *m )
 /*
  * Parse accessibility data
  */
-static int
-parse_accessibility ( epg_broadcast_t *ebc, htsmsg_t *m )
+int
+xmltv_parse_accessibility ( epg_broadcast_t *ebc, htsmsg_t *m )
 {
   int save = 0;
   htsmsg_t *tag;
@@ -328,16 +328,16 @@ _xmltv_parse_programme_tags(channel_t *ch, htsmsg_t *tags,
 
   /* Create/Find broadcast */
   ebc = epg_broadcast_find_by_time(ch, start, stop, 1, &save2);
-  if ( ebc != NULL ) {
+  if ( ebc ) {
     stats->broadcasts.total++;
     if (save2) stats->broadcasts.created++;
     save2 |= epg_broadcast_set_episode(ebc, ee);
 
     /* Quality metadata */
-    save2 |= parse_vid_quality(ebc, htsmsg_get_map(tags, "video"));
+    save2 |= parse_vid_quality(ebc, ee, htsmsg_get_map(tags, "video"));
 
     /* Accessibility */
-    save2 |= parse_accessibility(ebc, tags);
+    save2 |= xmltv_parse_accessibility(ebc, tags);
 
     /* Misc */
     if (htsmsg_get_map(tags, "previously-shown"))
index 7a2d1bee86fc8409ba2eae054e2bc803c78326d2..104842a7de393357b2d5f04bb6519e13ba3b0c15 100644 (file)
@@ -25,4 +25,7 @@
 void xmltv_init ( epggrab_module_list_t *list );
 void xmltv_load ( void );
 
+// reused by pyepg
+int xmltv_parse_accessibility ( epg_broadcast_t *ebc, htsmsg_t *m );
+
 #endif