diff options
| author | louis <louis.braun@gmx.de> | 2013-08-25 12:21:59 +0200 |
|---|---|---|
| committer | louis <louis.braun@gmx.de> | 2013-08-25 12:21:59 +0200 |
| commit | e364bce7d1e9b60d647d5fe8ee98e1c9c37317ef (patch) | |
| tree | 7036573013aef8ec244134ec13167a2f10c26c05 /themoviedbscraper | |
| parent | d11d4ed78e2c83bc98c00c39b9d601a8694698a7 (diff) | |
| download | vdr-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
Diffstat (limited to 'themoviedbscraper')
| -rw-r--r-- | themoviedbscraper/themoviedbscraper.c | 12 | ||||
| -rw-r--r-- | themoviedbscraper/themoviedbscraper.h | 1 |
2 files changed, 10 insertions, 3 deletions
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);
|
