summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlouis <louis.braun@gmx.de>2013-08-25 12:21:59 +0200
committerlouis <louis.braun@gmx.de>2013-08-25 12:21:59 +0200
commite364bce7d1e9b60d647d5fe8ee98e1c9c37317ef (patch)
tree7036573013aef8ec244134ec13167a2f10c26c05
parentd11d4ed78e2c83bc98c00c39b9d601a8694698a7 (diff)
downloadvdr-plugin-tvscraper-e364bce7d1e9b60d647d5fe8ee98e1c9c37317ef.tar.gz
vdr-plugin-tvscraper-e364bce7d1e9b60d647d5fe8ee98e1c9c37317ef.tar.bz2
Implemented cache so that an already looked up series or movie will not be looked up again
-rw-r--r--HISTORY4
-rw-r--r--themoviedbscraper/themoviedbscraper.c12
-rw-r--r--themoviedbscraper/themoviedbscraper.h1
-rw-r--r--thetvdbscraper/thetvdbscraper.c26
-rw-r--r--thetvdbscraper/thetvdbscraper.h1
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 <string>
#include <sstream>
#include <vector>
+#include <map>
#include <jansson.h>
#include "themoviedbscraper.h"
@@ -94,10 +95,14 @@ bool cMovieDBScraper::parseJSON(string jsonString) {
}
int cMovieDBScraper::SearchMovie(string movieName) {
- stringstream movieEscaped;
- movieEscaped << "\"" << movieName << "\"";
+ map<string,int>::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<string, int>(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<string, int> 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 <string>
#include <sstream>
#include <vector>
+#include <map>
#include <libxml/parser.h>
#include <libxml/tree.h>
#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<string,int>::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<string, int>(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<string, int> cache;
cTVDBMirrors *mirrors;
cTVDBSeries *ReadSeries(string seriesName);
cTVDBSeriesMedia *ReadSeriesMedia(int seriesID);