3

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.

YanivH
  • 99
  • 1
  • 9
  • Hi , i've managed to download the FLV , but can't change the FMT to HD . is this possible somehow ? – Rami Dabain Jan 07 '11 at 10:53
  • Yes, You know it is a 3 calls procedure since you've managed to download a video, The first one gives you the FMT, In the second call you pass the appropriate FMT link, Use This http://en.wikipedia.org/wiki/YouTube#Quality_and_codecs to choose the quality you want. – YanivH Jan 19 '11 at 13:51

2 Answers2

1

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.

YanivH
  • 99
  • 1
  • 9
  • After removing curlpp and using only curl everything works just fine, I guess their is a bug in curlpp or maybe I've used it in a wrong way. – YanivH Nov 13 '10 at 18:48
0

Youtube can provide videos encoded on several formats like h263 (flashvideo), h264, etc. Which format are you downloading? (this site also has good information of youtube audio/video formats)

Use a tool to verify the file's header and make sure that what you downloaded is ok! If you are on *nix you can execute file on the command line: file filename.flv

Another possibility is that you may not have the codec needed to play the video. This could explain why no video player on your system is able to play the video you downloaded.

karlphillip
  • 92,053
  • 36
  • 243
  • 426
  • Well, The formats of both files are flv. Still, the one I downloaded using curl is not playing. I compared both files and they are identical yet the size is little different. I think the way I write the file is wrong somehow, But its just a guess, I tried writing the file using a stream support from curl, still I get the same result. – YanivH Oct 03 '10 at 19:30
  • Ok buddy, I understood that the container you are using is FLV. But inside it, you could have multiple video encoding formats. What video encoding is being used? h263 or h264? – karlphillip Oct 03 '10 at 19:50
  • It does not really matter, I'll explain why: I took the url that I use to directly download the video, Put it in Firefox and it downloaded, I add flv suffix and played it, It worked perfectly, So i"m assuming it must be in the way i"m writing the file or the way I use curl to get it. (Oh and its H263, Also tried one that was H264, same problem with both.) – YanivH Oct 03 '10 at 20:58