mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-08-26 23:13:00 +02:00
imdb/tmdb: code formatations using astyle
Origin commit data
------------------
Branch: ni/coolstream
Commit: 13224efbf1
Author: vanhofen <vanhofen@gmx.de>
Date: 2021-04-10 (Sat, 10 Apr 2021)
Origin message was:
------------------
- imdb/tmdb: code formatations using astyle
------------------
No further description and justification available within origin commit message!
------------------
This commit was generated by Migit
This commit is contained in:
@@ -40,10 +40,10 @@
|
||||
|
||||
#include "mdb-imdb.h"
|
||||
|
||||
CIMDB* CIMDB::getInstance()
|
||||
CIMDB *CIMDB::getInstance()
|
||||
{
|
||||
static CIMDB* imdb = NULL;
|
||||
if(!imdb)
|
||||
static CIMDB *imdb = NULL;
|
||||
if (!imdb)
|
||||
imdb = new CIMDB();
|
||||
return imdb;
|
||||
}
|
||||
@@ -71,13 +71,16 @@ std::string CIMDB::utf82url(std::string s)
|
||||
std::stringstream ss;
|
||||
for (size_t i = 0; i < s.length(); ++i)
|
||||
{
|
||||
if (unsigned(s[i]) <= ' ') {
|
||||
if (unsigned(s[i]) <= ' ')
|
||||
{
|
||||
ss << '+';
|
||||
}
|
||||
else if (unsigned(s[i]) <= '\x27') {
|
||||
else if (unsigned(s[i]) <= '\x27')
|
||||
{
|
||||
ss << "%" << std::hex << unsigned(s[i]);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
ss << s[i];
|
||||
}
|
||||
}
|
||||
@@ -90,7 +93,7 @@ std::string CIMDB::parseString(std::string search1, std::string search2, std::st
|
||||
size_t pos_wildcard, pos_search1, pos_search2;
|
||||
pos_wildcard = pos_search1 = pos_search2 = std::string::npos;
|
||||
|
||||
if((pos_wildcard = search1.find('*')) != std::string::npos)
|
||||
if ((pos_wildcard = search1.find('*')) != std::string::npos)
|
||||
{
|
||||
search = search1.substr(0, pos_wildcard);
|
||||
//std::cout << "wildcard detected" << '\t' << "= " << search << "[*]" << search1.substr(pos_wildcard+1) << std::endl;
|
||||
@@ -99,19 +102,19 @@ std::string CIMDB::parseString(std::string search1, std::string search2, std::st
|
||||
search = search1;
|
||||
|
||||
//std::cout << "search1" << "\t\t\t" << "= " << '"' << search << '"' << std::endl;
|
||||
if((pos_search1 = str.find(search)) != std::string::npos)
|
||||
if ((pos_search1 = str.find(search)) != std::string::npos)
|
||||
{
|
||||
//std::cout << "search1 found" << "\t\t" << "= " << '"' << search << '"' << " at pos "<< (int)(pos_search1) << " => " << str << std::endl;
|
||||
|
||||
pos_search1 += search.length();
|
||||
|
||||
if(pos_wildcard != std::string::npos)
|
||||
if (pos_wildcard != std::string::npos)
|
||||
{
|
||||
size_t pos_wildcard_ext;
|
||||
std::string wildcard_ext = search1.substr(pos_wildcard+1);
|
||||
std::string wildcard_ext = search1.substr(pos_wildcard + 1);
|
||||
|
||||
//std::cout << "wildcard_ext" << "\t\t" << "= " << '"' << wildcard_ext << '"' << std::endl;
|
||||
if((pos_wildcard_ext = str.find(wildcard_ext,pos_wildcard+1)) != std::string::npos)
|
||||
if ((pos_wildcard_ext = str.find(wildcard_ext, pos_wildcard + 1)) != std::string::npos)
|
||||
{
|
||||
//std::cout << "wildcard_ext found" << "\t" << "= " << '"' << wildcard_ext << '"' << " at pos "<< (int)(pos_wildcard_ext) << " => " << str << std::endl;
|
||||
pos_search1 = pos_wildcard_ext + wildcard_ext.length();
|
||||
@@ -119,29 +122,29 @@ std::string CIMDB::parseString(std::string search1, std::string search2, std::st
|
||||
else
|
||||
{
|
||||
//std::cout << "wildcard_ext not found in line " << acc << " - exit" << std::endl;
|
||||
return("");
|
||||
return ("");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//std::cout << "search1 not found in line " << acc << " - exit" << std::endl;
|
||||
return("");
|
||||
return ("");
|
||||
}
|
||||
|
||||
if(pos_search1 != std::string::npos)
|
||||
if (pos_search1 != std::string::npos)
|
||||
{
|
||||
//std::cout << "search2 " << "\t\t" << "= " << '"' << search2 << '"' << std::endl;
|
||||
|
||||
if(search2 == "\n")
|
||||
if (search2 == "\n")
|
||||
{
|
||||
ret = str.substr(pos_search1, str.length() - pos_search1);
|
||||
return(ret);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
if((pos_search2 = str.find(search2, pos_search1)) != std::string::npos)
|
||||
if ((pos_search2 = str.find(search2, pos_search1)) != std::string::npos)
|
||||
{
|
||||
if(search2.empty())
|
||||
if (search2.empty())
|
||||
pos_search2 = str.length();
|
||||
|
||||
//std::cout << "search2" << "\t\t\t" << "= " << '"' << search2 << '"' << " found at "<< (int)(pos_search2) << " => " << str << std::endl;
|
||||
@@ -152,10 +155,10 @@ std::string CIMDB::parseString(std::string search1, std::string search2, std::st
|
||||
|
||||
}
|
||||
|
||||
return(ret);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
std::string CIMDB::parseFile(std::string search1, std::string search2, const char* file, std::string firstline, int line_offset)
|
||||
std::string CIMDB::parseFile(std::string search1, std::string search2, const char *file, std::string firstline, int line_offset)
|
||||
{
|
||||
|
||||
acc = 0;
|
||||
@@ -164,11 +167,11 @@ std::string CIMDB::parseFile(std::string search1, std::string search2, const cha
|
||||
size_t pos_firstline;
|
||||
pos_firstline = std::string::npos;
|
||||
|
||||
if(firstline.empty())
|
||||
if (firstline.empty())
|
||||
pos_firstline = 0;
|
||||
|
||||
fh.open(file, std::ios::in);
|
||||
if(fh.is_open())
|
||||
if (fh.is_open())
|
||||
{
|
||||
int line = 0;
|
||||
while (!fh.eof())
|
||||
@@ -176,33 +179,33 @@ std::string CIMDB::parseFile(std::string search1, std::string search2, const cha
|
||||
getline(fh, str);
|
||||
acc++;
|
||||
|
||||
if(pos_firstline == std::string::npos)
|
||||
if (pos_firstline == std::string::npos)
|
||||
{
|
||||
if((pos_firstline = str.find(firstline)) != std::string::npos)
|
||||
if ((pos_firstline = str.find(firstline)) != std::string::npos)
|
||||
{
|
||||
//std::cout << "firstline found " << str << std::endl;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if(line_offset /*&& pos_firstline != std::string::npos*/)
|
||||
if (line_offset /*&& pos_firstline != std::string::npos*/)
|
||||
{
|
||||
if(line+1 != line_offset)
|
||||
if (line + 1 != line_offset)
|
||||
{
|
||||
line++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
ret = parseString(search1,search2,str);
|
||||
ret = parseString(search1, search2, str);
|
||||
|
||||
if(!ret.empty())
|
||||
if (!ret.empty())
|
||||
break;
|
||||
}
|
||||
fh.close();
|
||||
}
|
||||
|
||||
return(ret);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
std::string CIMDB::googleIMDb(std::string s)
|
||||
@@ -210,7 +213,7 @@ std::string CIMDB::googleIMDb(std::string s)
|
||||
CHTTPTool httpTool;
|
||||
std::string ret = search_error;
|
||||
std::string search_string("title+");
|
||||
char* search_char = (char*) s.c_str();
|
||||
char *search_char = (char *) s.c_str();
|
||||
|
||||
m.clear();
|
||||
unlink(search_outfile.c_str());
|
||||
@@ -236,7 +239,7 @@ std::string CIMDB::googleIMDb(std::string s)
|
||||
{
|
||||
ret = parseFile("https://www.imdb.com/title/", ">", search_outfile.c_str());
|
||||
|
||||
if(ret.empty())
|
||||
if (ret.empty())
|
||||
ret = parseFile("http://www.imdb.de/title/", ">", search_outfile.c_str());
|
||||
|
||||
std::string delimiters = "/&;";
|
||||
@@ -247,19 +250,19 @@ std::string CIMDB::googleIMDb(std::string s)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void CIMDB::initMap( std::map<std::string, std::string>& my )
|
||||
void CIMDB::initMap(std::map<std::string, std::string> &my)
|
||||
{
|
||||
std::string errMsg = "";
|
||||
Json::Value root;
|
||||
|
||||
std::ostringstream ss;
|
||||
std::ifstream fh(imdb_outfile.c_str(),std::ifstream::in);
|
||||
std::ifstream fh(imdb_outfile.c_str(), std::ifstream::in);
|
||||
ss << fh.rdbuf();
|
||||
std::string filedata = ss.str();
|
||||
|
||||
bool parsedSuccess = parseJsonFromString(filedata, &root, &errMsg);
|
||||
|
||||
if(!parsedSuccess)
|
||||
if (!parsedSuccess)
|
||||
{
|
||||
std::cout << "Failed to parse JSON\n";
|
||||
std::cout << errMsg << std::endl;
|
||||
@@ -299,14 +302,14 @@ void CIMDB::initMap( std::map<std::string, std::string>& my )
|
||||
//my["Type"] = root.get("Type", "").asString();
|
||||
}
|
||||
|
||||
int CIMDB::getMovieDetails(const std::string& epgTitle)
|
||||
int CIMDB::getMovieDetails(const std::string &epgTitle)
|
||||
{
|
||||
CHTTPTool httpTool;
|
||||
int ret = 0;
|
||||
|
||||
std::string imdb_id = googleIMDb(epgTitle);
|
||||
|
||||
if(((imdb_id.find(search_error)) != std::string::npos))
|
||||
if (((imdb_id.find(search_error)) != std::string::npos))
|
||||
return ret;
|
||||
|
||||
std::string url = imdb_url + imdb_id;
|
||||
@@ -317,34 +320,36 @@ int CIMDB::getMovieDetails(const std::string& epgTitle)
|
||||
|
||||
//std::cout << "m now contains " << m.size() << " elements.\n";
|
||||
|
||||
if(m.empty() || m["Response"]!="True")
|
||||
if (m.empty() || m["Response"] != "True")
|
||||
return 0;
|
||||
|
||||
//for (std::map<std::string,std::string>::iterator it=m.begin(); it!=m.end(); ++it)
|
||||
// std::cout << it->first << " => " << it->second << '\n';
|
||||
|
||||
//download Poster
|
||||
if(m["Poster"] != "N/A")
|
||||
if (m["Poster"] != "N/A")
|
||||
{
|
||||
// if possible load bigger image
|
||||
std::string origURL ("300");
|
||||
std::string replURL ("600");
|
||||
std::string origURL("300");
|
||||
std::string replURL("600");
|
||||
|
||||
if (m["Poster"].compare(m["Poster"].size()-7,3,origURL) == 0){
|
||||
if (m["Poster"].compare(m["Poster"].size() - 7, 3, origURL) == 0)
|
||||
{
|
||||
//std::cout << "########## " << m["Poster"] << " contains " << origURL << '\n';
|
||||
m["Poster"].replace(m["Poster"].size()-7,3,replURL);
|
||||
m["Poster"].replace(m["Poster"].size() - 7, 3, replURL);
|
||||
//std::cout << "########## New string: " << m["Poster"] << '\n';
|
||||
}
|
||||
|
||||
if (httpTool.downloadFile(m["Poster"], posterfile.c_str()))
|
||||
return 2;
|
||||
else {
|
||||
else
|
||||
{
|
||||
if (access(posterfile.c_str(), F_OK) == 0)
|
||||
unlink(posterfile.c_str());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
ret=2;
|
||||
ret = 2;
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -434,13 +439,13 @@ std::string CIMDB::getMovieText()
|
||||
return movietext;
|
||||
}
|
||||
|
||||
std::string CIMDB::getFilename(CZapitChannel * channel, uint64_t id)
|
||||
std::string CIMDB::getFilename(CZapitChannel *channel, uint64_t id)
|
||||
{
|
||||
char fname[512]; // UTF-8
|
||||
char buf[256];
|
||||
unsigned int pos = 0;
|
||||
|
||||
if(check_dir(g_settings.network_nfs_recordingdir.c_str()))
|
||||
if (check_dir(g_settings.network_nfs_recordingdir.c_str()))
|
||||
return ("");
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s/", g_settings.network_nfs_recordingdir.c_str());
|
||||
@@ -451,36 +456,40 @@ std::string CIMDB::getFilename(CZapitChannel * channel, uint64_t id)
|
||||
if (FilenameTemplate.empty())
|
||||
FilenameTemplate = "%C_%T_%d_%t";
|
||||
|
||||
StringReplace(FilenameTemplate,"%d","");
|
||||
StringReplace(FilenameTemplate,"%t","");
|
||||
StringReplace(FilenameTemplate,"__","_");
|
||||
StringReplace(FilenameTemplate, "%d", "");
|
||||
StringReplace(FilenameTemplate, "%t", "");
|
||||
StringReplace(FilenameTemplate, "__", "_");
|
||||
|
||||
std::string channel_name = channel->getName();
|
||||
if (!(channel_name.empty())) {
|
||||
if (!(channel_name.empty()))
|
||||
{
|
||||
strcpy(buf, UTF8_TO_FILESYSTEM_ENCODING(channel_name.c_str()));
|
||||
ZapitTools::replace_char(buf);
|
||||
StringReplace(FilenameTemplate,"%C",buf);
|
||||
StringReplace(FilenameTemplate, "%C", buf);
|
||||
}
|
||||
else
|
||||
StringReplace(FilenameTemplate,"%C","no_channel");
|
||||
StringReplace(FilenameTemplate, "%C", "no_channel");
|
||||
|
||||
CShortEPGData epgdata;
|
||||
if(CEitManager::getInstance()->getEPGidShort(id, &epgdata)) {
|
||||
if (!(epgdata.title.empty())) {
|
||||
if (CEitManager::getInstance()->getEPGidShort(id, &epgdata))
|
||||
{
|
||||
if (!(epgdata.title.empty()))
|
||||
{
|
||||
strcpy(buf, epgdata.title.c_str());
|
||||
ZapitTools::replace_char(buf);
|
||||
StringReplace(FilenameTemplate,"%T",buf);
|
||||
StringReplace(FilenameTemplate, "%T", buf);
|
||||
}
|
||||
else
|
||||
StringReplace(FilenameTemplate,"%T","no_title");
|
||||
StringReplace(FilenameTemplate, "%T", "no_title");
|
||||
|
||||
if (!(epgdata.info1.empty())) {
|
||||
if (!(epgdata.info1.empty()))
|
||||
{
|
||||
strcpy(buf, epgdata.info1.c_str());
|
||||
ZapitTools::replace_char(buf);
|
||||
StringReplace(FilenameTemplate,"%I",buf);
|
||||
StringReplace(FilenameTemplate, "%I", buf);
|
||||
}
|
||||
else
|
||||
StringReplace(FilenameTemplate,"%I","no_info");
|
||||
StringReplace(FilenameTemplate, "%I", "no_info");
|
||||
}
|
||||
|
||||
strcpy(&(fname[pos]), UTF8_TO_FILESYSTEM_ENCODING(FilenameTemplate.c_str()));
|
||||
@@ -496,8 +505,9 @@ void CIMDB::StringReplace(std::string &str, const std::string search, const std:
|
||||
{
|
||||
std::string::size_type ptr = 0;
|
||||
std::string::size_type pos = 0;
|
||||
while((ptr = str.find(search,pos)) != std::string::npos){
|
||||
str.replace(ptr,search.length(),rstr);
|
||||
while ((ptr = str.find(search, pos)) != std::string::npos)
|
||||
{
|
||||
str.replace(ptr, search.length(), rstr);
|
||||
pos = ptr + rstr.length();
|
||||
}
|
||||
}
|
||||
|
@@ -37,15 +37,15 @@ class CIMDB
|
||||
std::string googleIMDb(std::string s);
|
||||
std::string utf82url(std::string s);
|
||||
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);
|
||||
std::map<std::string, std::string> m;
|
||||
|
||||
void initMap(std::map<std::string, std::string>& my);
|
||||
void initMap(std::map<std::string, std::string> &my);
|
||||
|
||||
public:
|
||||
CIMDB();
|
||||
~CIMDB();
|
||||
static CIMDB* getInstance();
|
||||
static CIMDB *getInstance();
|
||||
|
||||
std::string search_url;
|
||||
std::string search_outfile;
|
||||
@@ -53,20 +53,20 @@ class CIMDB
|
||||
std::string imdb_outfile;
|
||||
std::string posterfile;
|
||||
|
||||
int getMovieDetails(const std::string& epgTitle);
|
||||
std::string getFilename(CZapitChannel * channel, uint64_t id);
|
||||
int getMovieDetails(const std::string &epgTitle);
|
||||
std::string getFilename(CZapitChannel *channel, uint64_t id);
|
||||
void StringReplace(std::string &str, const std::string search, const std::string rstr);
|
||||
void cleanup();
|
||||
|
||||
std::string getEPGText();
|
||||
std::string getMovieText();
|
||||
|
||||
std::string getPoster() { return posterfile;}
|
||||
std::string getPoster() { return posterfile; }
|
||||
bool hasPoster() { return (access(posterfile.c_str(), F_OK) == 0); }
|
||||
|
||||
bool checkElement(std::string element);
|
||||
//FIXME: what if m[element] doesn't exist?
|
||||
std::string getIMDbElement(std::string element) { return m[element]; };
|
||||
std::string getIMDbElement(std::string element) { return m[element]; };
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@@ -42,10 +42,10 @@
|
||||
#include <global.h>
|
||||
#include "mdb-tmdb.h"
|
||||
|
||||
CTMDB* CTMDB::getInstance()
|
||||
CTMDB *CTMDB::getInstance()
|
||||
{
|
||||
static CTMDB* tmdb = NULL;
|
||||
if(!tmdb)
|
||||
static CTMDB *tmdb = NULL;
|
||||
if (!tmdb)
|
||||
tmdb = new CTMDB();
|
||||
return tmdb;
|
||||
}
|
||||
@@ -59,7 +59,7 @@ CTMDB::CTMDB()
|
||||
|
||||
CTMDB::~CTMDB()
|
||||
{
|
||||
cleanup();
|
||||
cleanup();
|
||||
}
|
||||
|
||||
void CTMDB::setTitle(std::string epgtitle)
|
||||
@@ -74,7 +74,8 @@ void CTMDB::setTitle(std::string epgtitle)
|
||||
if ((minfo.result < 1 || minfo.overview.empty()) && lang != "en")
|
||||
getMovieDetails("en", true);
|
||||
|
||||
if(hintbox){
|
||||
if (hintbox)
|
||||
{
|
||||
hintbox->hide();
|
||||
delete hintbox;
|
||||
hintbox = NULL;
|
||||
@@ -89,7 +90,8 @@ bool CTMDB::getData(std::string url, Json::Value *root)
|
||||
|
||||
std::string errMsg = "";
|
||||
bool ok = parseJsonFromString(answer, root, &errMsg);
|
||||
if (!ok) {
|
||||
if (!ok)
|
||||
{
|
||||
printf("Failed to parse JSON\n");
|
||||
printf("%s\n", errMsg.c_str());
|
||||
return false;
|
||||
@@ -99,75 +101,84 @@ bool CTMDB::getData(std::string url, Json::Value *root)
|
||||
|
||||
bool CTMDB::getMovieDetails(std::string lang, bool second)
|
||||
{
|
||||
printf("[TMDB]: %s\n",__func__);
|
||||
printf("[TMDB]: %s\n", __func__);
|
||||
Json::Value root;
|
||||
const std::string urlapi = "http://api.themoviedb.org/3/";
|
||||
std::string url = urlapi + "search/multi?api_key="+key+"&language="+lang+"&query=" + encodeUrl(minfo.epgtitle);
|
||||
if(!(getData(url, &root)))
|
||||
std::string url = urlapi + "search/multi?api_key=" + key + "&language=" + lang + "&query=" + encodeUrl(minfo.epgtitle);
|
||||
if (!(getData(url, &root)))
|
||||
return false;
|
||||
|
||||
minfo.result = root.get("total_results",0).asInt();
|
||||
if(minfo.result == 0){
|
||||
minfo.result = root.get("total_results", 0).asInt();
|
||||
if (minfo.result == 0)
|
||||
{
|
||||
std::string title = minfo.epgtitle;
|
||||
size_t pos1 = title.find_last_of("(");
|
||||
size_t pos2 = title.find_last_of(")");
|
||||
if(pos1 != std::string::npos && pos2 != std::string::npos && pos2 > pos1){
|
||||
if (pos1 != std::string::npos && pos2 != std::string::npos && pos2 > pos1)
|
||||
{
|
||||
printf("[TMDB]: second try\n");
|
||||
title.replace(pos1, pos2-pos1+1, "");
|
||||
url = urlapi + "search/multi?api_key="+key+"&language="+lang+"&query=" + encodeUrl(title);
|
||||
if(!(getData(url, &root)))
|
||||
title.replace(pos1, pos2 - pos1 + 1, "");
|
||||
url = urlapi + "search/multi?api_key=" + key + "&language=" + lang + "&query=" + encodeUrl(title);
|
||||
if (!(getData(url, &root)))
|
||||
return false;
|
||||
|
||||
minfo.result = root.get("total_results",0).asInt();
|
||||
minfo.result = root.get("total_results", 0).asInt();
|
||||
}
|
||||
}
|
||||
printf("[TMDB]: results: %d\n",minfo.result);
|
||||
printf("[TMDB]: results: %d\n", minfo.result);
|
||||
|
||||
if (minfo.result > 0) {
|
||||
if (minfo.result > 0)
|
||||
{
|
||||
Json::Value elements = root["results"];
|
||||
int use_result = 0;
|
||||
|
||||
if ((minfo.result > 1) && (!second))
|
||||
selectResult(elements, minfo.result, use_result);
|
||||
|
||||
if (!second) {
|
||||
minfo.id = elements[use_result].get("id",-1).asInt();
|
||||
minfo.media_type = elements[use_result].get("media_type","").asString();
|
||||
if (!second)
|
||||
{
|
||||
minfo.id = elements[use_result].get("id", -1).asInt();
|
||||
minfo.media_type = elements[use_result].get("media_type", "").asString();
|
||||
}
|
||||
if (minfo.id > -1) {
|
||||
url = urlapi+minfo.media_type+"/"+to_string(minfo.id)+"?api_key="+key+"&language="+lang+"&append_to_response=credits";
|
||||
if(!(getData(url, &root)))
|
||||
if (minfo.id > -1)
|
||||
{
|
||||
url = urlapi + minfo.media_type + "/" + to_string(minfo.id) + "?api_key=" + key + "&language=" + lang + "&append_to_response=credits";
|
||||
if (!(getData(url, &root)))
|
||||
return false;
|
||||
|
||||
minfo.overview = root.get("overview","").asString();
|
||||
minfo.poster_path = root.get("poster_path","").asString();
|
||||
minfo.original_title = root.get("original_title","").asString();;
|
||||
minfo.release_date = root.get("release_date","").asString();;
|
||||
minfo.vote_average = root.get("vote_average","").asString();;
|
||||
minfo.vote_count = root.get("vote_count",0).asInt();;
|
||||
minfo.runtime = root.get("runtime",0).asInt();;
|
||||
if (minfo.media_type == "tv") {
|
||||
minfo.original_title = root.get("original_name","").asString();;
|
||||
minfo.episodes = root.get("number_of_episodes",0).asInt();;
|
||||
minfo.seasons = root.get("number_of_seasons",0).asInt();;
|
||||
minfo.release_date = root.get("first_air_date","").asString();;
|
||||
minfo.overview = root.get("overview", "").asString();
|
||||
minfo.poster_path = root.get("poster_path", "").asString();
|
||||
minfo.original_title = root.get("original_title", "").asString();;
|
||||
minfo.release_date = root.get("release_date", "").asString();;
|
||||
minfo.vote_average = root.get("vote_average", "").asString();;
|
||||
minfo.vote_count = root.get("vote_count", 0).asInt();;
|
||||
minfo.runtime = root.get("runtime", 0).asInt();;
|
||||
if (minfo.media_type == "tv")
|
||||
{
|
||||
minfo.original_title = root.get("original_name", "").asString();;
|
||||
minfo.episodes = root.get("number_of_episodes", 0).asInt();;
|
||||
minfo.seasons = root.get("number_of_seasons", 0).asInt();;
|
||||
minfo.release_date = root.get("first_air_date", "").asString();;
|
||||
elements = root["episode_run_time"];
|
||||
minfo.runtimes = elements[0].asString();
|
||||
for (unsigned int i= 1; i<elements.size();i++) {
|
||||
minfo.runtimes += + ", "+elements[i].asString();
|
||||
for (unsigned int i = 1; i < elements.size(); i++)
|
||||
{
|
||||
minfo.runtimes += + ", " + elements[i].asString();
|
||||
}
|
||||
}
|
||||
|
||||
elements = root["genres"];
|
||||
minfo.genres = elements[0].get("name","").asString();
|
||||
for (unsigned int i= 1; i<elements.size();i++) {
|
||||
minfo.genres += ", " + elements[i].get("name","").asString();
|
||||
minfo.genres = elements[0].get("name", "").asString();
|
||||
for (unsigned int i = 1; i < elements.size(); i++)
|
||||
{
|
||||
minfo.genres += ", " + elements[i].get("name", "").asString();
|
||||
}
|
||||
|
||||
elements = root["credits"]["cast"];
|
||||
minfo.cast.clear();
|
||||
for (unsigned int i= 0; i<elements.size() && i<10;i++) {
|
||||
minfo.cast += " "+elements[i].get("character","").asString()+" ("+elements[i].get("name","").asString() + ")\n";
|
||||
for (unsigned int i = 0; i < elements.size() && i < 10; i++)
|
||||
{
|
||||
minfo.cast += " " + elements[i].get("character", "").asString() + " (" + elements[i].get("name", "").asString() + ")\n";
|
||||
//printf("test: %s (%s)\n",elements[i].get("character","").asString().c_str(),elements[i].get("name","").asString().c_str());
|
||||
}
|
||||
|
||||
@@ -178,7 +189,8 @@ bool CTMDB::getMovieDetails(std::string lang, bool second)
|
||||
|
||||
return true;
|
||||
}
|
||||
} else
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
return false;
|
||||
@@ -188,7 +200,7 @@ std::string CTMDB::getEPGText()
|
||||
{
|
||||
std::string epgtext("");
|
||||
|
||||
epgtext += "Vote: " + minfo.vote_average.substr(0,3) + "/10 Votecount: " + to_string(minfo.vote_count) + "\n";
|
||||
epgtext += "Vote: " + minfo.vote_average.substr(0, 3) + "/10 Votecount: " + to_string(minfo.vote_count) + "\n";
|
||||
epgtext += "\n";
|
||||
epgtext += minfo.overview + "\n";
|
||||
epgtext += "\n";
|
||||
@@ -198,7 +210,7 @@ std::string CTMDB::getEPGText()
|
||||
epgtext += g_Locale->getString(LOCALE_EPGVIEWER_LENGTH) + ": " + to_string(minfo.runtime) + "\n";
|
||||
epgtext += g_Locale->getString(LOCALE_EPGVIEWER_GENRE) + ": " + minfo.genres + "\n";
|
||||
epgtext += g_Locale->getString(LOCALE_EPGEXTENDED_ORIGINAL_TITLE) + ": " + minfo.original_title + "\n";
|
||||
epgtext += g_Locale->getString(LOCALE_EPGEXTENDED_YEAR_OF_PRODUCTION) + ": " + minfo.release_date.substr(0,4) + "\n";
|
||||
epgtext += g_Locale->getString(LOCALE_EPGEXTENDED_YEAR_OF_PRODUCTION) + ": " + minfo.release_date.substr(0, 4) + "\n";
|
||||
if (minfo.media_type == "tv")
|
||||
epgtext += "Seasons/Episodes: " + to_string(minfo.seasons) + "/" + to_string(minfo.episodes) + "\n";
|
||||
if (!minfo.cast.empty())
|
||||
@@ -233,7 +245,8 @@ void CTMDB::cleanup()
|
||||
|
||||
void CTMDB::selectResult(Json::Value elements, int results, int &use_result)
|
||||
{
|
||||
if(hintbox){
|
||||
if (hintbox)
|
||||
{
|
||||
hintbox->hide();
|
||||
delete hintbox;
|
||||
hintbox = NULL;
|
||||
@@ -242,18 +255,18 @@ void CTMDB::selectResult(Json::Value elements, int results, int &use_result)
|
||||
int select = 0;
|
||||
|
||||
CMenuWidget *m = new CMenuWidget(LOCALE_TMDB_READ_DATA, NEUTRINO_ICON_SETTINGS);
|
||||
CMenuSelectorTarget * selector = new CMenuSelectorTarget(&select);
|
||||
CMenuSelectorTarget *selector = new CMenuSelectorTarget(&select);
|
||||
|
||||
// we don't show introitems, so we add a separator for a smoother view
|
||||
m->addItem(GenericMenuSeparator);
|
||||
CMenuForwarder* mf;
|
||||
CMenuForwarder *mf;
|
||||
int counter = std::min(results, 10);
|
||||
for (int i = 0; i != counter; i++)
|
||||
{
|
||||
if (elements[i].get("media_type","").asString() == "movie")
|
||||
mf = new CMenuForwarder(elements[i].get("title","").asString(), true, NULL, selector, to_string(i).c_str());
|
||||
if (elements[i].get("media_type", "").asString() == "movie")
|
||||
mf = new CMenuForwarder(elements[i].get("title", "").asString(), true, NULL, selector, to_string(i).c_str());
|
||||
else
|
||||
mf = new CMenuForwarder(elements[i].get("name","").asString(), true, NULL, selector, to_string(i).c_str());
|
||||
mf = new CMenuForwarder(elements[i].get("name", "").asString(), true, NULL, selector, to_string(i).c_str());
|
||||
m->addItem(mf);
|
||||
}
|
||||
|
||||
|
@@ -27,7 +27,8 @@
|
||||
#include <system/helpers-json.h>
|
||||
#include <gui/widget/hintbox.h>
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
std::string epgtitle;
|
||||
std::string poster_path;
|
||||
std::string overview;
|
||||
@@ -44,13 +45,13 @@ typedef struct {
|
||||
int episodes;
|
||||
int seasons;
|
||||
std::string cast;
|
||||
}tmdbinfo;
|
||||
} tmdbinfo;
|
||||
|
||||
class CTMDB
|
||||
{
|
||||
private:
|
||||
tmdbinfo minfo;
|
||||
CHintBox* hintbox;
|
||||
CHintBox *hintbox;
|
||||
std::string key; // tmdb api key
|
||||
bool getMovieDetails(std::string lang, bool second = false);
|
||||
bool getData(std::string url, Json::Value *root);
|
||||
@@ -60,23 +61,23 @@ class CTMDB
|
||||
public:
|
||||
CTMDB();
|
||||
~CTMDB();
|
||||
static CTMDB* getInstance();
|
||||
static CTMDB *getInstance();
|
||||
void setTitle(std::string epgtitle);
|
||||
std::string getEPGText();
|
||||
std::string getMovieText();
|
||||
|
||||
std::string getTitle() { return minfo.epgtitle;}
|
||||
std::string getOrgTitle() { return minfo.original_title;}
|
||||
std::string getReleaseDate() { return minfo.release_date;}
|
||||
std::string getDescription() { return minfo.overview;}
|
||||
std::string getVote() { return minfo.vote_average;}
|
||||
std::string getCast() { return minfo.cast;}
|
||||
std::string getPoster() { return posterfile;}
|
||||
bool hasPoster() { return !minfo.poster_path.empty();}
|
||||
bool getBigPoster(std::string poster) { return downloadUrl("http://image.tmdb.org/t/p/w342" + minfo.poster_path, poster);}
|
||||
bool getSmallPoster(std::string poster) { return downloadUrl("http://image.tmdb.org/t/p/w185" + minfo.poster_path, poster);}
|
||||
int getResults() { return minfo.result;}
|
||||
int getStars() { return (int) (atof(minfo.vote_average.c_str())*10);}
|
||||
std::string getTitle() { return minfo.epgtitle; }
|
||||
std::string getOrgTitle() { return minfo.original_title; }
|
||||
std::string getReleaseDate() { return minfo.release_date; }
|
||||
std::string getDescription() { return minfo.overview; }
|
||||
std::string getVote() { return minfo.vote_average; }
|
||||
std::string getCast() { return minfo.cast; }
|
||||
std::string getPoster() { return posterfile; }
|
||||
bool hasPoster() { return !minfo.poster_path.empty(); }
|
||||
bool getBigPoster(std::string poster) { return downloadUrl("http://image.tmdb.org/t/p/w342" + minfo.poster_path, poster); }
|
||||
bool getSmallPoster(std::string poster) { return downloadUrl("http://image.tmdb.org/t/p/w185" + minfo.poster_path, poster); }
|
||||
int getResults() { return minfo.result; }
|
||||
int getStars() { return (int)(atof(minfo.vote_average.c_str()) * 10); }
|
||||
void cleanup();
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user