从curlpp在curl上下载flv从youtube使用 - 视频不播放 [英] Downloading flv from youtube using curlpp on top of curl - video not playing

查看:706
本文介绍了从curlpp在curl上下载flv从youtube使用 - 视频不播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经设法下载flv,但无法使用所有打开它



我使用另一个YouTube视频下载器,并下载完全相同的视频质量完全相同,我注意到请求是一样的,也是文件大小几乎相同 - 这里我认为是问题,例如:MyVideo.flv - 4.55MB WorkingVideo.flv - 4.53MB



这里是代码: p>


//回调函数
size_t FileCallback(FILE f,char ptr,size_t size, size_t nmemb)
{
return fwrite(ptr,size,nmemb,f);
}



void GetVideo wstring videoUrl)
{

  FILE * file = fopen(C:\\locatin\\ b.flv,w); 

if(file)
{
curlpp :: Cleanup cleaner;
curlpp :: Easy request;

//设置写回调以启用cURL将结果写入内存区
curlpp :: types :: WriteFunctionFunctor functor(utilspp :: BindFirst(utilspp :: make_functor(& FileCallback),file ));
curlpp :: options :: WriteFunction * getFileOpt = new curlpp :: options :: WriteFunction(functor); $ b $ d request.setOpt(getFileOpt);

//将URL设置为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.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);
}

}



任何想法任何人



谢谢。

方案

由于我在Windows平台上开发,我决定下载文件我将使用URLDownloadToFile信息: http://msdn.microsoft.com/en-us/library/ms775123%28VS.85%29.aspx p>

这个工作方式像一个charm,仍然不能确定为什么curl保存文件有点不同于IE或FF或上面的win32 api函数。


I"m using curlpp on to of curl lib in order to download videos from youtube.

I have managed to download the flv but unable to open it using all sorts of video players.

I used another youtube video downloader and download the exactly same video with the exactly same quality, I've noticed the requests are the same and also the file size is almost identical - here I think is the problem, For example: MyVideo.flv - 4.55MB WorkingVideo.flv - 4.53MB

Here is the code:

// 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);
}

}

Any ideas anyone??

Thanks.

解决方案

Since I"m developing on windows platform I've decided that for downloading the file I'll use URLDownloadToFile Info: http://msdn.microsoft.com/en-us/library/ms775123%28VS.85%29.aspx

This one works like a charm, Still not sure why curl saves the file a little bit different than IE or FF or the above win32 api function.

这篇关于从curlpp在curl上下载flv从youtube使用 - 视频不播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆