imdb: cosmetics

Origin commit data
------------------
Commit: 4ef7333bf9
Author: vanhofen <vanhofen@gmx.de>
Date: 2017-05-29 (Mon, 29 May 2017)

Origin message was:
------------------
- imdb: cosmetics
This commit is contained in:
vanhofen
2017-05-29 16:30:39 +02:00
parent 0ff784a92d
commit 70bd825e23
3 changed files with 40 additions and 36 deletions

View File

@@ -1645,7 +1645,7 @@ int CEpgData::showIMDb(bool splash)
//titel //titel
std::string title = imdb->getIMDbElement("Title"); std::string title = imdb->getIMDbElement("Title");
if(((title.find("IMDb: Google Download fehlgeschlagen")) != std::string::npos)) if(((title.find(imdb->search_error)) != std::string::npos))
return 1; return 1;
// clear epg array // clear epg array

View File

@@ -42,11 +42,12 @@
CIMDB::CIMDB() CIMDB::CIMDB()
{ {
surl = "http://www.google.de/search?q="; search_url = "http://www.google.de/search?q=";
soutfile = "/tmp/google.out"; search_outfile = "/tmp/google.out";
IMDburl = "http://www.omdbapi.com/?plot=full&r=json&i="; search_error = "IMDb: Google download failed";
IMDbAPI = "/tmp/imdb.json"; imdb_url = "http://www.omdbapi.com/?plot=full&r=json&i=";
omdbapiKey = "&apikey=20711f9e"; imdb_outfile = "/tmp/imdb.json";
omdb_apikey = "&apikey=20711f9e";
posterfile = "/tmp/imdb.jpg"; posterfile = "/tmp/imdb.jpg";
stars_bg = ICONSDIR "/stars_bg.png"; stars_bg = ICONSDIR "/stars_bg.png";
stars = ICONSDIR "/stars.png"; stars = ICONSDIR "/stars.png";
@@ -203,38 +204,39 @@ std::string CIMDB::parseFile(std::string search1, std::string search2, const cha
return(ret); return(ret);
} }
std::string CIMDB::googleIMDb(std::string searchStr) std::string CIMDB::googleIMDb(std::string s)
{ {
CHTTPTool httpTool; CHTTPTool httpTool;
std::string ret = "IMDb: Google Download fehlgeschlagen"; std::string ret = search_error;
std::string httpString = "imdb+"; std::string search_string("");
char* searchStr_ = (char*) searchStr.c_str(); char* search_char = (char*) s.c_str();
m.clear(); m.clear();
unlink(soutfile.c_str()); unlink(search_outfile.c_str());
unlink(IMDbAPI.c_str()); unlink(imdb_outfile.c_str());
unlink(posterfile.c_str()); unlink(posterfile.c_str());
while (*searchStr_!=0) while (*search_char != 0)
{ {
if ( (*searchStr_==' ') ) if (*search_char == ' ')
{ {
httpString += '+'; search_string += '+';
} else
{
httpString += *searchStr_;
} }
searchStr_++; else
{
search_string += *search_char;
}
search_char++;
} }
std::string url = surl + utf82url(httpString) + "%20site:www.imdb.com"; std::string url = search_url + utf82url(search_string) + "%20site:www.imdb.com";
if (httpTool.downloadFile(url, soutfile.c_str())) if (httpTool.downloadFile(url, search_outfile.c_str()))
{ {
ret = parseFile("http://www.imdb.com/title/", ">", soutfile.c_str()); ret = parseFile("http://www.imdb.com/title/", ">", search_outfile.c_str());
if(ret.empty()) if(ret.empty())
ret = parseFile("http://www.imdb.de/title/", ">", soutfile.c_str()); ret = parseFile("http://www.imdb.de/title/", ">", search_outfile.c_str());
std::string delimiters = "/&;"; std::string delimiters = "/&;";
size_t next = ret.find_first_of(delimiters, 0); size_t next = ret.find_first_of(delimiters, 0);
@@ -250,7 +252,7 @@ void CIMDB::initMap( std::map<std::string, std::string>& my )
Json::Reader reader; Json::Reader reader;
std::ostringstream ss; std::ostringstream ss;
std::ifstream fh(IMDbAPI.c_str(),std::ifstream::in); std::ifstream fh(imdb_outfile.c_str(),std::ifstream::in);
ss << fh.rdbuf(); ss << fh.rdbuf();
std::string filedata = ss.str(); std::string filedata = ss.str();
@@ -301,14 +303,14 @@ int CIMDB::getIMDb(const std::string& epgTitle)
CHTTPTool httpTool; CHTTPTool httpTool;
int ret = 0; int ret = 0;
std::string imdb_ID = googleIMDb(epgTitle); std::string imdb_id = googleIMDb(epgTitle);
if(((imdb_ID.find("IMDb: ")) != std::string::npos)) if(((imdb_id.find(search_error)) != std::string::npos))
return ret; return ret;
std::string url = IMDburl + imdb_ID + omdbapiKey; std::string url = imdb_url + imdb_id + omdb_apikey;
if (httpTool.downloadFile(url, IMDbAPI.c_str())) if (httpTool.downloadFile(url, imdb_outfile.c_str()))
{ {
initMap(m); initMap(m);
@@ -457,8 +459,8 @@ void CIMDB::StringReplace(std::string &str, const std::string search, const std:
void CIMDB::cleanup() void CIMDB::cleanup()
{ {
if (access(soutfile.c_str(), F_OK) == 0) if (access(search_outfile.c_str(), F_OK) == 0)
unlink(soutfile.c_str()); unlink(search_outfile.c_str());
if (access(posterfile.c_str(), F_OK) == 0) if (access(posterfile.c_str(), F_OK) == 0)
unlink(posterfile.c_str()); unlink(posterfile.c_str());
} }

View File

@@ -37,13 +37,15 @@ class CIMDB
~CIMDB(); ~CIMDB();
static CIMDB* getInstance(); static CIMDB* getInstance();
std::string surl; std::string search_url;
std::string soutfile; std::string search_outfile;
std::string IMDbAPI; std::string search_error;
std::string imdb_outfile;
std::string posterfile; std::string posterfile;
std::string stars_bg; std::string stars_bg;
std::string stars; std::string stars;
int getIMDb(const std::string& epgTitle); int getIMDb(const std::string& epgTitle);
std::string getFilename(CZapitChannel * channel, uint64_t id); std::string getFilename(CZapitChannel * channel, uint64_t id);
void StringReplace(std::string &str, const std::string search, const std::string rstr); void StringReplace(std::string &str, const std::string search, const std::string rstr);
@@ -59,9 +61,9 @@ class CIMDB
private: private:
int acc; int acc;
std::string IMDburl; std::string imdb_url;
std::string omdbapiKey; std::string omdb_apikey;
std::string googleIMDb(std::string searchStr); std::string googleIMDb(std::string s);
std::string utf82url(std::string s); std::string utf82url(std::string s);
std::string parseString(std::string search1, std::string search2, std::string str); std::string parseString(std::string search1, std::string search2, std::string str);
std::string parseFile(std::string search1, std::string search2, const char* file, std::string firstline="", int line_offset=0); std::string parseFile(std::string search1, std::string search2, const char* file, std::string firstline="", int line_offset=0);