From: Jaroslav Kysela Date: Thu, 12 Nov 2015 13:29:57 +0000 (+0100) Subject: IPTV: Add extra channels tags to IPTV mux config, m3u attribute tvh-tags X-Git-Tag: v4.2.1~1566 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=abad26ea05dcce8d8ddda9474414767de96644c1;p=thirdparty%2Ftvheadend.git IPTV: Add extra channels tags to IPTV mux config, m3u attribute tvh-tags --- diff --git a/src/input/mpegts/iptv/iptv_auto.c b/src/input/mpegts/iptv/iptv_auto.c index 4f4370ef5..7f1b5a9a5 100644 --- a/src/input/mpegts/iptv/iptv_auto.c +++ b/src/input/mpegts/iptv/iptv_auto.c @@ -54,7 +54,7 @@ iptv_auto_network_process_m3u_item(iptv_network_t *in, int delim; size_t l; int64_t chnum2; - const char *url, *name, *logo, *epgid; + const char *url, *name, *logo, *epgid, *tags; char url2[512], custom[512], name2[128], buf[32], *n, *y; url = htsmsg_get_str(item, "m3u-url"); @@ -90,6 +90,15 @@ iptv_auto_network_process_m3u_item(iptv_network_t *in, logo = htsmsg_get_str(item, "logo"); epgid = htsmsg_get_str(item, "tvg-id"); + tags = htsmsg_get_str(item, "tvh-tags"); + if (tags) { + tags = n = strdupa(tags); + while (*n) { + if (*n == '|') + *n = '\n'; + n++; + } + } urlinit(&u); custom[0] = '\0'; @@ -199,6 +208,11 @@ skip_url: im->mm_iptv_hdr = strdup(custom); change = 1; } + if (strcmp(im->mm_iptv_tags ?: "", tags ?: "")) { + free(im->mm_iptv_tags); + im->mm_iptv_tags = strdup(tags); + change = 1; + } if (change) idnode_notify_changed(&im->mm_id); (*total)++; @@ -222,6 +236,8 @@ skip_url: htsmsg_add_str(conf, "iptv_icon", logo); if (epgid) htsmsg_add_str(conf, "iptv_epgid", epgid); + if (tags) + htsmsg_add_str(conf, "iptv_tags", tags); if (!in->in_scan_create) htsmsg_add_s32(conf, "scan_result", MM_SCAN_OK); if (custom[0]) diff --git a/src/input/mpegts/iptv/iptv_mux.c b/src/input/mpegts/iptv/iptv_mux.c index 49bb00cc4..432a5f7b1 100644 --- a/src/input/mpegts/iptv/iptv_mux.c +++ b/src/input/mpegts/iptv/iptv_mux.c @@ -224,6 +224,13 @@ const idclass_t iptv_mux_class = .off = offsetof(iptv_mux_t, mm_iptv_hdr), .opts = PO_ADVANCED | PO_MULTILINE }, + { + .type = PT_STR, + .id = "iptv_tags", + .name = N_("Channel tags"), + .off = offsetof(iptv_mux_t, mm_iptv_tags), + .opts = PO_ADVANCED | PO_MULTILINE + }, {} } }; @@ -260,6 +267,7 @@ iptv_mux_delete ( mpegts_mux_t *mm, int delconf ) free(im->mm_iptv_svcname); free(im->mm_iptv_env); free(im->mm_iptv_hdr); + free(im->mm_iptv_tags); free(im->mm_iptv_icon); free(im->mm_iptv_epgid); mpegts_mux_delete(mm, delconf); diff --git a/src/input/mpegts/iptv/iptv_private.h b/src/input/mpegts/iptv/iptv_private.h index 77253473d..0343e04a8 100644 --- a/src/input/mpegts/iptv/iptv_private.h +++ b/src/input/mpegts/iptv/iptv_private.h @@ -131,6 +131,7 @@ struct iptv_mux int mm_iptv_kill_timeout; char *mm_iptv_env; char *mm_iptv_hdr; + char *mm_iptv_tags; uint32_t mm_iptv_rtp_seq; diff --git a/src/input/mpegts/iptv/iptv_service.c b/src/input/mpegts/iptv/iptv_service.c index 2d2b3762a..a09db9dab 100644 --- a/src/input/mpegts/iptv/iptv_service.c +++ b/src/input/mpegts/iptv/iptv_service.c @@ -108,6 +108,27 @@ iptv_service_channel_epgid ( service_t *s ) return im->mm_iptv_epgid; } +static htsmsg_t * +iptv_service_channel_tags ( service_t *s ) +{ + iptv_service_t *is = (iptv_service_t *)s; + iptv_mux_t *im = (iptv_mux_t *)is->s_dvb_mux; + char *p = im->mm_iptv_tags, *x; + htsmsg_t *r = NULL; + if (p) { + r = htsmsg_create_list(); + while (*p) { + while (*p && *p <= ' ') p++; + x = p; + while (*p && *p >= ' ') p++; + if (*p) { *p = '\0'; p++; } + if (*x) + htsmsg_add_str(r, NULL, x); + } + } + return r; +} + /* * Create */ @@ -128,6 +149,7 @@ iptv_service_create0 is->s_channel_number = iptv_service_channel_number; is->s_channel_icon = iptv_service_channel_icon; is->s_channel_epgid = iptv_service_channel_epgid; + is->s_channel_tags = iptv_service_channel_tags; /* Set default service name */ if (!is->s_dvb_svcname || !*is->s_dvb_svcname) diff --git a/src/service.h b/src/service.h index 738af0a55..c4612a93b 100644 --- a/src/service.h +++ b/src/service.h @@ -320,6 +320,7 @@ typedef struct service { int64_t (*s_channel_number) (struct service *); const char *(*s_channel_name) (struct service *); const char *(*s_channel_epgid) (struct service *); + htsmsg_t *(*s_channel_tags) (struct service *); const char *(*s_provider_name) (struct service *); const char *(*s_channel_icon) (struct service *); void (*s_mapped) (struct service *); diff --git a/src/service_mapper.c b/src/service_mapper.c index acfb6ab1c..23a98ba30 100644 --- a/src/service_mapper.c +++ b/src/service_mapper.c @@ -209,7 +209,9 @@ channel_t * service_mapper_process ( service_t *s, bouquet_t *bq ) { channel_t *chn = NULL; - const char *name; + const char *name, *tagname; + htsmsg_field_t *f; + htsmsg_t *m; /* Ignore */ if (s->s_status == SERVICE_ZOMBIE) { @@ -249,6 +251,12 @@ service_mapper_process ( service_t *s, bouquet_t *bq ) channel_tag_map(channel_tag_find_by_name("Radio", 1), chn, chn); } + /* Custom tags */ + if (s->s_channel_tags && (m = s->s_channel_tags(s)) != NULL) + HTSMSG_FOREACH(f, m) + if ((tagname = htsmsg_field_get_str(f)) != NULL) + channel_tag_map(channel_tag_find_by_name(tagname, 1), chn, chn); + /* Provider */ if (service_mapper_conf.provider_tags) if ((prov = s->s_provider_name(s)))