为了从youtube下载视频,我在curl lib上使用curlpp。
我已经设法下载了flv,但无法打开它使用各种各样的视频播放器。
我使用了另一个youtube视频下载程序,下载了完全相同的视频,质量完全相同,我注意到请求是相同的,而且文件大小几乎相同-我认为问题出在这里,例如:我的视频.flv-455万工作视频.flv-453万
// Callback Function
size_t FileCallback(FILE
f, char
ptr, size_t size, size_t nmemb)
{
return fwrite(ptr, size, nmemb, f);
}
void GetVideo(std::wstring videoUrl)
FILE * file = fopen("C:\\locatin\\b.flv", "w");
if (file)
{
curlpp::Cleanup cleaner;
curlpp::Easy request;
// Set the writer callback to enable cURL to write result in a memory area
curlpp::types::WriteFunctionFunctor functor(utilspp::BindFirst(utilspp::make_functor(&FileCallback), file));
curlpp::options::WriteFunction *getFileOpt = new curlpp::options::WriteFunction(functor);
request.setOpt(getFileOpt);
// Setting the URL to retrive.
request.setOpt(new curlpp::options::Url(videoUrl));
request.setOpt(new curlpp::options::Verbose(true));
request.setOpt(new Timeout(2000));
std::list<std::string> headers;
headers.push_back("Connection: keep-alive");
headers.push_back("Keep-Alive: 115");
headers.push_back("Accept-Encoding: gzip,deflate");
headers.push_back("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7");
headers.push_back("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10");
headers.push_back("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
headers.push_back("Accept-Language: en-us,en;q=0.5");
request.setOpt<HttpHeader>(headers);
request.perform();
fclose(file);
}
}
有什么想法吗??