mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-27 07:23:09 +02:00
TMDB: second try without (*)
This commit is contained in:
@@ -82,25 +82,45 @@ void cTmdb::setTitle(std::string epgtitle)
|
|||||||
hintbox.hide();
|
hintbox.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cTmdb::GetMovieDetails(std::string lang, bool second)
|
bool cTmdb::GetData(std::string url, Json::Value *root)
|
||||||
{
|
{
|
||||||
printf("[TMDB]: %s\n",__func__);
|
|
||||||
std::string url = "http://api.themoviedb.org/3/search/multi?api_key="+key+"&language="+lang+"&query=" + encodeUrl(minfo.epgtitle);
|
|
||||||
std::string answer;
|
std::string answer;
|
||||||
if (!getUrl(url, answer))
|
if (!getUrl(url, answer))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
std::string errMsg = "";
|
std::string errMsg = "";
|
||||||
Json::Value root;
|
bool ok = parseJsonFromString(answer, root, &errMsg);
|
||||||
bool ok = parseJsonFromString(answer, &root, &errMsg);
|
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
printf("Failed to parse JSON\n");
|
printf("Failed to parse JSON\n");
|
||||||
printf("%s\n", errMsg.c_str());
|
printf("%s\n", errMsg.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool cTmdb::GetMovieDetails(std::string lang, bool second)
|
||||||
|
{
|
||||||
|
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)))
|
||||||
|
return false;
|
||||||
|
|
||||||
minfo.result = root.get("total_results",0).asInt();
|
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){
|
||||||
|
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)))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
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) {
|
||||||
@@ -115,18 +135,10 @@ bool cTmdb::GetMovieDetails(std::string lang, bool second)
|
|||||||
minfo.media_type = elements[use_result].get("media_type","").asString();
|
minfo.media_type = elements[use_result].get("media_type","").asString();
|
||||||
}
|
}
|
||||||
if (minfo.id > -1) {
|
if (minfo.id > -1) {
|
||||||
url = "http://api.themoviedb.org/3/"+minfo.media_type+"/"+to_string(minfo.id)+"?api_key="+key+"&language="+lang+"&append_to_response=credits";
|
url = urlapi+minfo.media_type+"/"+to_string(minfo.id)+"?api_key="+key+"&language="+lang+"&append_to_response=credits";
|
||||||
answer.clear();
|
if(!(GetData(url, &root)))
|
||||||
if (!getUrl(url, answer))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ok = parseJsonFromString(answer, &root, &errMsg);
|
|
||||||
if (!ok) {
|
|
||||||
printf("Failed to parse JSON\n");
|
|
||||||
printf("%s\n", errMsg.c_str());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
minfo.overview = root.get("overview","").asString();
|
minfo.overview = root.get("overview","").asString();
|
||||||
minfo.poster_path = root.get("poster_path","").asString();
|
minfo.poster_path = root.get("poster_path","").asString();
|
||||||
minfo.original_title = root.get("original_title","").asString();;
|
minfo.original_title = root.get("original_title","").asString();;
|
||||||
|
@@ -52,6 +52,7 @@ class cTmdb
|
|||||||
|
|
||||||
std::string key; // tmdb api key
|
std::string key; // tmdb api key
|
||||||
bool GetMovieDetails(std::string lang, bool second = false);
|
bool GetMovieDetails(std::string lang, bool second = false);
|
||||||
|
bool GetData(std::string url, Json::Value *root);
|
||||||
void selectResult(Json::Value elements, int results, int &used_result);
|
void selectResult(Json::Value elements, int results, int &used_result);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Reference in New Issue
Block a user