Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #478 from diraimondo/master
scraping season/episode numbers for sky-it
  • Loading branch information
perexg committed Sep 13, 2014
2 parents ea9d782 + 42de59d commit e6ee82c
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions src/epggrab/module/opentv.c
Expand Up @@ -162,6 +162,14 @@ static epggrab_channel_t *_opentv_find_epggrab_channel
* OpenTV event processing
* ***********************************************************************/

/* Patterns for the extraction of season/episode numbers from summary of events*/
static const char *_opentv_se_num_patterns[] = {
" *\\(S ?([0-9]+),? Ep? ?([0-9]+)\\)", /* for ??? */
" *([0-9]+)'? Stagione +Ep\\. ?([0-9]+) ?-", /* for Sky IT */
" *([0-9]+)'? Stagione() ?-", /* for Sky IT */
"() *Ep\\. ?([0-9]+) ?-" }; /* for Sky IT */
static regex_t *_opentv_se_num_pregs;

/* Parse huffman encoded string */
static char *_opentv_parse_string
( opentv_module_t *prov, const uint8_t *buf, int len )
Expand Down Expand Up @@ -341,23 +349,24 @@ opentv_parse_event_section
epg_genre_list_destroy(egl);
}
if (ev.summary) {
regex_t preg;
regmatch_t match[3];
int i;

/* Parse Series/Episode
* TODO: HACK: this needs doing properly */
regcomp(&preg, " *\\(S ?([0-9]+),? Ep? ?([0-9]+)\\)",
REG_ICASE | REG_EXTENDED);
if (!regexec(&preg, ev.summary, 3, match, 0)) {
epg_episode_num_t en;
memset(&en, 0, sizeof(en));
if (match[1].rm_so != -1)
en.s_num = atoi(ev.summary + match[1].rm_so);
if (match[2].rm_so != -1)
en.e_num = atoi(ev.summary + match[2].rm_so);
save |= epg_episode_set_epnum(ee, &en, src);
for (i = 0; i < ARRAY_SIZE(_opentv_se_num_patterns); i++) {
if (!regexec(_opentv_se_num_pregs+i, ev.summary, 3, match, 0)) {
epg_episode_num_t en;
memset(&en, 0, sizeof(en));
if (match[1].rm_so != -1)
en.s_num = atoi(ev.summary + match[1].rm_so);
if (match[2].rm_so != -1)
en.e_num = atoi(ev.summary + match[2].rm_so);
tvhdebug("opentv", " extract from summary season %d episode %d", en.s_num, en.e_num);
save |= epg_episode_set_epnum(ee, &en, src);
break; /* skip other patterns */
}
}
regfree(&preg);
}
}

Expand Down Expand Up @@ -800,6 +809,7 @@ static void _opentv_prov_load ( htsmsg_t *m )
void opentv_init ( void )
{
htsmsg_t *m;
int i;

/* Load dictionaries */
if ((m = hts_settings_load("epggrab/opentv/dict")))
Expand All @@ -815,12 +825,18 @@ void opentv_init ( void )
if ((m = hts_settings_load("epggrab/opentv/prov")))
_opentv_prov_load(m);
tvhlog(LOG_DEBUG, "opentv", "providers loaded");

/* Compile some recurring regular-expressions */
_opentv_se_num_pregs = calloc(ARRAY_SIZE(_opentv_se_num_patterns), sizeof(regex_t));
for (i = 0; i < ARRAY_SIZE(_opentv_se_num_patterns); i++)
regcomp(_opentv_se_num_pregs+i, _opentv_se_num_patterns[i], REG_ICASE | REG_EXTENDED);
}

void opentv_done ( void )
{
opentv_dict_t *dict;
opentv_genre_t *genre;
int i;

while ((dict = RB_FIRST(&_opentv_dicts)) != NULL) {
RB_REMOVE(&_opentv_dicts, dict, h_link);
Expand All @@ -833,6 +849,10 @@ void opentv_done ( void )
free(genre->id);
free(genre);
}

for (i = 0; i < ARRAY_SIZE(_opentv_se_num_patterns); i++)
regfree(_opentv_se_num_pregs+i);
free(_opentv_se_num_pregs);
}

void opentv_load ( void )
Expand Down

0 comments on commit e6ee82c

Please sign in to comment.