Qt World Summit: Submit your Presentation

How to find complete information about the file to be downloaded using QNetworkAccessManager HTTP Qt

  • I'm making something like a Download Manager using Qt. I'm able to successfully download any file using a URL, but I also need to store that file on some storage media and for that I need to know the exact file type i.e (file format like .avi , .msi, .exe etc). The metadata header I receive at the start of the download does give me some information like for URL (http://u801.wapkafile.com//g03/video/1253022/7940/c8f9a32ef15648bfa6f693102de27835/DARNA-ZAROORI-HAI-3(Movies7.In).avi?md5=TU7ibYa85byjzJyJcH_LXQ&expires=1458916610)

    that is a ".avi" file, it gives me following info

    Content type :video/x-msvideo
    Content length :65707724
    Last modified :2014-12-31T06:15:08Z
    Content Disposition Info :
    but this is not sufficient. It doesn't tell me the exact format i.e ".avi". And additionally it doesn't give file description for a video file like in Internet Download Manager I get "AVI: Res. 640x360, 29 samp per sec, Length 36 min 13 sec" .

    Is there a way I can get this information? Any help is really appreciated!

  • The server is not returning anything useful in the HTTP headers (I wouldn't expect it to):

    ~/tmp$ wget -S 'http://u801.wapkafile.com//g03/video/1253022/7940/c8f9a32ef15648bfa6f693102de27835/DARNA-ZAROORI-HAI-3(Movies7.In).avi?md5=TU7ibYa85byjzJyJcH_LXQ&expires=1458916610'
    --2016-07-27 18:21:15--  http://u801.wapkafile.com//g03/video/1253022/7940/c8f9a32ef15648bfa6f693102de27835/DARNA-ZAROORI-HAI-3(Movies7.In).avi?md5=TU7ibYa85byjzJyJcH_LXQ&expires=1458916610
    Resolving u801.wapkafile.com (u801.wapkafile.com)...
    Connecting to u801.wapkafile.com (u801.wapkafile.com)||:80... connected.
    HTTP request sent, awaiting response... 
      HTTP/1.1 200 OK
      Server: nginx
      Date: Wed, 27 Jul 2016 08:21:15 GMT
      Content-Type: video/x-msvideo
      Content-Length: 65707724
      Connection: keep-alive
      Last-Modified: Wed, 31 Dec 2014 06:15:08 GMT
      Content-Disposition: attachment; filename="DARNA-ZAROORI-HAI-3(Movies7.In).avi"
      Accept-Ranges: bytes
      Expires: Wed, 03 Aug 2016 06:34:10 GMT
      Cache-Control: max-age=604800
      Cache-Control: s-maxage=604800,max-age=604800
      Age: 6425
      X-Cache: HIT TCP_MEM_HIT dirn:0:1402323922
      X-Swift-SaveTime: Wed, 27 Jul 2016 06:34:10 GMT
      X-Swift-CacheTime: 604800
      Via: 440d210b[0,206-0,H]
    Length: 65707724 (63M) [video/x-msvideo]
    Saving to: 'DARNA-ZAROORI-HAI-3(Movies7.In).avi?md5=TU7ibYa85byjzJyJcH_LXQ&expires=1458916610.1’

    So Download Manager must be getting the info from the metadata at the start of the file.

    For example, I only downloaded the first 70KB of the file, and:

    ~/tmp$ file DARNA-ZAROORI-HAI-3\(Movies7.In\).avi\?md5=TU7ibYa85byjzJyJcH_LXQ\&expires=1458916610 
    DARNA-ZAROORI-HAI-3(Movies7.In).avi?md5=TU7ibYa85byjzJyJcH_LXQ&expires=1458916610: RIFF (little-endian) data, AVI, 640 x 360, ~30 fps, video: H.264 X.264 or H.264, audio: MPEG-1 Layer 3 (stereo, 22050 Hz)

    So the info is there at the start. I expect you'll want to use a library to parse it out. I'm not sure if Qt has such functionality built-in. Perhaps have a look through the Qt Multimedia docs.