mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-29 00:11:14 +02:00
rework tmdb class
This commit is contained in:
@@ -50,7 +50,6 @@
|
|||||||
#include <gui/moviebrowser/mb.h>
|
#include <gui/moviebrowser/mb.h>
|
||||||
#include <gui/movieplayer.h>
|
#include <gui/movieplayer.h>
|
||||||
#include <gui/pictureviewer.h>
|
#include <gui/pictureviewer.h>
|
||||||
#include <gui/tmdb.h>
|
|
||||||
#include <driver/record.h>
|
#include <driver/record.h>
|
||||||
#include <driver/fontrenderer.h>
|
#include <driver/fontrenderer.h>
|
||||||
|
|
||||||
@@ -59,8 +58,6 @@
|
|||||||
#include <eitd/sectionsd.h>
|
#include <eitd/sectionsd.h>
|
||||||
#include <timerdclient/timerdclient.h>
|
#include <timerdclient/timerdclient.h>
|
||||||
|
|
||||||
#define TMDB_COVER "/tmp/tmdb.jpg"
|
|
||||||
|
|
||||||
extern CPictureViewer * g_PicViewer;
|
extern CPictureViewer * g_PicViewer;
|
||||||
|
|
||||||
#define ICON_LARGE_WIDTH 26
|
#define ICON_LARGE_WIDTH 26
|
||||||
@@ -125,7 +122,6 @@ CEpgData::CEpgData()
|
|||||||
{
|
{
|
||||||
bigFonts = false;
|
bigFonts = false;
|
||||||
frameBuffer = CFrameBuffer::getInstance();
|
frameBuffer = CFrameBuffer::getInstance();
|
||||||
tmdb_active = false;
|
|
||||||
mp_movie_info = NULL;
|
mp_movie_info = NULL;
|
||||||
header = NULL;
|
header = NULL;
|
||||||
Bottombox = NULL;
|
Bottombox = NULL;
|
||||||
@@ -135,6 +131,8 @@ CEpgData::CEpgData()
|
|||||||
|
|
||||||
imdb = CIMDB::getInstance();
|
imdb = CIMDB::getInstance();
|
||||||
imdb_active = false;
|
imdb_active = false;
|
||||||
|
tmdb = cTmdb::getInstance();
|
||||||
|
tmdb_active = false;
|
||||||
movie_filename.clear();
|
movie_filename.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,7 +242,7 @@ void CEpgData::processTextToArray(std::string text, int screening, bool has_cove
|
|||||||
void CEpgData::showText(int startPos, int ypos, bool has_cover, bool fullClear)
|
void CEpgData::showText(int startPos, int ypos, bool has_cover, bool fullClear)
|
||||||
{
|
{
|
||||||
Font* font = g_Font[SNeutrinoSettings::FONT_TYPE_EPG_INFO2];
|
Font* font = g_Font[SNeutrinoSettings::FONT_TYPE_EPG_INFO2];
|
||||||
std::string cover = "/tmp/tmdb.jpg"; //todo: maybe add a getCover()-function to tmdb class
|
std::string cover = tmdb->getCover();
|
||||||
int cover_max_width = ox/4; //25%
|
int cover_max_width = ox/4; //25%
|
||||||
int cover_max_height = sb-(2*OFFSET_INNER_MID);
|
int cover_max_height = sb-(2*OFFSET_INNER_MID);
|
||||||
int cover_width = 0;
|
int cover_width = 0;
|
||||||
@@ -1164,7 +1162,7 @@ int CEpgData::show(const t_channel_id channel_id, uint64_t a_id, time_t* a_start
|
|||||||
{
|
{
|
||||||
showPos = 0;
|
showPos = 0;
|
||||||
if (!tmdb_active) {
|
if (!tmdb_active) {
|
||||||
cTmdb* tmdb = new cTmdb(epgData.title);
|
tmdb->setTitle(epgData.title);
|
||||||
if ((tmdb->getResults() > 0) && (!tmdb->getDescription().empty())) {
|
if ((tmdb->getResults() > 0) && (!tmdb->getDescription().empty())) {
|
||||||
epgText_saved = epgText;
|
epgText_saved = epgText;
|
||||||
epgText.clear();
|
epgText.clear();
|
||||||
@@ -1181,7 +1179,6 @@ int CEpgData::show(const t_channel_id channel_id, uint64_t a_id, time_t* a_start
|
|||||||
} else {
|
} else {
|
||||||
ShowMsg(LOCALE_MESSAGEBOX_INFO, LOCALE_EPGVIEWER_NODETAILED, CMsgBox::mbrOk , CMsgBox::mbrOk);
|
ShowMsg(LOCALE_MESSAGEBOX_INFO, LOCALE_EPGVIEWER_NODETAILED, CMsgBox::mbrOk , CMsgBox::mbrOk);
|
||||||
}
|
}
|
||||||
delete tmdb;
|
|
||||||
} else {
|
} else {
|
||||||
epgText = epgText_saved;
|
epgText = epgText_saved;
|
||||||
textCount = epgText.size();
|
textCount = epgText.size();
|
||||||
@@ -1386,7 +1383,9 @@ void CEpgData::hide()
|
|||||||
imdb_active = false;
|
imdb_active = false;
|
||||||
imdb->cleanup();
|
imdb->cleanup();
|
||||||
|
|
||||||
remove(TMDB_COVER);
|
// tmdb
|
||||||
|
tmdb_active = false;
|
||||||
|
tmdb->cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CEpgData::GetEPGData(const t_channel_id channel_id, uint64_t id, time_t* startzeit, bool clear )
|
void CEpgData::GetEPGData(const t_channel_id channel_id, uint64_t id, time_t* startzeit, bool clear )
|
||||||
|
@@ -36,6 +36,7 @@
|
|||||||
#include <system/settings.h>
|
#include <system/settings.h>
|
||||||
|
|
||||||
#include <gui/imdb.h>
|
#include <gui/imdb.h>
|
||||||
|
#include <gui/tmdb.h>
|
||||||
#include <driver/movieinfo.h>
|
#include <driver/movieinfo.h>
|
||||||
#include "widget/menue.h"
|
#include "widget/menue.h"
|
||||||
#include "widget/navibar.h"
|
#include "widget/navibar.h"
|
||||||
@@ -53,6 +54,7 @@ class CEpgData
|
|||||||
CChannelEventList followlist;
|
CChannelEventList followlist;
|
||||||
CEPGData epgData;
|
CEPGData epgData;
|
||||||
CIMDB *imdb;
|
CIMDB *imdb;
|
||||||
|
cTmdb *tmdb;
|
||||||
|
|
||||||
CComponentsHeader *header;
|
CComponentsHeader *header;
|
||||||
CNaviBar *Bottombox;
|
CNaviBar *Bottombox;
|
||||||
|
@@ -2068,7 +2068,8 @@ bool CMovieBrowser::onButtonPressMainFrame(neutrino_msg_t msg)
|
|||||||
extension = "." + extension;
|
extension = "." + extension;
|
||||||
str_replace(extension, ".jpg", cover_file);
|
str_replace(extension, ".jpg", cover_file);
|
||||||
printf("TMDB: %s : %s\n",m_movieSelectionHandler->file.Name.c_str(),cover_file.c_str());
|
printf("TMDB: %s : %s\n",m_movieSelectionHandler->file.Name.c_str(),cover_file.c_str());
|
||||||
cTmdb* tmdb = new cTmdb(m_movieSelectionHandler->epgTitle);
|
cTmdb* tmdb = cTmdb::getInstance();
|
||||||
|
tmdb->setTitle(m_movieSelectionHandler->epgTitle);
|
||||||
if ((tmdb->getResults() > 0) && (tmdb->hasCover())) {
|
if ((tmdb->getResults() > 0) && (tmdb->hasCover())) {
|
||||||
if (!cover_file.empty())
|
if (!cover_file.empty())
|
||||||
if (tmdb->getSmallCover(cover_file))
|
if (tmdb->getSmallCover(cover_file))
|
||||||
|
153
src/gui/tmdb.cpp
153
src/gui/tmdb.cpp
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (C) 2015 TangoCash
|
Copyright (C) 2015,2018 TangoCash
|
||||||
|
|
||||||
License: GPLv2
|
License: GPLv2
|
||||||
|
|
||||||
@@ -34,7 +34,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "system/settings.h"
|
#include "system/settings.h"
|
||||||
#include "system/helpers.h"
|
|
||||||
#include <system/helpers-json.h>
|
#include <system/helpers-json.h>
|
||||||
#include "system/set_threadname.h"
|
#include "system/set_threadname.h"
|
||||||
#include "gui/widget/hintbox.h"
|
#include "gui/widget/hintbox.h"
|
||||||
@@ -46,23 +45,32 @@
|
|||||||
|
|
||||||
#include "tmdb.h"
|
#include "tmdb.h"
|
||||||
|
|
||||||
#if LIBCURL_VERSION_NUM < 0x071507
|
cTmdb* cTmdb::getInstance()
|
||||||
#include <curl/types.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define URL_TIMEOUT 60
|
|
||||||
#define TMDB_COVER "/tmp/tmdb.jpg"
|
|
||||||
|
|
||||||
cTmdb::cTmdb(std::string epgtitle)
|
|
||||||
{
|
{
|
||||||
minfo.epgtitle = epgtitle;
|
static cTmdb* tmdb = NULL;
|
||||||
curl_handle = curl_easy_init();
|
if(!tmdb)
|
||||||
|
tmdb = new cTmdb();
|
||||||
|
return tmdb;
|
||||||
|
}
|
||||||
|
|
||||||
|
cTmdb::cTmdb()
|
||||||
|
{
|
||||||
#ifdef TMDB_API_KEY
|
#ifdef TMDB_API_KEY
|
||||||
key = TMDB_API_KEY;
|
key = TMDB_API_KEY;
|
||||||
#else
|
#else
|
||||||
key = g_settings.tmdb_api_key;
|
key = g_settings.tmdb_api_key;
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
cTmdb::~cTmdb()
|
||||||
|
{
|
||||||
|
cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
void cTmdb::setTitle(std::string epgtitle)
|
||||||
|
{
|
||||||
|
memset(&minfo, 0, sizeof(minfo));
|
||||||
|
minfo.epgtitle = epgtitle;
|
||||||
|
|
||||||
CHintBox hintbox(LOCALE_MESSAGEBOX_INFO, g_Locale->getText(LOCALE_TMDB_READ_DATA));
|
CHintBox hintbox(LOCALE_MESSAGEBOX_INFO, g_Locale->getText(LOCALE_TMDB_READ_DATA));
|
||||||
hintbox.paint();
|
hintbox.paint();
|
||||||
@@ -75,121 +83,6 @@ cTmdb::cTmdb(std::string epgtitle)
|
|||||||
hintbox.hide();
|
hintbox.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
cTmdb::~cTmdb()
|
|
||||||
{
|
|
||||||
curl_easy_cleanup(curl_handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t cTmdb::CurlWriteToString(void *ptr, size_t size, size_t nmemb, void *data)
|
|
||||||
{
|
|
||||||
if (size * nmemb > 0) {
|
|
||||||
std::string* pStr = (std::string*) data;
|
|
||||||
pStr->append((char*) ptr, nmemb);
|
|
||||||
}
|
|
||||||
return size*nmemb;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string cTmdb::decodeUrl(std::string url)
|
|
||||||
{
|
|
||||||
char * str = curl_easy_unescape(curl_handle, url.c_str(), 0, NULL);
|
|
||||||
if (str)
|
|
||||||
url = str;
|
|
||||||
curl_free(str);
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string cTmdb::encodeUrl(std::string txt)
|
|
||||||
{
|
|
||||||
char * str = curl_easy_escape(curl_handle, txt.c_str(), txt.length());
|
|
||||||
if (str)
|
|
||||||
txt = str;
|
|
||||||
curl_free(str);
|
|
||||||
return txt;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool cTmdb::getUrl(std::string &url, std::string &answer, CURL *_curl_handle)
|
|
||||||
{
|
|
||||||
printf("[TMDB]: %s\n",__func__);
|
|
||||||
if (!_curl_handle)
|
|
||||||
_curl_handle = curl_handle;
|
|
||||||
|
|
||||||
curl_easy_setopt(_curl_handle, CURLOPT_URL, url.c_str());
|
|
||||||
curl_easy_setopt(_curl_handle, CURLOPT_WRITEFUNCTION, &cTmdb::CurlWriteToString);
|
|
||||||
curl_easy_setopt(_curl_handle, CURLOPT_FILE, (void *)&answer);
|
|
||||||
curl_easy_setopt(_curl_handle, CURLOPT_FAILONERROR, 1);
|
|
||||||
curl_easy_setopt(_curl_handle, CURLOPT_TIMEOUT, URL_TIMEOUT);
|
|
||||||
curl_easy_setopt(_curl_handle, CURLOPT_NOSIGNAL, (long)1);
|
|
||||||
curl_easy_setopt(_curl_handle, CURLOPT_SSL_VERIFYPEER, false);
|
|
||||||
|
|
||||||
if (!g_settings.softupdate_proxyserver.empty()) {
|
|
||||||
curl_easy_setopt(_curl_handle, CURLOPT_PROXY, g_settings.softupdate_proxyserver.c_str());
|
|
||||||
if (!g_settings.softupdate_proxyusername.empty()) {
|
|
||||||
std::string tmp = g_settings.softupdate_proxyusername + ":" + g_settings.softupdate_proxypassword;
|
|
||||||
curl_easy_setopt(_curl_handle, CURLOPT_PROXYUSERPWD, tmp.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
char cerror[CURL_ERROR_SIZE] = {0};
|
|
||||||
curl_easy_setopt(_curl_handle, CURLOPT_ERRORBUFFER, cerror);
|
|
||||||
|
|
||||||
printf("try to get [%s] ...\n", url.c_str());
|
|
||||||
CURLcode httpres = curl_easy_perform(_curl_handle);
|
|
||||||
|
|
||||||
printf("http: res %d size %d\n", httpres, (int)answer.size());
|
|
||||||
|
|
||||||
if (httpres != 0 || answer.empty()) {
|
|
||||||
printf("error: %s\n", cerror);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool cTmdb::DownloadUrl(std::string url, std::string file, CURL *_curl_handle)
|
|
||||||
{
|
|
||||||
if (!_curl_handle)
|
|
||||||
_curl_handle = curl_handle;
|
|
||||||
|
|
||||||
FILE * fp = fopen(file.c_str(), "wb");
|
|
||||||
if (fp == NULL) {
|
|
||||||
perror(file.c_str());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
curl_easy_setopt(_curl_handle, CURLOPT_URL, url.c_str());
|
|
||||||
curl_easy_setopt(_curl_handle, CURLOPT_WRITEFUNCTION, NULL);
|
|
||||||
curl_easy_setopt(_curl_handle, CURLOPT_FILE, fp);
|
|
||||||
curl_easy_setopt(_curl_handle, CURLOPT_FAILONERROR, 1);
|
|
||||||
curl_easy_setopt(_curl_handle, CURLOPT_TIMEOUT, URL_TIMEOUT);
|
|
||||||
curl_easy_setopt(_curl_handle, CURLOPT_NOSIGNAL, (long)1);
|
|
||||||
curl_easy_setopt(_curl_handle, CURLOPT_SSL_VERIFYPEER, false);
|
|
||||||
|
|
||||||
if (!g_settings.softupdate_proxyserver.empty()) {
|
|
||||||
curl_easy_setopt(_curl_handle, CURLOPT_PROXY, g_settings.softupdate_proxyserver.c_str());
|
|
||||||
if (!g_settings.softupdate_proxyusername.empty()) {
|
|
||||||
std::string tmp = g_settings.softupdate_proxyusername + ":" + g_settings.softupdate_proxypassword;
|
|
||||||
curl_easy_setopt(_curl_handle, CURLOPT_PROXYUSERPWD, tmp.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
char cerror[CURL_ERROR_SIZE] = {0};
|
|
||||||
curl_easy_setopt(_curl_handle, CURLOPT_ERRORBUFFER, cerror);
|
|
||||||
|
|
||||||
printf("try to get [%s] ...\n", url.c_str());
|
|
||||||
CURLcode httpres = curl_easy_perform(_curl_handle);
|
|
||||||
|
|
||||||
double dsize;
|
|
||||||
curl_easy_getinfo(_curl_handle, CURLINFO_SIZE_DOWNLOAD, &dsize);
|
|
||||||
fclose(fp);
|
|
||||||
|
|
||||||
printf("http: res %d size %g.\n", httpres, dsize);
|
|
||||||
|
|
||||||
if (httpres != 0) {
|
|
||||||
printf("curl error: %s\n", cerror);
|
|
||||||
unlink(file.c_str());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool cTmdb::GetMovieDetails(std::string lang)
|
bool cTmdb::GetMovieDetails(std::string lang)
|
||||||
{
|
{
|
||||||
printf("[TMDB]: %s\n",__func__);
|
printf("[TMDB]: %s\n",__func__);
|
||||||
@@ -292,3 +185,9 @@ std::string cTmdb::CreateEPGText()
|
|||||||
epgtext += (std::string)g_Locale->getText(LOCALE_EPGEXTENDED_ACTORS)+":\n"+ minfo.cast+"\n";
|
epgtext += (std::string)g_Locale->getText(LOCALE_EPGEXTENDED_ACTORS)+":\n"+ minfo.cast+"\n";
|
||||||
return epgtext;
|
return epgtext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cTmdb::cleanup()
|
||||||
|
{
|
||||||
|
if (access(TMDB_COVER, F_OK) == 0)
|
||||||
|
unlink(TMDB_COVER);
|
||||||
|
}
|
@@ -20,10 +20,10 @@
|
|||||||
#ifndef __TMDB__
|
#ifndef __TMDB__
|
||||||
#define __TMDB__
|
#define __TMDB__
|
||||||
|
|
||||||
#include <curl/curl.h>
|
|
||||||
#include <curl/easy.h>
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "system/helpers.h"
|
||||||
|
|
||||||
|
#define TMDB_COVER "/tmp/tmdb.jpg"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
std::string epgtitle;
|
std::string epgtitle;
|
||||||
@@ -47,20 +47,16 @@ typedef struct {
|
|||||||
class cTmdb
|
class cTmdb
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
CURL *curl_handle;
|
|
||||||
tmdbinfo minfo;
|
tmdbinfo minfo;
|
||||||
|
|
||||||
static size_t CurlWriteToString(void *ptr, size_t size, size_t nmemb, void *data);
|
|
||||||
std::string encodeUrl(std::string txt);
|
|
||||||
std::string decodeUrl(std::string url);
|
|
||||||
std::string key; // tmdb api key
|
std::string key; // tmdb api key
|
||||||
bool getUrl(std::string &url, std::string &answer, CURL *_curl_handle = NULL);
|
|
||||||
bool DownloadUrl(std::string url, std::string file, CURL *_curl_handle = NULL);
|
|
||||||
bool GetMovieDetails(std::string lang);
|
bool GetMovieDetails(std::string lang);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
cTmdb(std::string epgtitle);
|
cTmdb();
|
||||||
~cTmdb();
|
~cTmdb();
|
||||||
|
static cTmdb* getInstance();
|
||||||
|
void setTitle(std::string epgtitle);
|
||||||
std::string CreateEPGText();
|
std::string CreateEPGText();
|
||||||
|
|
||||||
std::string getTitle() { return minfo.epgtitle;}
|
std::string getTitle() { return minfo.epgtitle;}
|
||||||
@@ -69,11 +65,13 @@ class cTmdb
|
|||||||
std::string getDescription() { return minfo.overview;}
|
std::string getDescription() { return minfo.overview;}
|
||||||
std::string getVote() { return minfo.vote_average;}
|
std::string getVote() { return minfo.vote_average;}
|
||||||
std::string getCast() { return minfo.cast;}
|
std::string getCast() { return minfo.cast;}
|
||||||
|
std::string getCover() { return TMDB_COVER;}
|
||||||
bool hasCover() { return !minfo.poster_path.empty();}
|
bool hasCover() { return !minfo.poster_path.empty();}
|
||||||
bool getBigCover(std::string cover) { return DownloadUrl("http://image.tmdb.org/t/p/w342" + minfo.poster_path, cover);}
|
bool getBigCover(std::string cover) { return downloadUrl("http://image.tmdb.org/t/p/w342" + minfo.poster_path, cover);}
|
||||||
bool getSmallCover(std::string cover) { return DownloadUrl("http://image.tmdb.org/t/p/w185" + minfo.poster_path, cover);}
|
bool getSmallCover(std::string cover) { return downloadUrl("http://image.tmdb.org/t/p/w185" + minfo.poster_path, cover);}
|
||||||
int getResults() { return minfo.result;}
|
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())+0.5);}
|
||||||
|
void cleanup();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user