Merge branch 'master' into pu/mp

This commit is contained in:
M. Liebmann
2017-09-19 23:21:21 +02:00
8 changed files with 122 additions and 34 deletions

View File

@@ -60,6 +60,7 @@
#include <driver/fontrenderer.h> #include <driver/fontrenderer.h>
#include <eitd/edvbstring.h> #include <eitd/edvbstring.h>
#include <system/helpers.h> #include <system/helpers.h>
#include <system/helpers-json.h>
#include <src/mymenu.h> #include <src/mymenu.h>
@@ -842,12 +843,12 @@ bool CMoviePlayerGui::luaGetUrl(const std::string &script, const std::string &fi
return false; return false;
} }
string errMsg = "";
Json::Value root; Json::Value root;
Json::Reader reader; bool ok = parseJsonFromString(result_string, &root, &errMsg);
bool parsedSuccess = reader.parse(result_string, root, false); if (!ok) {
if (!parsedSuccess) {
printf("Failed to parse JSON\n"); printf("Failed to parse JSON\n");
printf("%s\n", reader.getFormattedErrorMessages().c_str()); printf("%s\n", errMsg.c_str());
if (box != NULL) { if (box != NULL) {
box->hide(); box->hide();
delete box; delete box;

View File

@@ -69,6 +69,7 @@
#include <system/settings.h> #include <system/settings.h>
#include <system/fsmounter.h> #include <system/fsmounter.h>
#include <system/helpers.h> #include <system/helpers.h>
#include <system/helpers-json.h>
#include <system/httptool.h> #include <system/httptool.h>
#include <json/json.h> #include <json/json.h>
@@ -739,16 +740,15 @@ bool CTimerList::RemoteBoxChanExists(t_channel_id channel_id)
r_url += string_printf_helper(PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS, channel_id); r_url += string_printf_helper(PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS, channel_id);
r_url = httpTool.downloadString(r_url, -1, httpConnectTimeout); r_url = httpTool.downloadString(r_url, -1, httpConnectTimeout);
string errMsg = "";
Json::Value root; Json::Value root;
Json::Reader reader; bool ok = parseJsonFromString(r_url, &root, &errMsg);
bool parsedSuccess = reader.parse(r_url, root, false); if (!ok) {
if (!parsedSuccess) {
printf("Failed to parse JSON\n"); printf("Failed to parse JSON\n");
printf("%s\n", reader.getFormattedErrorMessages().c_str()); printf("%s\n", errMsg.c_str());
} }
r_url = root.get("success","false").asString(); r_url = root.get("success","false").asString();
if (r_url == "false") if (r_url == "false")
ShowMsg(LOCALE_REMOTEBOX_CHANNEL_NA, convertChannelId2String(channel_id), ShowMsg(LOCALE_REMOTEBOX_CHANNEL_NA, convertChannelId2String(channel_id),
CMsgBox::mbrOk, CMsgBox::mbOk, NULL, 450, 30, false); CMsgBox::mbrOk, CMsgBox::mbOk, NULL, 450, 30, false);
@@ -797,13 +797,12 @@ void CTimerList::RemoteBoxTimerList(CTimerd::TimerList &rtimerlist)
r_url = httpTool.downloadString(r_url, -1, httpConnectTimeout); r_url = httpTool.downloadString(r_url, -1, httpConnectTimeout);
//printf("[remotetimer] timers:%s\n",r_url.c_str()); //printf("[remotetimer] timers:%s\n",r_url.c_str());
string errMsg = "";
Json::Value root; Json::Value root;
Json::Reader reader; bool ok = parseJsonFromString(r_url, &root, &errMsg);
bool parsedSuccess = reader.parse(r_url, root, false); if (!ok) {
if (!parsedSuccess)
{
printf("Failed to parse JSON\n"); printf("Failed to parse JSON\n");
printf("%s\n", reader.getFormattedErrorMessages().c_str()); printf("%s\n", errMsg.c_str());
it->online = false; it->online = false;
} else } else
it->online = true; it->online = true;
@@ -1287,13 +1286,12 @@ void CTimerList::paintItem(int pos)
r_url += string_printf_helper(PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS, timer.channel_id); r_url += string_printf_helper(PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS, timer.channel_id);
r_url = httpTool.downloadString(r_url, -1, httpConnectTimeout); r_url = httpTool.downloadString(r_url, -1, httpConnectTimeout);
string errMsg = "";
Json::Value root; Json::Value root;
Json::Reader reader; bool ok = parseJsonFromString(r_url, &root, &errMsg);
bool parsedSuccess = reader.parse(r_url, root, false); if (!ok) {
if (!parsedSuccess)
{
printf("Failed to parse JSON\n"); printf("Failed to parse JSON\n");
printf("%s\n", reader.getFormattedErrorMessages().c_str()); printf("%s\n", errMsg.c_str());
} }
Json::Value remotechannel = root["data"]["channel"][0]; Json::Value remotechannel = root["data"]["channel"][0];

View File

@@ -35,6 +35,7 @@
#include "system/settings.h" #include "system/settings.h"
#include "system/helpers.h" #include "system/helpers.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"
@@ -197,12 +198,12 @@ bool cTmdb::GetMovieDetails(std::string lang)
if (!getUrl(url, answer)) if (!getUrl(url, answer))
return false; return false;
string errMsg = "";
Json::Value root; Json::Value root;
Json::Reader reader; bool ok = parseJsonFromString(answer, &root, &errMsg);
bool parsedSuccess = reader.parse(answer, root, false); if (!ok) {
if (!parsedSuccess) {
printf("Failed to parse JSON\n"); printf("Failed to parse JSON\n");
printf("%s\n", reader.getFormattedErrorMessages().c_str()); printf("%s\n", errMsg.c_str());
return false; return false;
} }
@@ -219,10 +220,11 @@ bool cTmdb::GetMovieDetails(std::string lang)
answer.clear(); answer.clear();
if (!getUrl(url, answer)) if (!getUrl(url, answer))
return false; return false;
parsedSuccess = reader.parse(answer, root, false);
if (!parsedSuccess) { ok = parseJsonFromString(answer, &root, &errMsg);
if (!ok) {
printf("Failed to parse JSON\n"); printf("Failed to parse JSON\n");
printf("%s\n", reader.getFormattedErrorMessages().c_str()); printf("%s\n", errMsg.c_str());
return false; return false;
} }

View File

@@ -68,7 +68,7 @@ int CKeyChooserItem::exec(CMenuTarget* parent, const std::string &)
int timeout = 10; int timeout = 10;
CHintBox hintbox(name, LOCALE_KEYCHOOSER_TEXT, HINTBOX_MIN_WIDTH, NEUTRINO_ICON_SETTINGS, NEUTRINO_ICON_HINT_KEYS); CHintBox hintbox(name, LOCALE_KEYCHOOSER_TEXT, HINTBOX_MIN_WIDTH, NEUTRINO_ICON_SETTINGS, NEUTRINO_ICON_HINT_KEYS);
//hintbox.setTimeOut(timeout); hintbox.setTimeOut(timeout);
hintbox.paint(); hintbox.paint();
CFrameBuffer::getInstance()->blit(); CFrameBuffer::getInstance()->blit();
@@ -79,6 +79,7 @@ int CKeyChooserItem::exec(CMenuTarget* parent, const std::string &)
timeoutEnd = CRCInput::calcTimeoutEnd(timeout); timeoutEnd = CRCInput::calcTimeoutEnd(timeout);
get_Message: get_Message:
hintbox.enableTimeOutBar();
g_RCInput->getMsgAbsoluteTimeout( &msg, &data, &timeoutEnd ); g_RCInput->getMsgAbsoluteTimeout( &msg, &data, &timeoutEnd );
if (msg != CRCInput::RC_timeout) if (msg != CRCInput::RC_timeout)
@@ -92,6 +93,7 @@ int CKeyChooserItem::exec(CMenuTarget* parent, const std::string &)
} }
g_RCInput->setLongPressAny(false); g_RCInput->setLongPressAny(false);
hintbox.disableTimeOutBar();
hintbox.hide(); hintbox.hide();
return res; return res;
} }

31
src/system/helpers-json.h Normal file
View File

@@ -0,0 +1,31 @@
#ifndef __system_helpers_json__
#define __system_helpers_json__
/*
Neutrino-HD
License: GPL
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <json/json.h>
using namespace std;
bool parseJsonFromFile(string& jFile, Json::Value *root, string *errMsg);
bool parseJsonFromString(string& jData, Json::Value *root, string *errMsg);
#endif

View File

@@ -44,6 +44,7 @@
#include <stdarg.h> #include <stdarg.h>
#include <algorithm> #include <algorithm>
#include <mntent.h> #include <mntent.h>
#include <fstream>
#include <linux/hdreg.h> #include <linux/hdreg.h>
#include <linux/fs.h> #include <linux/fs.h>
#include "debug.h" #include "debug.h"
@@ -51,6 +52,7 @@
#include <driver/fontrenderer.h> #include <driver/fontrenderer.h>
//#include <driver/framebuffer.h> //#include <driver/framebuffer.h>
#include <system/helpers.h> #include <system/helpers.h>
#include <system/helpers-json.h>
#include <gui/update_ext.h> #include <gui/update_ext.h>
#include <libmd5sum.h> #include <libmd5sum.h>
#define MD5_DIGEST_LENGTH 16 #define MD5_DIGEST_LENGTH 16
@@ -1406,3 +1408,51 @@ string readLink(string lnk)
return ""; return "";
} }
string readFile(string file)
{
string ret_s;
ifstream tmpData(file.c_str(), ifstream::binary);
if (tmpData.is_open()) {
tmpData.seekg(0, tmpData.end);
int length = tmpData.tellg();
tmpData.seekg(0, tmpData.beg);
char* buffer = new char[length+1];
tmpData.read(buffer, length);
tmpData.close();
buffer[length] = '\0';
ret_s = (string)buffer;
delete [] buffer;
}
else {
cerr << "Error read " << file << endl;
return "";
}
return ret_s;
}
bool parseJsonFromFile(string& jFile, Json::Value *root, string *errMsg)
{
string jData = readFile(jFile);
bool ret = parseJsonFromString(jData, root, errMsg);
jData.clear();
return ret;
}
bool parseJsonFromString(string& jData, Json::Value *root, string *errMsg)
{
Json::CharReaderBuilder builder;
Json::CharReader* reader(builder.newCharReader());
JSONCPP_STRING errs = "";
const char* jData_c = jData.c_str();
bool ret = reader->parse(jData_c, jData_c + strlen(jData_c), root, &errs);
if (!ret || (!errs.empty())) {
ret = false;
if (errMsg != NULL)
*errMsg = errs;
}
delete reader;
return ret;
}

View File

@@ -151,4 +151,6 @@ std::string filehash(const char * file);
std::string get_path(const char * path); std::string get_path(const char * path);
inline bool file_exists(const std::string file) { return file_exists(file.c_str()); } inline bool file_exists(const std::string file) { return file_exists(file.c_str()); }
std::string readFile(std::string file);
#endif #endif

View File

@@ -38,6 +38,7 @@
#include <OpenThreads/ScopedLock> #include <OpenThreads/ScopedLock>
#include "settings.h" #include "settings.h"
#include "helpers.h" #include "helpers.h"
#include "helpers-json.h"
#include "set_threadname.h" #include "set_threadname.h"
#include <global.h> #include <global.h>
#include <json/json.h> #include <json/json.h>
@@ -288,25 +289,25 @@ std::string cYTFeedParser::getXmlData(xmlNodePtr node)
bool cYTFeedParser::parseFeedJSON(std::string &answer) bool cYTFeedParser::parseFeedJSON(std::string &answer)
{ {
string errMsg = "";
Json::Value root; Json::Value root;
Json::Reader reader;
std::ostringstream ss; std::ostringstream ss;
std::ifstream fh(curfeedfile.c_str(),std::ifstream::in); std::ifstream fh(curfeedfile.c_str(),std::ifstream::in);
ss << fh.rdbuf(); ss << fh.rdbuf();
std::string filedata = ss.str(); std::string filedata = ss.str();
bool parsedSuccess = reader.parse(filedata,root,false); bool parsedSuccess = parseJsonFromString(filedata, &root, NULL);
if(!parsedSuccess) if(!parsedSuccess)
{ {
parsedSuccess = reader.parse(answer,root,false); parsedSuccess = parseJsonFromString(answer, &root, &errMsg);
} }
if(!parsedSuccess) if(!parsedSuccess)
{ {
printf("Failed to parse JSON\n"); printf("Failed to parse JSON\n");
printf("%s\n", reader.getFormattedErrorMessages().c_str()); printf("%s\n", errMsg.c_str());
return false; return false;
} }
@@ -383,15 +384,16 @@ bool cYTFeedParser::parseFeedDetailsJSON(cYTVideoInfo* vinfo)
if (!getUrl(url, answer)) if (!getUrl(url, answer))
return false; return false;
string errMsg = "";
Json::Value root; Json::Value root;
Json::Reader reader; bool parsedSuccess = parseJsonFromString(answer, &root, &errMsg);
bool parsedSuccess = reader.parse(answer, root, false);
if (!parsedSuccess) { if (!parsedSuccess) {
printf("Failed to parse JSON\n"); printf("Failed to parse JSON\n");
printf("%s\n", reader.getFormattedErrorMessages().c_str()); printf("%s\n", errMsg.c_str());
return false; return false;
} }
Json::Value elements = root["items"]; Json::Value elements = root["items"];
std::string duration = elements[0]["contentDetails"].get("duration", "").asString(); std::string duration = elements[0]["contentDetails"].get("duration", "").asString();
if (duration.find("PT") != std::string::npos) { if (duration.find("PT") != std::string::npos) {