mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-08-29 16:31:05 +02:00
ytparser: re-use exiting curl connection for bulk transfers
Origin commit data
------------------
Branch: ni/coolstream
Commit: 0e6848d7d9
Author: martii <m4rtii@gmx.de>
Date: 2013-06-09 (Sun, 09 Jun 2013)
------------------
No further description and justification available within origin commit message!
------------------
This commit was generated by Migit
This commit is contained in:
@@ -96,9 +96,9 @@ size_t cYTFeedParser::CurlWriteToString(void *ptr, size_t size, size_t nmemb, vo
|
||||
return size*nmemb;
|
||||
}
|
||||
|
||||
bool cYTFeedParser::getUrl(std::string &url, std::string &answer)
|
||||
bool cYTFeedParser::getUrl(std::string &url, std::string &answer, CURL *_curl_handle)
|
||||
{
|
||||
CURL * curl_handle = curl_easy_init();
|
||||
CURL * curl_handle = _curl_handle ? _curl_handle : curl_easy_init();
|
||||
curl_easy_setopt(curl_handle, CURLOPT_URL, url.c_str());
|
||||
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, &cYTFeedParser::CurlWriteToString);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_FILE, (void *)&answer);
|
||||
@@ -112,6 +112,7 @@ bool cYTFeedParser::getUrl(std::string &url, std::string &answer)
|
||||
printf("try to get [%s] ...\n", url.c_str());
|
||||
CURLcode httpres = curl_easy_perform(curl_handle);
|
||||
|
||||
if (!_curl_handle)
|
||||
curl_easy_cleanup(curl_handle);
|
||||
|
||||
printf("http: res %d size %d\n", httpres, answer.size());
|
||||
@@ -123,14 +124,14 @@ bool cYTFeedParser::getUrl(std::string &url, std::string &answer)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cYTFeedParser::DownloadUrl(std::string &url, std::string &file)
|
||||
bool cYTFeedParser::DownloadUrl(std::string &url, std::string &file, CURL *_curl_handle)
|
||||
{
|
||||
FILE * fp = fopen(file.c_str(), "wb");
|
||||
if (fp == NULL) {
|
||||
perror(file.c_str());
|
||||
return false;
|
||||
}
|
||||
CURL * curl_handle = curl_easy_init();
|
||||
CURL * curl_handle = _curl_handle ? _curl_handle : curl_easy_init();
|
||||
curl_easy_setopt(curl_handle, CURLOPT_URL, url.c_str());
|
||||
curl_easy_setopt(curl_handle, CURLOPT_FILE, fp);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_FAILONERROR, 1);
|
||||
@@ -145,6 +146,7 @@ bool cYTFeedParser::DownloadUrl(std::string &url, std::string &file)
|
||||
|
||||
double dsize;
|
||||
curl_easy_getinfo(curl_handle, CURLINFO_SIZE_DOWNLOAD, &dsize);
|
||||
if (!_curl_handle)
|
||||
curl_easy_cleanup(curl_handle);
|
||||
fclose(fp);
|
||||
|
||||
@@ -537,6 +539,7 @@ bool cYTFeedParser::ParseVideoInfo(cYTVideoInfo &vinfo)
|
||||
estr.push_back("&el=vevo");
|
||||
estr.push_back("&el=detailpage");
|
||||
|
||||
CURL *curl_handle = curl_easy_init();
|
||||
for (unsigned i = 0; i < estr.size(); i++) {
|
||||
std::string vurl = "http://www.youtube.com/get_video_info?video_id=";
|
||||
vurl += vinfo.id;
|
||||
@@ -544,12 +547,13 @@ bool cYTFeedParser::ParseVideoInfo(cYTVideoInfo &vinfo)
|
||||
vurl += "&ps=default&eurl=&gl=US&hl=en";
|
||||
printf("cYTFeedParser::ParseVideoInfo: get [%s]\n", vurl.c_str());
|
||||
std::string answer;
|
||||
if (!getUrl(vurl, answer))
|
||||
if (!getUrl(vurl, answer, curl_handle))
|
||||
continue;
|
||||
ret = decodeVideoInfo(answer, vinfo);
|
||||
if (ret)
|
||||
break;
|
||||
}
|
||||
curl_easy_cleanup(curl_handle);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -560,6 +564,7 @@ bool cYTFeedParser::DownloadThumbnails()
|
||||
perror(thumbnail_dir.c_str());
|
||||
//return ret;
|
||||
}
|
||||
CURL *curl_handle = curl_easy_init();
|
||||
for (unsigned i = 0; i < videos.size(); i++) {
|
||||
if (!videos[i].thumbnail.empty()) {
|
||||
std::string fname = thumbnail_dir;
|
||||
@@ -568,12 +573,13 @@ bool cYTFeedParser::DownloadThumbnails()
|
||||
fname += ".jpg";
|
||||
bool found = !access(fname.c_str(), F_OK);
|
||||
if (!found)
|
||||
found = DownloadUrl(videos[i].thumbnail, fname);
|
||||
found = DownloadUrl(videos[i].thumbnail, fname, curl_handle);
|
||||
if (found)
|
||||
videos[i].tfile = fname;
|
||||
ret |= found;
|
||||
}
|
||||
}
|
||||
curl_easy_cleanup(curl_handle);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@@ -93,8 +93,8 @@ class cYTFeedParser
|
||||
static void splitString(std::string &str, std::string delim, std::vector<std::string> &strlist, int start = 0);
|
||||
static void splitString(std::string &str, std::string delim, std::map<std::string,std::string> &strmap, int start = 0);
|
||||
static bool saveToFile(const char * name, std::string str);
|
||||
bool getUrl(std::string &url, std::string &answer);
|
||||
bool DownloadUrl(std::string &url, std::string &file);
|
||||
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 parseFeedXml(std::string &answer);
|
||||
bool decodeVideoInfo(std::string &answer, cYTVideoInfo &vinfo);
|
||||
bool supportedFormat(int fmt);
|
||||
|
Reference in New Issue
Block a user