Results 1 to 20 of 22

Thread: Downloading a video from youtube

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2009
    Posts
    19
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Downloading a video from youtube

    Hi, what qt4 class could I use to download a video from youtube? I need to download a video from an url like this: http://youtube.com/get_video?video_i...xA5rvs=&fmt=18. Firefox download this video but Qhttp fails to download. Any suggestions?
    This is my code:
    Qt Code:
    1. QString video_url = "http://youtube.com/get_video";
    2. QString argument = "?video_id=Th7-EzW0Ccw&t=vjVQa1PpcFNQDXk1DXroxSYaUxdfZ23C8lngRxA5rvs=&fmt=18";
    3. QString dest = "/home/faster/video.mp4";
    4.  
    5. QUrl url(video_url);
    6. QFileInfo fileInfo(url.path());
    7. QString fileName = fileInfo.fileName();
    8. if (fileName.isEmpty())
    9. fileName = "index.html";
    10.  
    11. file = new QFile(dest);
    12.  
    13. QHttp::ConnectionMode mode = url.scheme().toLower() == "https" ? QHttp::ConnectionModeHttps : QHttp::ConnectionModeHttp;
    14. http->setHost(url.host(), mode, url.port() != -1 ? url.port() : 80);
    15.  
    16. if (!url.userName().isEmpty())
    17. http->setUser(url.userName(), url.password());
    18.  
    19. httpRequestAborted = false;
    20. QByteArray path = QUrl::toPercentEncoding(url.path(), "!$&'()*+,;=:@/");
    21. if (path.isEmpty())
    22. path = "/";
    23. httpGetId = http->get(video_url+argument, file);
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Downloading a video from youtube

    Quote Originally Posted by Faster View Post
    Hi, what qt4 class could I use to download a video from youtube?
    There are many options.
    1. QHttp
    2. QTCPSocket
    3. QNetworkAccessManager
    4. QDesktopServices::openUrl();

  3. The following user says thank you to yogeshgokul for this useful post:

    Faster (28th November 2009)

  4. #3
    Join Date
    Apr 2009
    Posts
    19
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Downloading a video from youtube

    How can I download a video from http://youtube.com/get_video?video_i...xA5rvs=&fmt=18 using Qhttp? I posted my code but I don't understand what's wrong! It downloads a web page instead of the mp4 file.

  5. #4
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Downloading a video from youtube

    Quote Originally Posted by Faster View Post
    How can I download a video from http://youtube.com/get_video?video_i...xA5rvs=&fmt=18 using Qhttp?
    You need to call QHttp::get() with appropriate URL.

  6. #5
    Join Date
    Apr 2009
    Posts
    19
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Downloading a video from youtube

    I used this:
    Qt Code:
    1. http->get("http://youtube.com/get_video?video_id=Th7-EzW0Ccw&t=vjVQa1PpcFNQDXk1DXroxSYaUxdfZ23C8lngRxA5rvs=&fmt=18", file);
    To copy to clipboard, switch view to plain text mode 
    But it downloads only a web page and not the video file. If I open this link with firefox it downloads the correct video file. Any idea?

  7. #6
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Downloading a video from youtube

    Its downloading what youtube is sending. You need to parse the downloaded web page most likely.

  8. #7
    Join Date
    Apr 2009
    Posts
    19
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Downloading a video from youtube

    This is the web page content:

    Qt Code:
    1. Moved Permanently
    2. The document has moved here.
    3.  
    4. Apache Server at www.youtube.com Port 80
    To copy to clipboard, switch view to plain text mode 

    I'm creating a program that allows the user to download a video from youtube. I written a code that generates a link to a mp4 file using http://youtube.com/get_video. The link generated is session-sensitive and changed every time the video is accessed. This url works with web browsers but doesn't work with my program.
    Now I think that this url works only with web browsers. if my argumentation is right, how can I modify my code to make youtube believe that my program is a web browser, using qhttp?

    Sorry for my poor English. I hope I explained myself.

  9. #8
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Downloading a video from youtube

    Like I said before, you need to parse the returned content and process it. If a web browser receives "Moved Permanently The document has moved here.", then they will automatically follow that redirection. This is invisible to the user - they never see the message.

  10. #9
    Join Date
    Apr 2009
    Posts
    19
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Downloading a video from youtube

    No, the web browser receives the correct video while qhttp receives a redirection web page! The redirection link contained in this web page is the same link that I have used to download the page!

  11. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Downloading a video from youtube

    When I follow the link you pasted using the browser, I get a blank page.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #11
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Downloading a video from youtube

    It doesn't work for me either. Maybe when Faster posts a link that works, we can help him

Similar Threads

  1. open a video file in a new window...
    By jiapei100 in forum Qt Programming
    Replies: 0
    Last Post: 19th September 2009, 14:53
  2. Replies: 3
    Last Post: 5th July 2009, 17:22
  3. Video freezes during mpeg video playback using Phonon
    By davejames in forum Qt Programming
    Replies: 2
    Last Post: 12th January 2009, 08:45

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.