From 3cbde1a1f912dadaa71a35751b96c8f7cccb305a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20Go=C5=82da?= Date: Mon, 7 Oct 2013 22:16:59 +0200 Subject: [PATCH] Support for star rating and age rating in xmltv and web ui --- .gitignore | 1 + src/epggrab/module/xmltv.c | 50 ++++++++++++++++++++++++++++++++++--- src/webui/extjs.c | 4 +++ src/webui/static/app/epg.js | 32 +++++++++++++++++++++--- 4 files changed, 79 insertions(+), 8 deletions(-) mode change 100644 => 100755 src/epggrab/module/xmltv.c mode change 100644 => 100755 src/webui/extjs.c mode change 100644 => 100755 src/webui/static/app/epg.js diff --git a/.gitignore b/.gitignore index d7e34f72..217c9961 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ data/dvb-scan *.pyc .*.sw[op] +*.bak debian/changelog debian/files diff --git a/src/epggrab/module/xmltv.c b/src/epggrab/module/xmltv.c old mode 100644 new mode 100755 index 8c7bc389..8acda8de --- a/src/epggrab/module/xmltv.c +++ b/src/epggrab/module/xmltv.c @@ -352,6 +352,9 @@ static int _xmltv_parse_previously_shown /* * Star rating + * + * 3.3/5 + * */ static int _xmltv_parse_star_rating ( epggrab_module_t *mod, epg_episode_t *ee, htsmsg_t *body ) @@ -359,6 +362,7 @@ static int _xmltv_parse_star_rating double a, b; htsmsg_t *stars, *tags; const char *s1, *s2; + char *s1end, *s2end; if (!mod || !ee || !body) return 0; if (!(stars = htsmsg_get_map(body, "star-rating"))) return 0; @@ -366,12 +370,51 @@ static int _xmltv_parse_star_rating if (!(s1 = htsmsg_xml_get_cdata_str(tags, "value"))) return 0; if (!(s2 = strstr(s1, "/"))) return 0; - a = atof(s1); - b = atof(s2 + 1); + a = strtod(s1, &s1end); + b = strtod(s2 + 1, &s2end); + if ( a == 0.0f || b == 0.0f) return 0; return epg_episode_set_star_rating(ee, (100 * a) / b, mod); } +/* + * Tries to get age ratingform element. + * Expects integer representing minimal age of watcher. + * Other rating types (non-integer, for example MPAA or VCHIP) are ignored. + * + * Attribute system is ignored. + * + * Working example: + * 16 + * + * Currently non-working example: + * + * PG + * + * + * + * TODO - support for other rating systems: + * [rating system=VCHIP] values TV-PG, TV-G, etc + * [rating system=MPAA] values R, PG, G, PG-13 etc + * [rating system=advisory] values "strong sexual content","Language", etc + */ +static int _xmltv_parse_age_rating + ( epggrab_module_t *mod, epg_episode_t *ee, htsmsg_t *body ) +{ + uint8_t age; + htsmsg_t *rating, *tags; + const char *s1; + + if (!mod || !ee || !body) return 0; + if (!(rating = htsmsg_get_map(body, "rating"))) return 0; + if (!(tags = htsmsg_get_map(rating, "tags"))) return 0; + if (!(s1 = htsmsg_xml_get_cdata_str(tags, "value"))) return 0; + + age = atoi(s1); + + return epg_episode_set_age_rating(ee, age, mod); +} + /* * Parse category list */ @@ -509,8 +552,7 @@ static int _xmltv_parse_programme_tags save3 |= _xmltv_parse_star_rating(mod, ee, tags); - - // TODO: parental rating + save3 |= _xmltv_parse_age_rating(mod, ee, tags); } /* Stats */ diff --git a/src/webui/extjs.c b/src/webui/extjs.c old mode 100644 new mode 100755 index 6ff9fbb8..6b47e490 --- a/src/webui/extjs.c +++ b/src/webui/extjs.c @@ -973,6 +973,10 @@ extjs_epg(http_connection_t *hc, const char *remain, void *opaque) htsmsg_add_u32(m, "start", e->start); htsmsg_add_u32(m, "end", e->stop); htsmsg_add_u32(m, "duration", e->stop - e->start); + if(ee->star_rating) + htsmsg_add_u32(m, "starrating", ee->star_rating); + if(ee->age_rating) + htsmsg_add_u32(m, "agerating", ee->age_rating); if(e->serieslink) htsmsg_add_str(m, "serieslink", e->serieslink->uri); diff --git a/src/webui/static/app/epg.js b/src/webui/static/app/epg.js old mode 100644 new mode 100755 index 9fc74aa8..e73b62b5 --- a/src/webui/static/app/epg.js +++ b/src/webui/static/app/epg.js @@ -40,6 +40,8 @@ tvheadend.epgDetails = function(event) { content += ''; content += '
' + event.episode + '
'; content += '
' + event.description + '
'; + content += '
' + event.starrating + '
'; + content += '
' + event.agerating + '
'; content += '
' + tvheadend.contentGroupLookupName(event.contenttype) + '
'; if (event.ext_desc != null) @@ -228,6 +230,10 @@ tvheadend.epg = function() { dateFormat : 'U' /* unix time */ }, { name : 'duration' + }, { + name : 'starrating' + }, { + name : 'agerating' }, { name : 'contenttype' }, { @@ -272,11 +278,17 @@ tvheadend.epg = function() { } } - function renderText(value, meta, record, rowIndex, colIndex, store) { - setMetaAttr(meta, record); + function renderText(value, meta, record, rowIndex, colIndex, store) { + setMetaAttr(meta, record); - return value; - } + return value; + } + + function renderInt(value, meta, record, rowIndex, colIndex, store) { + setMetaAttr(meta, record); + + return '' + value; + } var epgCm = new Ext.grid.ColumnModel([ actions, { width : 250, @@ -321,6 +333,18 @@ tvheadend.epg = function() { header : "Channel", dataIndex : 'channel', renderer : renderText + }, { + width : 50, + id : 'starrating', + header : "Stars", + dataIndex : 'starrating', + renderer : renderInt + }, { + width : 50, + id : 'agerating', + header : "Age", + dataIndex : 'agerating', + renderer : renderInt }, { width : 250, id : 'contenttype',