diff --git a/src/Makefile.am b/src/Makefile.am index 94817b2ed..ef5b8fc73 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -104,6 +104,7 @@ neutrino_LDADD = \ $(top_builddir)/lib/connection/libtuxbox-connection.a \ $(top_builddir)/lib/libeventserver/libtuxbox-eventserver.a \ $(top_builddir)/lib/xmltree/libtuxbox-xmltree.a \ + $(top_builddir)/lib/jsoncpp/libjsoncpp.a \ $(top_builddir)/lib/libnet/libtuxbox-net.a \ $(top_builddir)/lib/libmd5sum/libtuxbox-md5sum.a \ $(top_builddir)/lib/libtuxtxt/libtuxtxt.a \ diff --git a/src/neutrino.cpp b/src/neutrino.cpp index 2d66d6758..eb1554bb1 100644 --- a/src/neutrino.cpp +++ b/src/neutrino.cpp @@ -795,6 +795,7 @@ int CNeutrinoApp::loadSetup(const char * fname) //Movie-Player g_settings.movieplayer_repeat_on = configfile.getInt32("movieplayer_repeat_on", CMoviePlayerGui::REPEAT_OFF); + g_settings.youtube_dev_id = configfile.getString("youtube_dev_id","XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); //Filebrowser g_settings.filebrowser_showrights = configfile.getInt32("filebrowser_showrights", 1); @@ -1255,6 +1256,7 @@ void CNeutrinoApp::saveSetup(const char * fname) //Movie-Player configfile.setInt32( "movieplayer_repeat_on", g_settings.movieplayer_repeat_on ); + configfile.setString( "youtube_dev_id", g_settings.youtube_dev_id ); //Filebrowser configfile.setInt32("filebrowser_showrights", g_settings.filebrowser_showrights); diff --git a/src/system/Makefile.am b/src/system/Makefile.am index 475039742..ac7c5da18 100644 --- a/src/system/Makefile.am +++ b/src/system/Makefile.am @@ -16,6 +16,7 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/lib/libconfigfile \ -I$(top_srcdir)/lib/libmd5sum \ -I$(top_srcdir)/lib/xmltree \ + -I$(top_srcdir)/lib/jsoncpp/include \ @SIGC_CFLAGS@ \ @FREETYPE_CFLAGS@ diff --git a/src/system/settings.h b/src/system/settings.h index 85b6b3666..8a1a8e697 100644 --- a/src/system/settings.h +++ b/src/system/settings.h @@ -682,6 +682,7 @@ struct SNeutrinoSettings //movieplayer int movieplayer_repeat_on; + std::string youtube_dev_id; //zapit setup std::string StartChannelTV; diff --git a/src/system/ytparser.cpp b/src/system/ytparser.cpp index dfa3fef59..d31e31608 100644 --- a/src/system/ytparser.cpp +++ b/src/system/ytparser.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -39,6 +40,7 @@ #include "helpers.h" #include "set_threadname.h" #include +#include #include "ytparser.h" #include "ytcache.h" @@ -50,6 +52,7 @@ #define URL_TIMEOUT 60 static int itags[] = { 37 /* 1080p MP4 */, 22 /* 720p MP4 */, 18 /* 270p/360p MP4 */, 0 }; + std::string cYTVideoUrl::GetUrl() { std::string fullurl = url; @@ -133,6 +136,7 @@ bool cYTFeedParser::getUrl(std::string &url, std::string &answer, CURL *_curl_ha 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()); @@ -173,6 +177,7 @@ bool cYTFeedParser::DownloadUrl(std::string &url, std::string &file, CURL *_curl 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()); @@ -276,134 +281,79 @@ std::string cYTFeedParser::getXmlData(xmlNodePtr node) return result; } -bool cYTFeedParser::parseFeedXml(std::string &answer) +bool cYTFeedParser::parseFeedJSON(std::string &answer) { - xmlDocPtr answer_parser = parseXmlFile(curfeedfile.c_str()); - if (answer_parser == NULL) - answer_parser = parseXml(answer.c_str()); + Json::Value root; + Json::Reader reader; - if (answer_parser == NULL) { - printf("failed to parse xml\n"); + std::ostringstream ss; + std::ifstream fh(curfeedfile.c_str(),std::ifstream::in); + ss << fh.rdbuf(); + std::string filedata = ss.str(); + + bool parsedSuccess = reader.parse(filedata,root,false); + + if(!parsedSuccess) + { + parsedSuccess = reader.parse(answer,root,false); + } + + if(!parsedSuccess) + { + printf("Failed to parse JSON\n"); + printf("%s\n", reader.getFormattedErrorMessages().c_str()); return false; } + next.clear(); prev.clear(); + //TODO total.clear(); start.clear(); - xmlNodePtr entry = xmlDocGetRootElement(answer_parser); - entry = xmlChildrenNode(entry); - while (entry) { - std::string name = getXmlName(entry); -#ifdef DEBUG_PARSER - printf("entry: %s\n", name.c_str()); -#endif - if (name == "openSearch:startIndex") { - start = getXmlData(entry); - printf("start %s\n", start.c_str()); - } else if (name == "openSearch:totalResults") { - total = getXmlData(entry); - printf("total %s\n", total.c_str()); - } - else if (name == "link") { - std::string link = getXmlAttr(entry, "rel"); - if (link == "next") { - next = getXmlAttr(entry, "href"); - printf(" next [%s]\n", next.c_str()); - } else if (link == "previous") { - prev = getXmlAttr(entry, "href"); - printf(" prev [%s]\n", prev.c_str()); - } - } - else if (name != "entry") { - entry = xmlNextNode(entry); - continue; - } - xmlNodePtr node = xmlChildrenNode(entry); - cYTVideoInfo vinfo; - std::string thumbnail; - while (node) { - name = getXmlName(node); -#ifdef DEBUG_PARSER - printf(" node: %s\n", name.c_str()); -#endif - if (name == "title") { -#ifdef DEBUG_PARSER - printf(" title [%s]\n", getXmlData(node).c_str()); -#endif - vinfo.title = getXmlData(node); - } - else if (name == "published") { - vinfo.published = getXmlData(node).substr(0, 10); - } - else if (name == "author") { - xmlNodePtr author = xmlChildrenNode(node); - while(author) { - name = getXmlName(author); - if (name == "name") { -#ifdef DEBUG_PARSER - printf(" author [%s]\n", getXmlData(author).c_str()); -#endif - vinfo.author = getXmlData(author); - } - author = xmlNextNode(author); - } - } - else if (name == "media:group") { - xmlNodePtr media = xmlChildrenNode(node); - while (media) { - name = getXmlName(media); - if (name == "media:description") { - vinfo.description = getXmlData(media).c_str(); - } - else if (name == "media:category") { - if (vinfo.category.size() < 3) - vinfo.category = getXmlData(media).c_str(); - } - else if (name == "yt:videoid") { -#ifdef DEBUG_PARSER - printf(" id [%s]\n", getXmlData(media).c_str()); -#endif - vinfo.id = getXmlData(media).c_str(); - } - else if (name == "media:thumbnail") { - /* save first found */ - if (thumbnail.empty()) - thumbnail = getXmlAttr(media, "url"); - /* check wanted quality */ - if (tquality == getXmlAttr(media, "yt:name")) { - vinfo.thumbnail = getXmlAttr(media, "url"); + next = root.get("nextPageToken", "").asString(); + prev = root.get("prevPageToken", "").asString(); + + cYTVideoInfo vinfo; + Json::Value elements = root["items"]; + for(unsigned int i=0; i