Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
added an external interface to scrape information from epg broadcasts
  • Loading branch information
john-tornblom committed Jan 28, 2014
1 parent 635ce0a commit 8f81b22
Show file tree
Hide file tree
Showing 9 changed files with 495 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Makefile
Expand Up @@ -82,6 +82,7 @@ SRCS = src/version.c \
src/epg.c \
src/epgdb.c\
src/epggrab.c\
src/epgscrape.c\
src/spawn.c \
src/packet.c \
src/streaming.c \
Expand Down Expand Up @@ -124,6 +125,7 @@ SRCS += \
src/api/api_mpegts.c \
src/api/api_epg.c \
src/api/api_epggrab.c \
src/api/api_epgscrape.c \
src/api/api_imagecache.c

SRCS += \
Expand Down
1 change: 1 addition & 0 deletions src/api.c
Expand Up @@ -122,6 +122,7 @@ void api_init ( void )
api_channel_init();
api_epg_init();
api_epggrab_init();
api_epgscrape_init();
api_status_init();
api_imagecache_init();
}
1 change: 1 addition & 0 deletions src/api.h
Expand Up @@ -63,6 +63,7 @@ void api_channel_init ( void );
void api_mpegts_init ( void );
void api_epg_init ( void );
void api_epggrab_init ( void );
void api_epgscrape_init ( void );
void api_status_init ( void );
void api_imagecache_init ( void );

Expand Down
64 changes: 64 additions & 0 deletions src/api/api_epgscrape.c
@@ -0,0 +1,64 @@
/*
* API - EPG scraping related calls
*
* Copyright (C) 2013 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; withm 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 "tvheadend.h"
#include "channels.h"
#include "access.h"
#include "api.h"
#include "epgscrape.h"


static int
api_epgscrape_load
( void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
{
htsmsg_t *l;
pthread_mutex_lock(&global_lock);
*resp = htsmsg_create_map();
l = htsmsg_create_list();
htsmsg_add_msg(l, NULL, epgscrape_get_config());
htsmsg_add_msg(*resp, "entries", l);
pthread_mutex_unlock(&global_lock);
return 0;
}

static int
api_epgscrape_save
( void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
{
pthread_mutex_lock(&global_lock);
if (epgscrape_set_config(args))
epgscrape_save();
pthread_mutex_unlock(&global_lock);
*resp = htsmsg_create_map();
htsmsg_add_u32(*resp, "success", 1);
return 0;
}

void
api_epgscrape_init ( void )
{
static api_hook_t ah[] = {
{ "epgscrape/config/load", ACCESS_ADMIN, api_epgscrape_load, NULL },
{ "epgscrape/config/save", ACCESS_ADMIN, api_epgscrape_save, NULL },
{ NULL },
};

api_register_all(ah);
}
9 changes: 9 additions & 0 deletions src/epg.c
Expand Up @@ -32,6 +32,7 @@
#include "dvr/dvr.h"
#include "htsp_server.h"
#include "epggrab.h"
#include "epgscrape.h"
#include "imagecache.h"

/* Broadcast hashing */
Expand Down Expand Up @@ -94,6 +95,7 @@ static int _episode_order ( const void *_a, const void *_b )
return a->epnum.p_num - b->epnum.p_num;
}


void epg_updated ( void )
{
epg_object_t *eo;
Expand All @@ -111,6 +113,10 @@ void epg_updated ( void )

/* Update updated */
while ((eo = LIST_FIRST(&epg_object_updated))) {
// scrape for more detailed information
if(eo->type == EPG_BROADCAST)
epgscrape_enqueue_broadcast((epg_broadcast_t *)eo);

eo->update(eo);
LIST_REMOVE(eo, up_link);
eo->_updated = 0;
Expand Down Expand Up @@ -1771,6 +1777,7 @@ htsmsg_t *epg_broadcast_serialize ( epg_broadcast_t *broadcast )
if (!(m = _epg_object_serialize((epg_object_t*)broadcast))) return NULL;
htsmsg_add_s64(m, "start", broadcast->start);
htsmsg_add_s64(m, "stop", broadcast->stop);
htsmsg_add_s64(m, "scraped", broadcast->scraped);
htsmsg_add_str(m, "episode", broadcast->episode->uri);
if (broadcast->channel)
htsmsg_add_str(m, "channel", channel_get_uuid(broadcast->channel));
Expand Down Expand Up @@ -1843,6 +1850,8 @@ epg_broadcast_t *epg_broadcast_deserialize
ebc = _epg_channel_add_broadcast(ch, skel, create, save);
if (!ebc) return NULL;

ebc->scraped = htsmsg_get_s64_or_default(m, "scraped", 0);

/* Get metadata */
if (!htsmsg_get_u32(m, "is_widescreen", &u32))
*save |= epg_broadcast_set_is_widescreen(ebc, u32, NULL);
Expand Down
3 changes: 3 additions & 0 deletions src/epg.h
Expand Up @@ -432,6 +432,9 @@ struct epg_broadcast
uint8_t is_new; ///< New series / file premiere
uint8_t is_repeat; ///< Repeat screening

uint32_t _scraping; ///< Currently being scraped
time_t scraped; ///< Last time scraped

/* Broadcast level text */
lang_str_t *summary; ///< Summary
lang_str_t *description; ///< Description
Expand Down

0 comments on commit 8f81b22

Please sign in to comment.