diff --git a/src/epg.c b/src/epg.c
index 2b3c8470..378e2333 100644
--- a/src/epg.c
+++ b/src/epg.c
@@ -851,6 +851,16 @@ size_t epg_episode_number_format
return i;
}
+int epg_episode_fuzzy_match
+ ( epg_episode_t *episode, const char *uri, const char *title,
+ const char *summary, const char *description )
+{
+ if ( !episode ) return 0;
+ if ( uri && episode->_.uri && !strcmp(episode->_.uri, uri) ) return 1;
+ // TODO: how to match title/summary/description
+ return 0;
+}
+
htsmsg_t *epg_episode_serialize ( epg_episode_t *episode )
{
htsmsg_t *m;
@@ -1194,6 +1204,18 @@ int epg_channel_set_channel ( epg_channel_t *ec, channel_t *ch )
return save;
}
+int epg_channel_set_icon ( epg_channel_t *channel, const char *icon )
+{
+ int save = 0;
+ if ( !channel | !icon ) return 0;
+ if ( !channel->icon || strcmp(channel->icon, icon) ) {
+ if ( channel->icon ) free(channel->icon);
+ channel->icon = strdup(icon);
+ save = 1;
+ }
+ return save;
+}
+
epg_broadcast_t *epg_channel_get_broadcast
( epg_channel_t *channel, time_t start, time_t stop, int create, int *save )
{
diff --git a/src/epg.h b/src/epg.h
index 87e208c3..6eab8300 100644
--- a/src/epg.h
+++ b/src/epg.h
@@ -223,6 +223,11 @@ size_t epg_episode_number_format
const char *sep, const char *efmt,
const char *cfmt );
+/* Matching */
+int epg_episode_fuzzy_match
+ ( epg_episode_t *ee, const char *uri, const char *title,
+ const char *summary, const char *description );
+
/* Serialization */
htsmsg_t *epg_episode_serialize ( epg_episode_t *b );
epg_episode_t *epg_episode_deserialize ( htsmsg_t *m, int create, int *save );
diff --git a/src/epggrab/pyepg.c b/src/epggrab/pyepg.c
index 31de4c56..79c6e7a6 100644
--- a/src/epggrab/pyepg.c
+++ b/src/epggrab/pyepg.c
@@ -1,5 +1,19 @@
/*
- * PyEPG grabber
+ * Electronic Program Guide - pyepg grabber
+ * Copyright (C) 2012 Adam Sutton
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
*/
#define _GNU_SOURCE
diff --git a/src/epggrab/pyepg.h b/src/epggrab/pyepg.h
index 5e42a565..716baf43 100644
--- a/src/epggrab/pyepg.h
+++ b/src/epggrab/pyepg.h
@@ -1,12 +1,26 @@
/*
- * PyEPG grabber module
+ * Electronic Program Guide - pyepg grabber
+ * Copyright (C) 2012 Adam Sutton
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
*/
-#include "epggrab.h"
-
#ifndef EPGGRAB_PYEPG_H
#define EPGGRAB_PYEPG_H
+#include "epggrab.h"
+
epggrab_module_t* pyepg_init ( void );
#endif
diff --git a/src/epggrab/xmltv.c b/src/epggrab/xmltv.c
index 7e7d0bca..42a4174c 100644
--- a/src/epggrab/xmltv.c
+++ b/src/epggrab/xmltv.c
@@ -1,6 +1,6 @@
/*
- * Electronic Program Guide - xmltv interface
- * Copyright (C) 2007 Andreas Öman
+ * Electronic Program Guide - xmltv grabber
+ * Copyright (C) 2012 Adam Sutton
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -43,7 +43,9 @@
* Hash the description to get a URI for episode
*
* Note: converts to an ASCII format
+ * TODO: move somewhere else
*/
+#if 0
static const char *_xmltv_hash ( const char *str )
{
size_t i;
@@ -56,6 +58,7 @@ static const char *_xmltv_hash ( const char *str )
ret[MD5_DIGEST_LENGTH*2] = '\0';
return ret;
}
+#endif
/**
*
@@ -88,9 +91,7 @@ _xmltv_str2time(const char *str)
}
}
-#if TODO_XMLTV_EP_NUMBERING
-
-
+#if 0
/**
* This is probably the most obscure formating there is. From xmltv.dtd:
*
@@ -180,36 +181,29 @@ xmltv_ns_get_parse_num(const char *s, int *ap, int *bp)
static void
-parse_xmltv_ns_episode(const char *s, epg_episode_t *ee)
+parse_xmltv_ns_episode
+(const char *s, int *season, int *episode, int *part)
{
- int season;
- int episode;
- int part;
+ s = xmltv_ns_get_parse_num(s, season, NULL);
+ s = xmltv_ns_get_parse_num(s, episode, NULL);
+ xmltv_ns_get_parse_num(s, part, NULL);
- s = xmltv_ns_get_parse_num(s, &season, NULL);
- s = xmltv_ns_get_parse_num(s, &episode, NULL);
- xmltv_ns_get_parse_num(s, &part, NULL);
-
- if(season != -1)
- ee->ee_season = season + 1;
- if(episode != -1)
- ee->ee_episode = episode + 1;
- if(part != -1)
- ee->ee_part = part + 1;
+ *season += 1;
+ *episode += 1;
+ *part += 1;
}
/**
*
*/
static void
-get_episode_info(htsmsg_t *tags, epg_episode_t *ee)
+get_episode_info
+(htsmsg_t *tags, const char **screen, int *season, int *episode, int *part)
{
htsmsg_field_t *f;
htsmsg_t *c, *a;
const char *sys, *cdata;
- memset(ee, 0, sizeof(epg_episode_t));
-
HTSMSG_FOREACH(f, tags) {
if((c = htsmsg_get_map_by_field(f)) == NULL ||
strcmp(f->hmf_name, "episode-num") ||
@@ -218,10 +212,9 @@ get_episode_info(htsmsg_t *tags, epg_episode_t *ee)
(sys = htsmsg_get_str(a, "system")) == NULL)
continue;
- if(!strcmp(sys, "onscreen"))
- tvh_str_set(&ee->ee_onscreen, cdata);
+ if(!strcmp(sys, "onscreen")) *screen = cdata;
else if(!strcmp(sys, "xmltv_ns"))
- parse_xmltv_ns_episode(cdata, ee);
+ parse_xmltv_ns_episode(cdata, season, episode, part);
}
}
@@ -234,20 +227,37 @@ static int
_xmltv_parse_programme_tags(epg_channel_t *xc, htsmsg_t *tags,
time_t start, time_t stop, epggrab_stats_t *stats)
{
+#if TODO_XMLTV
int save = 0, save2 = 0;
- epg_broadcast_t *ebc;
epg_episode_t *ee;
+ epg_broadcast_t *ebc;
+ int sn = 0, en = 0, pn = 0;
+ const char *onscreen = NULL;
const char *uri = NULL;
const char *title = htsmsg_xml_get_cdata_str(tags, "title");
const char *desc = htsmsg_xml_get_cdata_str(tags, "desc");
-#if TODO_EPG_GENRE
const char *category = htsmsg_xml_get_cdata_str(tags, "category");
-#endif
+ get_episode_info(tags, &onscreen, &sn, &en, &pn);
+
+ /* Create/Find broadcast */
+ ebc = epg_broadcast_find_by_time(xc, start, stop, 1, &save2);
+ if ( ebc != NULL ) {
+ stats->broadcasts.total++;
+ if (save2) stats->broadcasts.created++;
+ save2 |= epg_broadcast_set_episode(ebc, ee);
+ if (save2) stats->broadcasts.modified++;
+ }
+
+ // TODO:
+ // do we attempt to make an episode URI from info?
+ // OR
+ // do we first try to find the broadcast and do a fuzzy check on params?
+ // OR
+ // do we do something else?
/* Generate a URI */
if ( desc )
uri = _xmltv_hash(desc);
- // TODO: what to do otherwise?
if ( !uri ) return 0;
/* Find episode */
@@ -256,24 +266,17 @@ _xmltv_parse_programme_tags(epg_channel_t *xc, htsmsg_t *tags,
if (save) stats->episodes.created++;
if (title) save |= epg_episode_set_title(ee, title);
if (desc) save |= epg_episode_set_description(ee, desc);
-#if TODO_EPG_GENRE
- if (category) save |= epg_episode_set_genre(ee, category);
-#endif
-#if TODO_XMLTV_EP_NUMBERING
- _get_episode_info(tags, &episode);
-#endif
+ if (category) save |= epg_episode_set_genre_str(ee, category);
+ if (onscreen) save |= epg_episode_set_onscreen(ee, onscreen);
+ if (pn) save |= epg_episode_set_part(ee, pn, 0);
+ if (en) save |= epg_episode_set_number(ee, en);
+ // TODO: how can we handle season number?
if (save) stats->episodes.modified++;
- /* Create broadcast */
- ebc = epg_broadcast_find_by_time(xc, start, stop, 1, &save2);
- if ( ebc != NULL ) {
- stats->broadcasts.total++;
- if (save2) stats->broadcasts.created++;
- save2 |= epg_broadcast_set_episode(ebc, ee);
- if (save2) stats->broadcasts.modified++;
- }
return save | save2;
+#endif
+ return 0;
}
@@ -313,8 +316,8 @@ static int
_xmltv_parse_channel(htsmsg_t *body, epggrab_stats_t *stats)
{
int save =0;
- htsmsg_t *attribs, *tags;/*, *subtag;*/
- const char *id, *name; /*,icon;*/
+ htsmsg_t *attribs, *tags, *subtag;
+ const char *id, *name, *icon;
epg_channel_t *xc;
if(body == NULL) return 0;
@@ -330,20 +333,11 @@ _xmltv_parse_channel(htsmsg_t *body, epggrab_stats_t *stats)
save |= epg_channel_set_name(xc, name);
}
-#if TODO_EPG_CHANNEL_META
if((subtag = htsmsg_get_map(tags, "icon")) != NULL &&
(attribs = htsmsg_get_map(subtag, "attrib")) != NULL &&
(icon = htsmsg_get_str(attribs, "src")) != NULL) {
-
- if(xc->xc_icon == NULL || strcmp(xc->xc_icon, icon)) {
- tvh_str_set(&xc->xc_icon, icon);
-
- LIST_FOREACH(ch, &xc->xc_channels, ch_xc_link)
- channel_set_icon(ch, icon);
- save = 1;
- }
+ save |= epg_channel_set_icon(xc, icon);
}
-#endif
if (save) stats->channels.modified++;
return save;
}
diff --git a/src/epggrab/xmltv.h b/src/epggrab/xmltv.h
index 3c501a13..bef9e6b9 100644
--- a/src/epggrab/xmltv.h
+++ b/src/epggrab/xmltv.h
@@ -1,6 +1,6 @@
/*
- * Electronic Program Guide - xmltv interface
- * Copyright (C) 2007 Andreas Öman
+ * Electronic Program Guide - xmltv grabber
+ * Copyright (C) 2012 Adam Sutton
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by