static int _pyepg_parse_broadcast ( epggrab_module_t *mod, htsmsg_t *data, channel_t *channel, epggrab_stats_t *stats ) { int save = 0; 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; if ((attr = htsmsg_get_map(data, "attrib")) == NULL) return 0; 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; /* Parse times */ if (!_pyepg_parse_time(start, &tm_start)) return 0; if (!_pyepg_parse_time(stop, &tm_stop)) return 0; /* Find broadcast */ broadcast = epg_broadcast_find_by_time(channel, tm_start, tm_stop, 0, 1, &save); if ( broadcast == NULL ) return 0; stats->broadcasts.total++; if ( save ) stats->broadcasts.created++; /* Quality */ u32 = htsmsg_get_map(tags, "hd") ? 1 : 0; save |= epg_broadcast_set_is_hd(broadcast, u32, mod); u32 = htsmsg_get_map(tags, "widescreen") ? 1 : 0; save |= epg_broadcast_set_is_widescreen(broadcast, u32, mod); // TODO: lines, aspect /* Accessibility */ // Note: reuse XMLTV parse code as this is the same xmltv_parse_accessibility(mod, broadcast, tags); /* New/Repeat */ u32 = htsmsg_get_map(tags, "new") || htsmsg_get_map(tags, "premiere"); save |= epg_broadcast_set_is_new(broadcast, u32, mod); u32 = htsmsg_get_map(tags, "repeat") ? 1 : 0; save |= epg_broadcast_set_is_repeat(broadcast, u32, mod); /* Set episode */ if ((episode = epg_episode_find_by_uri(id, 1, &save)) == NULL) return 0; save |= epg_broadcast_set_episode(broadcast, episode, mod); if (save) stats->broadcasts.modified++; return save; }
/** * Parse tags inside of a programme */ static int _xmltv_parse_programme_tags (epggrab_module_t *mod, channel_t *ch, htsmsg_t *tags, time_t start, time_t stop, epggrab_stats_t *stats) { int save = 0, save2 = 0, save3 = 0; epg_episode_t *ee = NULL; epg_serieslink_t *es = NULL; epg_broadcast_t *ebc; epg_genre_list_t *egl; epg_episode_num_t epnum; memset(&epnum, 0, sizeof(epnum)); char *suri = NULL, *uri = NULL; lang_str_t *title = NULL; lang_str_t *desc = NULL; lang_str_t *subtitle = NULL; time_t first_aired = 0; int8_t bw = -1; /* * Broadcast */ if (!(ebc = epg_broadcast_find_by_time(ch, start, stop, 0, 1, &save))) return 0; stats->broadcasts.total++; if (save) stats->broadcasts.created++; /* Description (wait for episode first) */ _xmltv_parse_lang_str(&desc, tags, "desc"); if (desc) save3 |= epg_broadcast_set_description2(ebc, desc, mod); /* Quality metadata */ save |= xmltv_parse_vid_quality(mod, ebc, htsmsg_get_map(tags, "video"), &bw); /* Accessibility */ save |= xmltv_parse_accessibility(mod, ebc, tags); /* Misc */ save |= _xmltv_parse_previously_shown(mod, ebc, tags, &first_aired); if (htsmsg_get_map(tags, "premiere") || htsmsg_get_map(tags, "new")) save |= epg_broadcast_set_is_new(ebc, 1, mod); /* * Episode/Series info */ get_episode_info(mod, tags, &uri, &suri, &epnum); /* * Series Link */ if (suri) { es = epg_serieslink_find_by_uri(suri, 1, &save2); free(suri); if (es) stats->seasons.total++; if (save2) stats->seasons.created++; if (es) save |= epg_broadcast_set_serieslink(ebc, es, mod); } /* * Episode */ if (uri) { if ((ee = epg_episode_find_by_uri(uri, 1, &save3))) save |= epg_broadcast_set_episode(ebc, ee, mod); free(uri); } else { ee = epg_broadcast_get_episode(ebc, 1, &save3); } if (ee) stats->episodes.total++; if (save3) stats->episodes.created++; if (ee) { _xmltv_parse_lang_str(&title, tags, "title"); _xmltv_parse_lang_str(&subtitle, tags, "sub-title"); if (title) save3 |= epg_episode_set_title2(ee, title, mod); if (subtitle) save3 |= epg_episode_set_subtitle2(ee, subtitle, mod); if ((egl = _xmltv_parse_categories(tags))) { save3 |= epg_episode_set_genre(ee, egl, mod); epg_genre_list_destroy(egl); } if (bw != -1) save3 |= epg_episode_set_is_bw(ee, (uint8_t)bw, mod); save3 |= epg_episode_set_epnum(ee, &epnum, mod); save3 |= _xmltv_parse_star_rating(mod, ee, tags); // TODO: parental rating } /* Stats */ if (save) stats->broadcasts.modified++; if (save2) stats->seasons.modified++; if (save3) stats->episodes.modified++; /* Cleanup */ if (title) lang_str_destroy(title); if (subtitle) lang_str_destroy(subtitle); if (desc) lang_str_destroy(desc); return save | save2 | save3; }