Results 1 to 20 of 20

Thread: Best way to download file

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    154

    Best way to download file

    I am using Inet but it seems it fails to download file which has some redirects

    for example

    file : http://youtube.com/get_video?video_i...cwXazKqj_xj5Yf

    it has some redirects so how to download that kind of files using vb?
    Last edited by Peon; Nov 3rd, 2008 at 01:21 PM.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Best way to download file

    "Seems it fails" - what does that mean?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    154

    Re: Best way to download file

    Quote Originally Posted by Hack
    "Seems it fails" - what does that mean?
    I meant that it doesn't accomplish the task or may be I am using it wrong.

    Following is code

    Code:
    Inet1.Execute Trim(Link), "GET"
    Do While Inet1.StillExecuting
      DoEvents
    Loop    
    
    size = Inet1.GetHeader("Content-Length")
    and size is returned ZERO... so I think its because of redirects.

    and Link variable contains the url
    http://youtube.com/get_video?video_i...cwXazKqj_xj5Yf
    Last edited by Peon; Nov 3rd, 2008 at 01:21 PM.

  4. #4
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Best way to download file

    There are quite a few threads in here and alot of them are very recent about doing what you are trying to do.

    Try using another link. It appears that the page no longer exists.
    Last edited by jmsrickland; Nov 3rd, 2008 at 11:47 AM.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    154

    Re: Best way to download file

    Quote Originally Posted by jmsrickland
    There are quite a few threads in here and alot of them are very recent about doing what you are trying to do.
    I have used search function but none of the address come up with the redirects issue solution.. I give it another try.

    Quote Originally Posted by jmsrickland
    Try using another link. It appears that the page no longer exists.
    for me that link is working and offering get_video page to download which is infact a flv file.

  6. #6
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Best way to download file

    When I click on that link I get this:

    The page does not exist
    The page you are looking for has been removed.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    154

    Re: Best way to download file

    Quote Originally Posted by jmsrickland
    When I click on that link I get this:

    The page does not exist
    The page you are looking for has been removed.

    Well, It happens because rotate the parameters every few hours. Anyhow.. I have changed the urls now they open.

  8. #8
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Best way to download file

    Add reference to WinHTTP.dll in systems32. (Browse to it, if Microsoft WinHTTP services doesn't show on the references list.)

    Note this simple example doesn't do anything fancy, just dumps the downloaded bytes to disk.

    OnResponseStart when you can safely access the headers.
    OnResponseDataAvailable which returns a byte array of downloaded data for each chunk.
    OnResponseEnd which ends the download.

    Code:
    Option Explicit
    Private WithEvents http As WinHttpRequest
    Private mContentLength As Long
    Private mProgress As Long
    
    Private Sub Command1_Click()
        ' Create the WinHTTPRequest ActiveX Object.
        Set http = New WinHttpRequest
        ' Open an HTTP connection.
        http.open "GET", "http://home.in.tum.de/~paula/mpeg/wg_gdo_1.mpg", True  'True means asynch.
        ' Send the HTTP Request.
        http.send
    End Sub
    
    Private Sub http_OnResponseDataAvailable(Data() As Byte)
        mProgress = mProgress + UBound(Data) + 1
        ProgressBar1.Value = mProgress
       
        Put #1, , Data
       
       
    End Sub
    
    Private Sub http_OnResponseFinished()
        Close #1
        MsgBox "done"
    End Sub
    
    Private Sub http_OnResponseStart(ByVal Status As Long, ByVal ContentType As String)
        Text1.Text = http.getAllResponseHeaders()
        mProgress = 0
        mContentLength = CLng(http.getResponseHeader("Content-Length"))
       
        ProgressBar1.Max = mContentLength
        Open "C:\twg_gdo_1.mpg" For Binary As #1
    
    End Sub
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    154

    Re: Best way to download file

    Quote Originally Posted by isnoend07
    Add reference to WinHTTP.dll in systems32. (Browse to it, if Microsoft WinHTTP services doesn't show on the references list.)

    Note this simple example doesn't do anything fancy, just dumps the downloaded bytes to disk.

    OnResponseStart when you can safely access the headers.
    OnResponseDataAvailable which returns a byte array of downloaded data for each chunk.
    OnResponseEnd which ends the download.

    Code:
    Option Explicit
    Private WithEvents http As WinHttpRequest
    Private mContentLength As Long
    Private mProgress As Long
    
    Private Sub Command1_Click()
        ' Create the WinHTTPRequest ActiveX Object.
        Set http = New WinHttpRequest
        ' Open an HTTP connection.
        http.open "GET", "http://home.in.tum.de/~paula/mpeg/wg_gdo_1.mpg", True  'True means asynch.
        ' Send the HTTP Request.
        http.send
    End Sub
    
    Private Sub http_OnResponseDataAvailable(Data() As Byte)
        mProgress = mProgress + UBound(Data) + 1
        ProgressBar1.Value = mProgress
       
        Put #1, , Data
       
       
    End Sub
    
    Private Sub http_OnResponseFinished()
        Close #1
        MsgBox "done"
    End Sub
    
    Private Sub http_OnResponseStart(ByVal Status As Long, ByVal ContentType As String)
        Text1.Text = http.getAllResponseHeaders()
        mProgress = 0
        mContentLength = CLng(http.getResponseHeader("Content-Length"))
       
        ProgressBar1.Max = mContentLength
        Open "C:\twg_gdo_1.mpg" For Binary As #1
    
    End Sub
    It worked superb...
    just a new thought in my mind..

    Is it possible to download only specific part of file?

    Suppose file size is 1024 KB.
    First file is downloaded 1KB to 100KB.

    Then resuming it from 101KB to 1024KB.

    I have achieved this functionality in php but still not successful with doing this in vb.

  10. #10
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Best way to download file

    Quote Originally Posted by Peon
    It worked superb...
    just a new thought in my mind..

    Is it possible to download only specific part of file?

    Suppose file size is 1024 KB.
    First file is downloaded 1KB to 100KB.

    Then resuming it from 101KB to 1024KB.

    I have achieved this functionality in php but still not successful with doing this in vb.
    Seems to me you could stop it at a certain byte. Don't know about resuming at the next byte. You may want to post this as a new question.
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  11. #11
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Best way to download file

    Is there something wrong with that code? I use it and everything I download is missing the sound from the file. I downloaded that example mpg (exactly as shown in the post) and I get the video but no sound. So I changed the URL to something else (a You Tube video) and also got the video but again no sound. I know it is not my sound card cause I can play music on my PC and it is audiable.

  12. #12
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Best way to download file

    Quote Originally Posted by jmsrickland
    Is there something wrong with that code? I use it and everything I download is missing the sound from the file. I downloaded that example mpg (exactly as shown in the post) and I get the video but no sound. So I changed the URL to something else (a You Tube video) and also got the video but again no sound. I know it is not my sound card cause I can play music on my PC and it is audiable.
    Been using the code for a year. I use it like this:
    It downloads a real small text file that holds a version number. This version number is compared to the users exe version number and if its higher then they can then download the exe. The exe is 14980kb and i gotta say it has always worked. Here is a working example:
    http://www.planet-source-code.com/vb...xtCodeId=69060, it also uses WinHttpRequest


    Don't know what could be wrong other than downloading the file with your browser to make sure it's valid.
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  13. #13
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Best way to download file

    I just don't think the file has sound to it.

    What does that link do? I don't see where it has anything to do with the code and link you posted.

  14. #14
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Best way to download file

    Quote Originally Posted by jmsrickland
    I just don't think the file has sound to it.

    What does that link do? I don't see where it has anything to do with the code and link you posted.
    It downloads files. I have posted a valid wav file that works on my website for you to test here: http://roofgenius.com/wahoo.wav
    Hope this helps
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  15. #15
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Best way to download file

    It returns Page Cannot Be Found. I even tried http://www.roofgenius.com/wahoo.wav

    The URL http://www.roofgenius.com seems to be OK; so it must be the wahoo.wav that it can't find.

  16. #16
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Best way to download file

    Quote Originally Posted by jmsrickland
    It returns Page Cannot Be Found. I even tried http://www.roofgenius.com/wahoo.wav

    The URL http://www.roofgenius.com seems to be OK; so it must be the wahoo.wav that it can't find.
    Whoops
    It's Whoo.wav
    sorry
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  17. #17
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Best way to download file

    OK, now using the code you posted in #8 and the following statement:

    http.Open "GET", "http://www.roofgenius.com/Whoo.wav", True

    It downloads the file and there is sound. But when I download this....

    http.Open "GET", "http://home.in.tum.de/~paula/mpeg/wg_gdo_1.mpg

    I get the video but no sound.

    So, I am assuming the file does not contain sound in it.

  18. #18
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Best way to download file

    Quote Originally Posted by jmsrickland
    OK, now using the code you posted in #8 and the following statement:

    http.Open "GET", "http://www.roofgenius.com/Whoo.wav", True

    It downloads the file and there is sound. But when I download this....

    http.Open "GET", "http://home.in.tum.de/~paula/mpeg/wg_gdo_1.mpg

    I get the video but no sound.

    So, I am assuming the file does not contain sound in it.
    I downloaded the file in your link with my browser and it does not contain sound
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  19. #19
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Best way to download file

    I downloaded the file in your link with my browser and it does not contain sound

    Not my link; it was the link in your code from your post #8

  20. #20
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Best way to download file

    Quote Originally Posted by jmsrickland
    I downloaded the file in your link with my browser and it does not contain sound

    Not my link; it was the link in your code from your post #8
    That file was just an old example, don't know if it ever existed. Think I copied it from somewhere I expected you to supply your own file
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width