diff options
author | horchi <vdr@jwendel.de> | 2017-03-16 19:03:57 +0100 |
---|---|---|
committer | horchi <vdr@jwendel.de> | 2017-03-16 19:03:57 +0100 |
commit | 62627661d3fc79cdf0a38fc4708a1e88c7285e7a (patch) | |
tree | 36ecb8bda35d998f7d23ee13e87720b9dcb109be /lib | |
parent | 21057136ae42ea59022d87f3e5d83c55c4cca074 (diff) | |
download | vdr-epg-daemon-62627661d3fc79cdf0a38fc4708a1e88c7285e7a.tar.gz vdr-epg-daemon-62627661d3fc79cdf0a38fc4708a1e88c7285e7a.tar.bz2 |
2017-03-16: version 1.1.108 (horchi)\n - change: Improved error message on failed downloads\n - added: sleep 1 second every 50 scraper downloads due to server limit\n\n
Diffstat (limited to 'lib')
-rw-r--r-- | lib/curl.c | 95 |
1 files changed, 56 insertions, 39 deletions
@@ -137,58 +137,70 @@ int cCurl::exit() // Get Url //*************************************************************************** -int cCurl::GetUrl(const char *url, std::string *sOutput, const std::string &sReferer) +int cCurl::GetUrl(const char* url, std::string* sOutput, const std::string& sReferer) { - CURLcode res; + CURLcode res; - init(); + init(); - curl_easy_setopt(handle, CURLOPT_URL, url); // Set the URL to get + curl_easy_setopt(handle, CURLOPT_URL, url); // Set the URL to get - if (sReferer != "") - curl_easy_setopt(handle, CURLOPT_REFERER, sReferer.c_str()); + if (sReferer != "") + curl_easy_setopt(handle, CURLOPT_REFERER, sReferer.c_str()); - curl_easy_setopt(handle, CURLOPT_HTTPGET, yes); - curl_easy_setopt(handle, CURLOPT_FAILONERROR, yes); - curl_easy_setopt(handle, CURLOPT_WRITEDATA, 0); // Set option to write to string - sBuf = ""; + curl_easy_setopt(handle, CURLOPT_HTTPGET, yes); + curl_easy_setopt(handle, CURLOPT_FAILONERROR, yes); + curl_easy_setopt(handle, CURLOPT_WRITEDATA, 0); // Set option to write to string + sBuf = ""; - res = curl_easy_perform(handle); + if ((res = curl_easy_perform(handle)) != CURLE_OK) + { + long httpCode = 0; - if (res != CURLE_OK) - { - *sOutput = ""; - return 0; - } + curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &httpCode); + tell(1, "Error: Getting URL failed; %s (%d); http code was (%ld) [%s]", + curl_easy_strerror(res), res, httpCode, url); - *sOutput = sBuf; - return 1; + *sOutput = ""; + + return 0; + } + + *sOutput = sBuf; + + return 1; } -int cCurl::GetUrlFile(const char *url, const char *filename, const std::string &sReferer) +int cCurl::GetUrlFile(const char* url, const char* filename, const std::string& sReferer) { - int nRet = 0; - init(); + int nRet = 0; - // Point the output to a file + init(); - FILE *fp; - if ((fp = fopen(filename, "w")) == NULL) - return 0; + // Point the output to a file - curl_easy_setopt(handle, CURLOPT_WRITEDATA, fp); // Set option to write to file - curl_easy_setopt(handle, CURLOPT_URL, url); // Set the URL to get - if (sReferer != "") - curl_easy_setopt(handle, CURLOPT_REFERER, sReferer.c_str()); - curl_easy_setopt(handle, CURLOPT_HTTPGET, yes); - if (curl_easy_perform(handle) == 0) - nRet = 1; - else - nRet = 0; - - curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL); // Set option back to default (string) - fclose(fp); - return nRet; + FILE *fp; + + if ((fp = fopen(filename, "w")) == NULL) + return 0; + + curl_easy_setopt(handle, CURLOPT_WRITEDATA, fp); // Set option to write to file + curl_easy_setopt(handle, CURLOPT_URL, url); // Set the URL to get + + if (sReferer != "") + curl_easy_setopt(handle, CURLOPT_REFERER, sReferer.c_str()); + + curl_easy_setopt(handle, CURLOPT_HTTPGET, yes); + + if (curl_easy_perform(handle) == 0) + nRet = 1; + else + nRet = 0; + + curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL); // Set option back to default (string) + fclose(fp); + + return nRet; } int cCurl::PostUrl(const char *url, const std::string &sPost, std::string *sOutput, const std::string &sReferer) @@ -433,8 +445,13 @@ int cCurl::downloadFile(const char* url, int& size, MemoryStruct* data, int time if ((res = curl_easy_perform(handle)) != 0) { + long httpCode = 0; + + curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &httpCode); + tell(1, "Error: Download failed; %s (%d); http code was (%ld) [%s]", + curl_easy_strerror(res), res, httpCode, url); + data->clear(); - tell(1, "Error, download failed; %s (%d)", curl_easy_strerror(res), res); return fail; } |