From: E.Smith <31170571+azlm8t@users.noreply.github.com> Date: Wed, 20 Sep 2017 10:44:10 +0000 (+0100) Subject: xmltv: Parse copyright year from xmltv and display in GUI. (#4441). X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=16c64bc472c2d4eb956fca439bd786a78a977b9b;p=thirdparty%2Ftvheadend.git xmltv: Parse copyright year from xmltv and display in GUI. (#4441). --- diff --git a/src/api/api_epg.c b/src/api/api_epg.c index c9c5e17ff..8a39d6e36 100644 --- a/src/api/api_epg.c +++ b/src/api/api_epg.c @@ -185,6 +185,9 @@ api_epg_entry ( epg_broadcast_t *eb, const char *lang, access_t *perm, const cha if (ee->age_rating) htsmsg_add_u32(m, "ageRating", ee->age_rating); + if (ee->copyright_year) + htsmsg_add_u32(m, "copyrightYear", ee->copyright_year); + /* Content Type */ m2 = NULL; LIST_FOREACH(eg, &ee->genre, link) { diff --git a/src/epg.c b/src/epg.c index 301fd8ed4..d6ca56d70 100644 --- a/src/epg.c +++ b/src/epg.c @@ -1030,6 +1030,8 @@ int epg_episode_change_finish save |= epg_episode_set_age_rating(episode, 0, NULL); if (!(changes & EPG_CHANGED_FIRST_AIRED)) save |= epg_episode_set_first_aired(episode, 0, NULL); + if (!(changes & EPG_CHANGED_COPYRIGHT_YEAR)) + save |= epg_episode_set_copyright_year(episode, 0, NULL); return save; } @@ -1216,6 +1218,14 @@ int epg_episode_set_star_rating changed, EPG_CHANGED_STAR_RATING); } +int epg_episode_set_copyright_year + ( epg_episode_t *episode, uint16_t year, uint32_t *changed ) +{ + if (!episode) return 0; + return _epg_object_set_u16(episode, &episode->copyright_year, year, + changed, EPG_CHANGED_COPYRIGHT_YEAR); +} + int epg_episode_set_age_rating ( epg_episode_t *episode, uint8_t age, uint32_t *changed ) { @@ -1354,6 +1364,8 @@ htsmsg_t *epg_episode_serialize ( epg_episode_t *episode ) htsmsg_add_u32(m, "is_bw", 1); if (episode->star_rating) htsmsg_add_u32(m, "star_rating", episode->star_rating); + if (episode->copyright_year) + htsmsg_add_u32(m, "copyright_year", episode->copyright_year); if (episode->age_rating) htsmsg_add_u32(m, "age_rating", episode->age_rating); if (episode->first_aired) @@ -1428,6 +1440,9 @@ epg_episode_t *epg_episode_deserialize ( htsmsg_t *m, int create, int *save ) if (!htsmsg_get_u32(m, "star_rating", &u32)) *save |= epg_episode_set_star_rating(ee, u32, &changes); + if (!htsmsg_get_u32(m, "copyright_year", &u32)) + *save |= epg_episode_set_copyright_year(ee, u32, &changes); + if (!htsmsg_get_u32(m, "age_rating", &u32)) *save |= epg_episode_set_age_rating(ee, u32, &changes); diff --git a/src/epg.h b/src/epg.h index 299dd28c9..e775f0964 100644 --- a/src/epg.h +++ b/src/epg.h @@ -304,6 +304,7 @@ epg_season_t *epg_season_deserialize ( htsmsg_t *m, int create, int *save ); #define EPG_CHANGED_FIRST_AIRED (1<<(EPG_CHANGED_SLAST+12)) #define EPG_CHANGED_BRAND (1<<(EPG_CHANGED_SLAST+13)) #define EPG_CHANGED_SEASON (1<<(EPG_CHANGED_SLAST+14)) +#define EPG_CHANGED_COPYRIGHT_YEAR (1<<(EPG_CHANGED_SLAST+15)) /* Episode numbering object - this is for some back-compat and also * to allow episode information to be "collated" into easy to use object @@ -337,7 +338,11 @@ struct epg_episode uint8_t star_rating; ///< Star rating uint8_t age_rating; ///< Age certificate time_t first_aired; ///< Original airdate - + uint16_t copyright_year; ///< xmltv DTD gives a tag "date" (separate to previously-shown/first aired). + ///< This is the date programme was "finished...probably the copyright date." + ///< We'll call it copyright_year since words like "complete" and "finished" + ///< sound too similar to dvr recorded functionality. We'll only store the + ///< year since we only get year not month and day. LIST_ENTRY(epg_episode) blink; ///< Brand link LIST_ENTRY(epg_episode) slink; ///< Season link epg_brand_t *brand; ///< (Grand-)Parent brand @@ -409,6 +414,9 @@ int epg_episode_set_first_aired int epg_episode_set_star_rating ( epg_episode_t *e, uint8_t stars, uint32_t *changed ) __attribute__((warn_unused_result)); +int epg_episode_set_copyright_year + ( epg_episode_t *e, uint16_t stars, uint32_t *changed ) + __attribute__((warn_unused_result)); int epg_episode_set_age_rating ( epg_episode_t *e, uint8_t age, uint32_t *changed ) __attribute__((warn_unused_result)); diff --git a/src/epggrab/module/xmltv.c b/src/epggrab/module/xmltv.c index b96bb669f..f02b6c1ea 100644 --- a/src/epggrab/module/xmltv.c +++ b/src/epggrab/module/xmltv.c @@ -351,6 +351,36 @@ static int _xmltv_parse_previously_shown return ret; } +/* + * Date finished, typically copyright date. + */ +static int _xmltv_parse_date_finished + ( epg_episode_t *ee, + htsmsg_t *tag, uint32_t *changes ) +{ + if (!ee || !tag) return 0; + const char *str = htsmsg_xml_get_cdata_str(tag, "date"); + if (str) { + /* Technically the date could contain information about month + * and even second it was completed. We only want the four + * digit year. + */ + const size_t len = strlen(str); + if (len >= 4) { + char year_buf[32]; + strncpy(year_buf, str, 4); + year_buf[5] = 0; + const uint16_t year = atoi(year_buf); + /* Sanity check the year before copying it over. */ + if (year && year > 1800 && year < 2500) { + return epg_episode_set_copyright_year(ee, year, changes); + } + } + } + return 0; +} + + /* * Star rating * @@ -724,6 +754,8 @@ static int _xmltv_parse_programme_tags save3 |= _xmltv_parse_star_rating(ee, tags, &changes3); + save3 |= _xmltv_parse_date_finished(ee, tags, &changes3); + save3 |= _xmltv_parse_age_rating(ee, tags, &changes3); if (icon) diff --git a/src/htsp_server.c b/src/htsp_server.c index 667f70dad..ab14cc37d 100644 --- a/src/htsp_server.c +++ b/src/htsp_server.c @@ -1259,6 +1259,8 @@ htsp_build_event htsmsg_add_u32(out, "ageRating", ee->age_rating); if (ee->star_rating) htsmsg_add_u32(out, "starRating", ee->star_rating); + if (ee->copyright_year) + htsmsg_add_u32(out, "copyrightYear", ee->copyright_year); if (ee->first_aired) htsmsg_add_s64(out, "firstAired", ee->first_aired); epg_episode_get_epnum(ee, &epnum); diff --git a/src/webui/static/app/epg.js b/src/webui/static/app/epg.js index 09180afc2..325361a29 100644 --- a/src/webui/static/app/epg.js +++ b/src/webui/static/app/epg.js @@ -106,6 +106,8 @@ tvheadend.epgDetails = function(event) { content += '
' + event.title; if (event.subtitle) content += " : " + event.subtitle; + if (event.copyrightYear) + content += " (" + event.copyrightYear + ")"; content += '
'; if (event.episodeOnscreen) content += '
' + event.episodeOnscreen + '
'; @@ -482,6 +484,7 @@ tvheadend.epg = function() { { name: 'category' }, { name: 'keyword' }, { name: 'ageRating' }, + { name: 'copyrightYear' }, { name: 'genre' }, { name: 'dvrUuid' }, { name: 'dvrState' },