diff --git a/src/epg.c b/src/epg.c index 39625783..f4322090 100644 --- a/src/epg.c +++ b/src/epg.c @@ -53,7 +53,7 @@ epg_object_list_t epg_object_updated; static uint64_t _epg_object_idx = 0; /* ************************************************************************** - * Comparators + * Comparators / Ordering * *************************************************************************/ static int _uri_cmp ( const void *a, const void *b ) @@ -66,6 +66,27 @@ static int _ebc_start_cmp ( const void *a, const void *b ) return ((epg_broadcast_t*)a)->start - ((epg_broadcast_t*)b)->start; } +static int _season_order ( const void *_a, const void *_b ) +{ + const epg_season_t *a = (const epg_season_t*)_a; + const epg_season_t *b = (const epg_season_t*)_b; + if ( !a || !a->number ) return 1; + if ( !b || !b->number ) return -1; + return a->number - b->number; +} + +static int _episode_order ( const void *_a, const void *_b ) +{ + int r; + const epg_episode_t *a = (const epg_episode_t*)_a; + const epg_episode_t *b = (const epg_episode_t*)_b; + r = _season_order(a->season, b->season); + if (r) return r; + if (!a || !a->number) return 1; + if (!b || !b->number) return -1; + return a->number - b->number; +} + /* ************************************************************************** * Setup / Update * *************************************************************************/ @@ -467,7 +488,7 @@ int epg_brand_set_season_count ( epg_brand_t *brand, uint16_t count ) static void _epg_brand_add_season ( epg_brand_t *brand, epg_season_t *season ) { - LIST_INSERT_HEAD(&brand->seasons, season, blink); + LIST_INSERT_SORTED(&brand->seasons, season, blink, _season_order); _epg_object_set_updated((epg_object_t*)brand); } @@ -481,7 +502,7 @@ static void _epg_brand_rem_season static void _epg_brand_add_episode ( epg_brand_t *brand, epg_episode_t *episode ) { - LIST_INSERT_HEAD(&brand->episodes, episode, blink); + LIST_INSERT_SORTED(&brand->episodes, episode, blink, _episode_order); _epg_object_set_updated((epg_object_t*)brand); } @@ -649,7 +670,7 @@ int epg_season_set_brand ( epg_season_t *season, epg_brand_t *brand, int u ) static void _epg_season_add_episode ( epg_season_t *season, epg_episode_t *episode ) { - LIST_INSERT_HEAD(&season->episodes, episode, slink); + LIST_INSERT_SORTED(&season->episodes, episode, slink, _episode_order); _epg_object_set_updated((epg_object_t*)season); } @@ -993,12 +1014,12 @@ epg_episode_t *epg_episode_deserialize ( htsmsg_t *m, int create, int *save ) !htsmsg_get_u32(m, "part-count", &u32a) ) *save |= epg_episode_set_part(ee, u32, u32a); - if ( (str = htsmsg_get_str(m, "brand")) ) - if ( (eb = epg_brand_find_by_uri(str, 0, NULL)) ) - *save |= epg_episode_set_brand(ee, eb); if ( (str = htsmsg_get_str(m, "season")) ) if ( (es = epg_season_find_by_uri(str, 0, NULL)) ) *save |= epg_episode_set_season(ee, es); + if ( (str = htsmsg_get_str(m, "brand")) ) + if ( (eb = epg_brand_find_by_uri(str, 0, NULL)) ) + *save |= epg_episode_set_brand(ee, eb); return ee; } @@ -1548,6 +1569,7 @@ void epg_query0 _eqr_add_channel(eqr, channel, genre, preg, now); } } + if (preg) regfree(preg); return; } diff --git a/src/epggrab.c b/src/epggrab.c index 8e91b121..3aad8eed 100644 --- a/src/epggrab.c +++ b/src/epggrab.c @@ -184,7 +184,7 @@ static void *_epggrab_socket_thread ( void *p ) while ( mod->enabled && mod->sock ) { tvhlog(LOG_DEBUG, mod->id, "waiting for connection"); s = accept(mod->sock, NULL, NULL); - if (s <= 0) break; // assume closed + if (s <= 0) continue; tvhlog(LOG_DEBUG, mod->id, "got connection %d", s); _epggrab_socket_handler(mod, s); } @@ -428,6 +428,7 @@ void epggrab_module_channels_load ( epggrab_module_t *mod ) if ((e = htsmsg_get_map_by_field(f))) epggrab_module_channel_load(mod, e, f->hmf_name); } + htsmsg_destroy(m); } } diff --git a/src/epggrab/pyepg.c b/src/epggrab/pyepg.c index 5921a751..40e70989 100644 --- a/src/epggrab/pyepg.c +++ b/src/epggrab/pyepg.c @@ -244,13 +244,6 @@ static int _pyepg_parse_episode ( htsmsg_t *data, epggrab_stats_t *stats ) stats->episodes.total++; if (save) stats->episodes.created++; - /* Set brand */ - if ((str = htsmsg_get_str(attr, "brand"))) { - if ((brand = epg_brand_find_by_uri(str, 0, NULL))) { - save |= epg_episode_set_brand(episode, brand); - } - } - /* Set season */ if ((str = htsmsg_get_str(attr, "series"))) { if ((season = epg_season_find_by_uri(str, 0, NULL))) { @@ -258,6 +251,13 @@ static int _pyepg_parse_episode ( htsmsg_t *data, epggrab_stats_t *stats ) } } + /* Set brand */ + if ((str = htsmsg_get_str(attr, "brand"))) { + if ((brand = epg_brand_find_by_uri(str, 0, NULL))) { + save |= epg_episode_set_brand(episode, brand); + } + } + /* Set title/subtitle */ if ((str = htsmsg_xml_get_cdata_str(tags, "title"))) { save |= epg_episode_set_title(episode, str);