none
This code to download videos in vb.net is missing something: RRS feed

  • Question

  • I want to be able to view videos offline.   Based on some forum posts, I wrote the following code:

        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles ButtonDownload.Click
            '        Make your form, 3 textboxes, 1 button
    
            download = New WebClient
            Dim url As String
            url = TextBoxURL.Text.Trim
            If url.Length = 0 Then
                MessageBox.Show("Error: you left out the url.")
                Exit Sub
            End If
    
            SaveFileDialog1.Filter = "video file|*.*"
            SaveFileDialog1.Title = "Save a Youtube File"
            SaveFileDialog1.ShowDialog()
            If SaveFileDialog1.FileName <> "" Then
                Try
                    download.DownloadFile(New Uri(url), SaveFileDialog1.FileName)
                Catch ex As Exception
                    MessageBox.Show("Error: " & ex.Message)
                    Exit Sub
                End Try
                MessageBox.Show("Success!!!")
                Application.Exit()
            Else
                Exit Sub
            End If
    
        End Sub

    A file gets produced, but I don't know what extension to give it.   For instance, if I'm downloading a YouTube video, what extension should it have.   I tried opening the file anyway, with Windows Media Player, and it said that it could not recognize the file.

    So what is missing here?

    Friday, April 13, 2018 11:11 AM

Answers

  • First off it is illegal to download youtube videos.  

    It's <g class="gr_ gr_209 gr-alert gr_gramm gr_hide gr_run_anim Grammar" data-gr-id="209" id="209" style="box-sizing:border-box;font-family:Roboto, Helvetica, Arial, sans-serif;font-size:18.72px;letter-spacing:0.9px;">more black</g> and white when you consider Google's terms of service for YouTube, which reads: "You shall not download any Content unless you see a 'download' or similar link displayed by YouTube on the Service for that Content."

    Secondly the link from youtube is not to a video but to a page which hosts the video.  There are lots of youtube video sites and they convert the video to a downloadable format.  I think you have lots to investigate if you still want to perform a download and save.


    Lloyd Sheen

    • Marked as answer by Gidmaestro Friday, April 13, 2018 8:02 PM
    Friday, April 13, 2018 11:40 AM
  • You can only download and save an entire file.

    You are probably trying to download a streaming video as a file. What url are you trying to download from?

    But videos on youtube are normally not a file you can download and save as a video file on your system. On youtube what happens is just the video frames are being sent to your computer and the streaming video player in your browser is putting the frame images together as a video and then playing them back on your system from memory. A total video file is not being downloaded. And what does get saved when you try it is just an error.

    To play a streaming video from utube you can just play the web page in a vb browser control:

    WebBrowser1.Navigate("https://www.youtube.com/watch?v=hQEG5JymFpQ")

    To play a video file in vb.net you would use something like media player, but first you need the whole file. Like an mpeg video you buy from a store like iTunes.

    • Marked as answer by Gidmaestro Friday, April 13, 2018 8:04 PM
    Friday, April 13, 2018 11:43 AM
  • If you download a Youtube link, you just download a HTML page

    You must get/parse the real information from "get_video_inf" Youtube command or use libraries like libvideo


    • Edited by Castorix31 Friday, April 13, 2018 11:48 AM
    • Marked as answer by Gidmaestro Friday, April 13, 2018 8:04 PM
    Friday, April 13, 2018 11:45 AM

All replies

  • First off it is illegal to download youtube videos.  

    It's <g class="gr_ gr_209 gr-alert gr_gramm gr_hide gr_run_anim Grammar" data-gr-id="209" id="209" style="box-sizing:border-box;font-family:Roboto, Helvetica, Arial, sans-serif;font-size:18.72px;letter-spacing:0.9px;">more black</g> and white when you consider Google's terms of service for YouTube, which reads: "You shall not download any Content unless you see a 'download' or similar link displayed by YouTube on the Service for that Content."

    Secondly the link from youtube is not to a video but to a page which hosts the video.  There are lots of youtube video sites and they convert the video to a downloadable format.  I think you have lots to investigate if you still want to perform a download and save.


    Lloyd Sheen

    • Marked as answer by Gidmaestro Friday, April 13, 2018 8:02 PM
    Friday, April 13, 2018 11:40 AM
  • You can only download and save an entire file.

    You are probably trying to download a streaming video as a file. What url are you trying to download from?

    But videos on youtube are normally not a file you can download and save as a video file on your system. On youtube what happens is just the video frames are being sent to your computer and the streaming video player in your browser is putting the frame images together as a video and then playing them back on your system from memory. A total video file is not being downloaded. And what does get saved when you try it is just an error.

    To play a streaming video from utube you can just play the web page in a vb browser control:

    WebBrowser1.Navigate("https://www.youtube.com/watch?v=hQEG5JymFpQ")

    To play a video file in vb.net you would use something like media player, but first you need the whole file. Like an mpeg video you buy from a store like iTunes.

    • Marked as answer by Gidmaestro Friday, April 13, 2018 8:04 PM
    Friday, April 13, 2018 11:43 AM
  • If you download a Youtube link, you just download a HTML page

    You must get/parse the real information from "get_video_inf" Youtube command or use libraries like libvideo


    • Edited by Castorix31 Friday, April 13, 2018 11:48 AM
    • Marked as answer by Gidmaestro Friday, April 13, 2018 8:04 PM
    Friday, April 13, 2018 11:45 AM
  • So what is missing here?

    I suspect you never downloaded a video therefore the video is missing.

    La vida loca

    Friday, April 13, 2018 4:24 PM
  • If it is illegal, then the various services on the net that let you do that should all be terminated.   There is a lot of them.

    I wanted to view offline videos simply because much of the day, I can't be on the internet.

    Anyway, thanks for the info.

    Friday, April 13, 2018 8:04 PM
  •  With one quick search I saw this thread at the top of the results.  Try the libraries that they have given links to.

    Downloading video from YouTube

     The link is a few years old but,  looking at the two GitHub links given in that thread they seem to be keeping them both up to date as far as 2017.


    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Friday, April 13, 2018 8:27 PM
    Friday, April 13, 2018 8:26 PM
  • If it is illegal, then the various services on the net that let you do that should all be terminated.   There is a lot of them.

    I wanted to view offline videos simply because much of the day, I can't be on the internet.

    Anyway, thanks for the info.


    Team America Internet Police isn't on the ball then. It is illegal but so is hacking millions of peoples data. What's your point questioning whether the TOS is valid for youtube or not just cause you want to download videos?

    La vida loca

    Saturday, April 14, 2018 1:55 AM