From e364bce7d1e9b60d647d5fe8ee98e1c9c37317ef Mon Sep 17 00:00:00 2001 From: louis Date: Sun, 25 Aug 2013 12:21:59 +0200 Subject: Implemented cache so that an already looked up series or movie will not be looked up again --- HISTORY | 4 ++++ themoviedbscraper/themoviedbscraper.c | 12 +++++++++--- themoviedbscraper/themoviedbscraper.h | 1 + thetvdbscraper/thetvdbscraper.c | 26 +++++++++++++++++++++----- thetvdbscraper/thetvdbscraper.h | 1 + 5 files changed, 36 insertions(+), 8 deletions(-) diff --git a/HISTORY b/HISTORY index 0481e4d..9329650 100644 --- a/HISTORY +++ b/HISTORY @@ -14,3 +14,7 @@ VDR Plugin 'tvscraper' Revision History - adapted detection of series/movies: duration of series has to be between 10 and 75 minutes, movies have to be longer than 75 minutes + +Version 0.0.3 +- Implemented cache so that an already looked up + series or movie will not be looked up again diff --git a/themoviedbscraper/themoviedbscraper.c b/themoviedbscraper/themoviedbscraper.c index 8e33779..8dd05df 100644 --- a/themoviedbscraper/themoviedbscraper.c +++ b/themoviedbscraper/themoviedbscraper.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include "themoviedbscraper.h" @@ -94,10 +95,14 @@ bool cMovieDBScraper::parseJSON(string jsonString) { } int cMovieDBScraper::SearchMovie(string movieName) { - stringstream movieEscaped; - movieEscaped << "\"" << movieName << "\""; + map::iterator cacheHit = cache.find(movieName); + if (cacheHit != cache.end()) { + if (config.enableDebug) + esyslog("tvscraper: found cache %s => %d", ((string)cacheHit->first).c_str(), (int)cacheHit->second); + return (int)cacheHit->second; + } stringstream url; - url << baseURL << "/search/movie?api_key=" << apiKey << "&query=" << CurlEscape(movieEscaped.str().c_str()) << "&language=" << language.c_str(); + url << baseURL << "/search/movie?api_key=" << apiKey << "&query=" << CurlEscape(movieName.c_str()) << "&language=" << language.c_str(); if (config.enableDebug) esyslog("tvscraper: calling %s", url.str().c_str()); string movieJSON; @@ -107,6 +112,7 @@ int cMovieDBScraper::SearchMovie(string movieName) { movieID = movie->ParseJSONForMovieId(movieName); delete movie; } + cache.insert(pair(movieName, movieID)); return movieID; } diff --git a/themoviedbscraper/themoviedbscraper.h b/themoviedbscraper/themoviedbscraper.h index 54d463b..3560fb5 100644 --- a/themoviedbscraper/themoviedbscraper.h +++ b/themoviedbscraper/themoviedbscraper.h @@ -16,6 +16,7 @@ private: string backdropSize; string actorthumbSize; cTVScraperDB *db; + map cache; bool parseJSON(string jsonString); int SearchMovie(string movieName); cMovieDbMovie *ReadMovie(int movieID); diff --git a/thetvdbscraper/thetvdbscraper.c b/thetvdbscraper/thetvdbscraper.c index 040baf6..19cbc7e 100644 --- a/thetvdbscraper/thetvdbscraper.c +++ b/thetvdbscraper/thetvdbscraper.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include "thetvdbscraper.h" @@ -26,11 +27,28 @@ void cTVDBScraper::Scrap(const cEvent *event, int recordingID) { if (config.enableDebug) esyslog("tvscraper: scraping series \"%s\"", seriesName.c_str()); int eventID = (int)event->EventID(); + + map::iterator cacheHit = cache.find(seriesName); + if (cacheHit != cache.end()) { + if (config.enableDebug) + esyslog("tvscraper: found in cache %s => %d", ((string)cacheHit->first).c_str(), (int)cacheHit->second); + int cachedSeriesID = (int)cacheHit->second; + if (cachedSeriesID > 0) { + if (!recordingID) { + time_t validTill = event->EndTime(); + db->InsertEventSeries(eventID, validTill, cachedSeriesID); + } else { + db->InsertRecording(recordingID, cachedSeriesID, 0); + } + } + return; + } cTVDBSeries *series = ReadSeries(seriesName); cTVDBSeriesMedia *media = NULL; cTVDBActors *actors = NULL; if (!series) return; + cache.insert(pair(seriesName, series->ID())); if (series->ID() < 1) { if (config.enableDebug) esyslog("tvscraper: nothing found for \"%s\"", seriesName.c_str()); @@ -50,13 +68,13 @@ void cTVDBScraper::Scrap(const cEvent *event, int recordingID) { } else { db->InsertRecording(recordingID, series->ID(), 0); } + if (config.enableDebug) + esyslog("tvscraper: \"%s\" successfully scraped, id %d", seriesName.c_str(), series->ID()); delete series; if (media) delete media; if (actors) delete actors; - if (config.enableDebug) - esyslog("tvscraper: \"%s\" successfully scraped, id %d", seriesName.c_str(), series->ID()); } @@ -72,10 +90,8 @@ bool cTVDBScraper::Connect(void) { } cTVDBSeries *cTVDBScraper::ReadSeries(string seriesName) { - stringstream seriesEscape; - seriesEscape << "\"" << seriesName << "\""; stringstream url; - url << mirrors->GetMirrorXML() << "/api/GetSeries.php?seriesname=" << CurlEscape(seriesEscape.str().c_str()) << "&language=" << language.c_str(); + url << mirrors->GetMirrorXML() << "/api/GetSeries.php?seriesname=" << CurlEscape(seriesName.c_str()) << "&language=" << language.c_str(); string seriesXML; cTVDBSeries *series = NULL; if (config.enableDebug) diff --git a/thetvdbscraper/thetvdbscraper.h b/thetvdbscraper/thetvdbscraper.h index 2659bdc..2e45f75 100644 --- a/thetvdbscraper/thetvdbscraper.h +++ b/thetvdbscraper/thetvdbscraper.h @@ -12,6 +12,7 @@ private: string baseDir; string language; cTVScraperDB *db; + map cache; cTVDBMirrors *mirrors; cTVDBSeries *ReadSeries(string seriesName); cTVDBSeriesMedia *ReadSeriesMedia(int seriesID); -- cgit v1.2.3