mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-09-17 18:33:41 +02:00
- imdb/tmdb: code formatations using astyle
Conflicts: src/gui/mdb-tmdb.h Signed-off-by: Thilo Graf <dbt@novatux.de>
This commit is contained in:
@@ -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];
|
||||
}
|
||||
}
|
||||
@@ -330,7 +333,8 @@ int CIMDB::getMovieDetails(const std::string& epgTitle)
|
||||
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);
|
||||
//std::cout << "########## New string: " << m["Poster"] << '\n';
|
||||
@@ -338,7 +342,8 @@ int CIMDB::getMovieDetails(const std::string& epgTitle)
|
||||
|
||||
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;
|
||||
@@ -456,7 +461,8 @@ std::string CIMDB::getFilename(CZapitChannel * channel, uint64_t id)
|
||||
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);
|
||||
@@ -465,8 +471,10 @@ std::string CIMDB::getFilename(CZapitChannel * channel, uint64_t id)
|
||||
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);
|
||||
@@ -474,7 +482,8 @@ std::string CIMDB::getFilename(CZapitChannel * channel, uint64_t id)
|
||||
else
|
||||
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);
|
||||
@@ -496,7 +505,8 @@ 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){
|
||||
while ((ptr = str.find(search, pos)) != std::string::npos)
|
||||
{
|
||||
str.replace(ptr, search.length(), rstr);
|
||||
pos = ptr + rstr.length();
|
||||
}
|
||||
|
@@ -78,7 +78,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;
|
||||
@@ -93,7 +94,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;
|
||||
@@ -111,11 +113,13 @@ bool CTMDB::getMovieDetails(std::string lang, bool second)
|
||||
return false;
|
||||
|
||||
minfo.result = root.get("total_results", 0).asInt();
|
||||
if(minfo.result == 0){
|
||||
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);
|
||||
@@ -127,18 +131,21 @@ bool CTMDB::getMovieDetails(std::string lang, bool second)
|
||||
}
|
||||
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) {
|
||||
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) {
|
||||
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;
|
||||
@@ -150,27 +157,31 @@ bool CTMDB::getMovieDetails(std::string lang, bool second)
|
||||
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") {
|
||||
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++) {
|
||||
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++) {
|
||||
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++) {
|
||||
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());
|
||||
}
|
||||
@@ -182,7 +193,8 @@ bool CTMDB::getMovieDetails(std::string lang, bool second)
|
||||
|
||||
return true;
|
||||
}
|
||||
} else
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
return false;
|
||||
@@ -237,7 +249,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;
|
||||
|
@@ -1,4 +1,6 @@
|
||||
/*
|
||||
Movie Database - TMDb
|
||||
|
||||
Copyright (C) 2015-2020 TangoCash
|
||||
|
||||
License: GPLv2
|
||||
@@ -25,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;
|
||||
@@ -74,7 +77,7 @@ class CTMDB
|
||||
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())+0.5);}
|
||||
int getStars() { return (int)(atof(minfo.vote_average.c_str()) * 10); }
|
||||
void cleanup();
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user