--- /dev/null
+/*
+ * Electronic Program Guide - Regular Expression Pattern Functions
+ * Copyright (C) 2012-2017 Adam Sutton
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <ctype.h>
+#include "tvheadend.h"
+#include "eitpatternlist.h"
+#include "htsmsg.h"
+
+void eit_pattern_compile_list ( eit_pattern_list_t *list, htsmsg_t *l )
+{
+ eit_pattern_t *pattern;
+ htsmsg_field_t *f;
+ const char *s;
+
+ TAILQ_INIT(list);
+ if (!l) return;
+ HTSMSG_FOREACH(f, l) {
+ s = htsmsg_field_get_str(f);
+ if (s == NULL) continue;
+ pattern = calloc(1, sizeof(eit_pattern_t));
+ pattern->text = strdup(s);
+ if (regcomp(&pattern->compiled, pattern->text, REG_EXTENDED)) {
+ tvhwarn(LS_EPGGRAB, "error compiling pattern \"%s\"", pattern->text);
+ free(pattern->text);
+ free(pattern);
+ } else {
+ tvhtrace(LS_EPGGRAB, "compiled pattern \"%s\"", pattern->text);
+ TAILQ_INSERT_TAIL(list, pattern, p_links);
+ }
+ }
+}
+
+void *eit_pattern_apply_list(char *buf, size_t size_buf, const char *text, eit_pattern_list_t *l)
+{
+ regmatch_t match[2];
+ eit_pattern_t *p;
+ int size;
+
+ if (!l) return NULL;
+ /* search and report the first match */
+ TAILQ_FOREACH(p, l, p_links)
+ if (!regexec(&p->compiled, text, 2, match, 0) && match[1].rm_so != -1) {
+ size = MIN(match[1].rm_eo - match[1].rm_so, size_buf - 1);
+ while (size > 0 && isspace(text[match[1].rm_so + size - 1]))
+ size--;
+ memcpy(buf, text + match[1].rm_so, size);
+ buf[size] = '\0';
+ if (size) {
+ tvhtrace(LS_EPGGRAB," pattern \"%s\" matches with '%s'", p->text, buf);
+ return buf;
+ }
+ }
+ return NULL;
+}
+
+void eit_pattern_free_list ( eit_pattern_list_t *l )
+{
+ eit_pattern_t *p;
+
+ if (!l) return;
+ while ((p = TAILQ_FIRST(l)) != NULL) {
+ TAILQ_REMOVE(l, p, p_links);
+ free(p->text);
+ regfree(&p->compiled);
+ free(p);
+ }
+}
--- /dev/null
+/*
+ * Electronic Program Guide - Regular Expression Pattern Functions
+ * Copyright (C) 2012-2017 Adam Sutton
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __EITPATTERN_LIST__
+#define __EITPATTERN_LIST__
+
+#include <regex.h>
+#include "queue.h"
+
+typedef struct eit_pattern
+{
+ char *text;
+ regex_t compiled;
+ TAILQ_ENTRY(eit_pattern) p_links;
+} eit_pattern_t;
+TAILQ_HEAD(eit_pattern_list, eit_pattern);
+typedef struct eit_pattern_list eit_pattern_list_t;
+
+/* Compile a regular expression pattern from a message */
+void eit_pattern_compile_list ( eit_pattern_list_t *list, htsmsg_t *l );
+/* Apply the compiled pattern to text. If it matches then return the
+ * match in buf which is of size size_buf.
+ * Return the buf or NULL if no match.
+ */
+void *eit_pattern_apply_list(char *buf, size_t size_buf, const char *text, eit_pattern_list_t *l);
+void eit_pattern_free_list ( eit_pattern_list_t *l );
+#endif
#include <string.h>
#include <assert.h>
#include <unistd.h>
-#include <regex.h>
#include <ctype.h>
#include "tvheadend.h"
#include "channels.h"
#include "epg.h"
#include "epggrab.h"
#include "epggrab/private.h"
+#include "eitpatternlist.h"
#include "subscriptions.h"
#include "streaming.h"
#include "service.h"
RB_ENTRY(opentv_genre) h_link;
} opentv_genre_t;
-typedef struct opentv_pattern
-{
- char *text;
- regex_t compiled;
- TAILQ_ENTRY(opentv_pattern) p_links;
-} opentv_pattern_t;
-TAILQ_HEAD(opentv_pattern_list, opentv_pattern);
-typedef struct opentv_pattern_list opentv_pattern_list_t;
/* Provider configuration */
typedef struct opentv_module_t
opentv_genre_t *genre;
int titles_time;
int summaries_time;
- opentv_pattern_list_t p_snum;
- opentv_pattern_list_t p_enum;
- opentv_pattern_list_t p_pnum;
- opentv_pattern_list_t p_subt;
- opentv_pattern_list_t p_cleanup_title;
+ eit_pattern_list_t p_snum;
+ eit_pattern_list_t p_enum;
+ eit_pattern_list_t p_pnum;
+ eit_pattern_list_t p_subt;
+ eit_pattern_list_t p_cleanup_title;
} opentv_module_t;
/*
return slen+4;
}
-static void *_opentv_apply_pattern_list(char *buf, size_t size_buf, const char *text, opentv_pattern_list_t *l)
-{
- regmatch_t match[2];
- opentv_pattern_t *p;
- int size;
-
- if (!l) return NULL;
- /* search and report the first match */
- TAILQ_FOREACH(p, l, p_links)
- if (!regexec(&p->compiled, text, 2, match, 0) && match[1].rm_so != -1) {
- size = MIN(match[1].rm_eo - match[1].rm_so, size_buf - 1);
- while (size > 0 && isspace(text[match[1].rm_so + size - 1]))
- size--;
- memcpy(buf, text + match[1].rm_so, size);
- buf[size] = '\0';
- if (size) {
- tvhtrace(LS_OPENTV," pattern \"%s\" matches with '%s'", p->text, buf);
- return buf;
- }
- }
- return NULL;
-}
-
/* Parse an event section */
static int
opentv_parse_event_section_one
tvhdebug(LS_OPENTV, " title '%s'", ev.title);
/* try to cleanup the title */
- if (_opentv_apply_pattern_list(buffer, sizeof(buffer), ev.title, &mod->p_cleanup_title)) {
+ if (eit_pattern_apply_list(buffer, sizeof(buffer), ev.title, &mod->p_cleanup_title)) {
tvhtrace(LS_OPENTV, " clean title '%s'", buffer);
s = buffer;
} else {
memset(&en, 0, sizeof(en));
/* search for season number */
- if (_opentv_apply_pattern_list(buffer, sizeof(buffer), ev.summary, &mod->p_snum))
+ if (eit_pattern_apply_list(buffer, sizeof(buffer), ev.summary, &mod->p_snum))
if ((en.s_num = atoi(buffer)))
tvhtrace(LS_OPENTV," extract season number %d", en.s_num);
/* ...for episode number */
- if (_opentv_apply_pattern_list(buffer, sizeof(buffer), ev.summary, &mod->p_enum))
+ if (eit_pattern_apply_list(buffer, sizeof(buffer), ev.summary, &mod->p_enum))
if ((en.e_num = atoi(buffer)))
tvhtrace(LS_OPENTV," extract episode number %d", en.e_num);
/* ...for part number */
- if (_opentv_apply_pattern_list(buffer, sizeof(buffer), ev.summary, &mod->p_pnum)) {
+ if (eit_pattern_apply_list(buffer, sizeof(buffer), ev.summary, &mod->p_pnum)) {
if (buffer[0] >= 'a' && buffer[0] <= 'z')
en.p_num = buffer[0] - 'a' + 1;
else
save |= epg_episode_set_epnum(ee, &en, &changes3);
/* ...for subtitle */
- if (_opentv_apply_pattern_list(buffer, sizeof(buffer), ev.summary, &mod->p_subt)) {
+ if (eit_pattern_apply_list(buffer, sizeof(buffer), ev.summary, &mod->p_subt)) {
tvhtrace(LS_OPENTV, " extract subtitle '%s'", buffer);
ls = lang_str_create2(buffer, lang);
save |= epg_episode_set_subtitle(ee, ls, &changes3);
return ret;
}
-static void _opentv_compile_pattern_list ( opentv_pattern_list_t *list, htsmsg_t *l )
-{
- opentv_pattern_t *pattern;
- htsmsg_field_t *f;
- const char *s;
-
- TAILQ_INIT(list);
- if (!l) return;
- HTSMSG_FOREACH(f, l) {
- s = htsmsg_field_get_str(f);
- if (s == NULL) continue;
- pattern = calloc(1, sizeof(opentv_pattern_t));
- pattern->text = strdup(s);
- if (regcomp(&pattern->compiled, pattern->text, REG_EXTENDED)) {
- tvhwarn(LS_OPENTV, "error compiling pattern \"%s\"", pattern->text);
- free(pattern->text);
- free(pattern);
- } else {
- tvhtrace(LS_OPENTV, "compiled pattern \"%s\"", pattern->text);
- TAILQ_INSERT_TAIL(list, pattern, p_links);
- }
- }
-}
-
static int _opentv_genre_load_one ( const char *id, htsmsg_t *m )
{
htsmsg_field_t *f;
htsmsg_destroy(m);
}
-static void _opentv_free_pattern_list ( opentv_pattern_list_t *l )
-{
- opentv_pattern_t *p;
-
- if (!l) return;
- while ((p = TAILQ_FIRST(l)) != NULL) {
- TAILQ_REMOVE(l, p, p_links);
- free(p->text);
- regfree(&p->compiled);
- free(p);
- }
-}
static void _opentv_done( void *m )
{
free(mod->title);
free(mod->summary);
- _opentv_free_pattern_list(&mod->p_snum);
- _opentv_free_pattern_list(&mod->p_enum);
- _opentv_free_pattern_list(&mod->p_pnum);
- _opentv_free_pattern_list(&mod->p_subt);
- _opentv_free_pattern_list(&mod->p_cleanup_title);
+ eit_pattern_free_list(&mod->p_snum);
+ eit_pattern_free_list(&mod->p_enum);
+ eit_pattern_free_list(&mod->p_pnum);
+ eit_pattern_free_list(&mod->p_subt);
+ eit_pattern_free_list(&mod->p_cleanup_title);
}
static int _opentv_tune
mod->channel = _pid_list_to_array(cl);
mod->title = _pid_list_to_array(tl);
mod->summary = _pid_list_to_array(sl);
- _opentv_compile_pattern_list(&mod->p_snum, htsmsg_get_list(m, "season_num"));
- _opentv_compile_pattern_list(&mod->p_enum, htsmsg_get_list(m, "episode_num"));
- _opentv_compile_pattern_list(&mod->p_pnum, htsmsg_get_list(m, "part_num"));
- _opentv_compile_pattern_list(&mod->p_subt, htsmsg_get_list(m, "subtitle"));
- _opentv_compile_pattern_list(&mod->p_cleanup_title, htsmsg_get_list(m, "cleanup_title"));
+ eit_pattern_compile_list(&mod->p_snum, htsmsg_get_list(m, "season_num"));
+ eit_pattern_compile_list(&mod->p_enum, htsmsg_get_list(m, "episode_num"));
+ eit_pattern_compile_list(&mod->p_pnum, htsmsg_get_list(m, "part_num"));
+ eit_pattern_compile_list(&mod->p_subt, htsmsg_get_list(m, "subtitle"));
+ eit_pattern_compile_list(&mod->p_cleanup_title, htsmsg_get_list(m, "cleanup_title"));
return 1;
}