mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-29 00:11:14 +02:00
- tmdb: add movie selection menu
This commit is contained in:
@@ -20,6 +20,7 @@ AM_CPPFLAGS = \
|
||||
-I$(top_srcdir)/lib/xmltree \
|
||||
-I$(top_srcdir)/lib/libmd5sum \
|
||||
-I$(top_srcdir)/lib/libupnpclient \
|
||||
-I$(top_srcdir)/lib/jsoncpp \
|
||||
@SIGC_CFLAGS@ \
|
||||
@FREETYPE_CFLAGS@ \
|
||||
@AVFORMAT_CFLAGS@ \
|
||||
|
@@ -9,6 +9,7 @@ AM_CPPFLAGS += \
|
||||
-I$(top_srcdir)/lib/libeventserver \
|
||||
-I$(top_srcdir)/lib/libconfigfile \
|
||||
-I$(top_srcdir)/lib/xmltree \
|
||||
-I$(top_srcdir)/lib/jsoncpp \
|
||||
@SIGC_CFLAGS@ \
|
||||
@FREETYPE_CFLAGS@ \
|
||||
@LUA_CFLAGS@ \
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 2015,2018 TangoCash
|
||||
Copyright (C) 2015-2020 TangoCash
|
||||
|
||||
License: GPLv2
|
||||
|
||||
@@ -33,15 +33,15 @@
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include <neutrino.h>
|
||||
|
||||
#include "system/settings.h"
|
||||
#include <system/helpers-json.h>
|
||||
#include "system/set_threadname.h"
|
||||
#include "gui/widget/hintbox.h"
|
||||
|
||||
#include <driver/screen_max.h>
|
||||
|
||||
#include <global.h>
|
||||
#include <json/json.h>
|
||||
|
||||
#include "tmdb.h"
|
||||
|
||||
@@ -77,12 +77,12 @@ void cTmdb::setTitle(std::string epgtitle)
|
||||
std::string lang = Lang2ISO639_1(g_settings.language);
|
||||
GetMovieDetails(lang);
|
||||
if ((minfo.result < 1 || minfo.overview.empty()) && lang != "en")
|
||||
GetMovieDetails("en");
|
||||
GetMovieDetails("en", true);
|
||||
|
||||
hintbox.hide();
|
||||
}
|
||||
|
||||
bool cTmdb::GetMovieDetails(std::string lang)
|
||||
bool cTmdb::GetMovieDetails(std::string lang, bool second)
|
||||
{
|
||||
printf("[TMDB]: %s\n",__func__);
|
||||
std::string url = "http://api.themoviedb.org/3/search/multi?api_key="+key+"&language="+lang+"&query=" + encodeUrl(minfo.epgtitle);
|
||||
@@ -105,8 +105,15 @@ bool cTmdb::GetMovieDetails(std::string lang)
|
||||
|
||||
if (minfo.result > 0) {
|
||||
Json::Value elements = root["results"];
|
||||
minfo.id = elements[0].get("id",-1).asInt();
|
||||
minfo.media_type = elements[0].get("media_type","").asString();
|
||||
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 (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";
|
||||
answer.clear();
|
||||
@@ -191,3 +198,32 @@ void cTmdb::cleanup()
|
||||
if (access(TMDB_COVER, F_OK) == 0)
|
||||
unlink(TMDB_COVER);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
// we don't show introitems, so we add a separator for a smoother view
|
||||
m->addItem(GenericMenuSeparator);
|
||||
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());
|
||||
else
|
||||
mf = new CMenuForwarder(elements[i].get("name","").asString(), true, NULL, selector, to_string(i).c_str());
|
||||
m->addItem(mf);
|
||||
}
|
||||
|
||||
m->enableSaveScreen();
|
||||
m->exec(NULL, "");
|
||||
if (!m->gotAction())
|
||||
return;
|
||||
delete selector;
|
||||
m->hide();
|
||||
use_result = select;
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 2015 TangoCash
|
||||
Copyright (C) 2015-2020 TangoCash
|
||||
|
||||
License: GPLv2
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include <string>
|
||||
#include "system/helpers.h"
|
||||
#include <system/helpers-json.h>
|
||||
|
||||
#define TMDB_COVER "/tmp/tmdb.jpg"
|
||||
|
||||
@@ -50,7 +51,8 @@ class cTmdb
|
||||
tmdbinfo minfo;
|
||||
|
||||
std::string key; // tmdb api key
|
||||
bool GetMovieDetails(std::string lang);
|
||||
bool GetMovieDetails(std::string lang, bool second = false);
|
||||
void selectResult(Json::Value elements, int results, int &used_result);
|
||||
|
||||
public:
|
||||
cTmdb();
|
||||
|
Reference in New Issue
Block a user