extract and store episode thumbnail

This commit is contained in:
hummypkg 2015-11-02 23:05:32 +00:00
parent 4c14046991
commit 9fd6117cd5
1 changed files with 14 additions and 2 deletions

16
tvdb.c
View File

@ -28,6 +28,7 @@ struct episode {
unsigned long id; unsigned long id;
char *name; char *name;
char *overview; char *overview;
char *thumb;
unsigned long series; unsigned long series;
unsigned long episode; unsigned long episode;
}; };
@ -204,19 +205,21 @@ main(int argc, char **argv)
sprintf(buf, "attach '%s/%lu.db' as episode", CACHE, s.id); sprintf(buf, "attach '%s/%lu.db' as episode", CACHE, s.id);
EXEC(buf); EXEC(buf);
EXEC("drop table if exists episode.episode");
EXEC( EXEC(
"create table if not exists episode.episode(" "create table if not exists episode.episode("
"[episode_id] integer primary key, " "[episode_id] integer primary key, "
"[series] integer, " "[series] integer, "
"[episode] integer, " "[episode] integer, "
"[name] text, " "[name] text, "
"[overview] text" "[overview] text, "
"[thumb] text"
")" ")"
); );
if (sqlite3_prepare_v2(db, if (sqlite3_prepare_v2(db,
"insert or replace into episode.episode " "insert or replace into episode.episode "
"values(?,?,?,?,?)", "values(?,?,?,?,?,?)",
-1, &stmt, NULL) != SQLITE_OK) -1, &stmt, NULL) != SQLITE_OK)
{ {
fprintf(stderr, fprintf(stderr,
@ -255,6 +258,13 @@ main(int argc, char **argv)
*q = '\0'; *q = '\0';
unescape(e.overview); unescape(e.overview);
} }
if (!strncmp(p, "filename>", 9))
{
e.thumb = strdup(p + 9);
if ((q = strstr(e.thumb, "</filename>")))
*q = '\0';
unescape(e.thumb);
}
if (!strncmp(p, "/Episode>", 8)) if (!strncmp(p, "/Episode>", 8))
{ {
@ -268,12 +278,14 @@ main(int argc, char **argv)
sqlite3_bind_text(stmt, 4, e.name, -1, NULL); sqlite3_bind_text(stmt, 4, e.name, -1, NULL);
sqlite3_bind_text(stmt, 5, e.overview, sqlite3_bind_text(stmt, 5, e.overview,
-1, NULL); -1, NULL);
sqlite3_bind_text(stmt, 6, e.thumb, -1, NULL);
sqlite3_step(stmt); sqlite3_step(stmt);
sqlite3_reset(stmt); sqlite3_reset(stmt);
sqlite3_clear_bindings(stmt); sqlite3_clear_bindings(stmt);
} }
if (e.name) free(e.name); if (e.name) free(e.name);
if (e.overview) free(e.overview); if (e.overview) free(e.overview);
if (e.thumb) free(e.thumb);
memset(&e, '\0', sizeof(e)); memset(&e, '\0', sizeof(e));
} }
} }