is there a way to get info from a youtube video link such as
i want to get the title, description, video duration, thumbnail link, and videoid ie.: v=gJ_3BN0m7S8
just the bold part from a link

and yeah without the use of an webbrowser since they seem to be really slow

and no code is done for now ill manage to implement into a project im workin on later this is the only part i need, thanks!

You could use WebClient or HttpWebRequest to get the URL source. Then look for the desired info.

Add the following Imports statements:

  • Imports System.IO
  • Imports System.Net

Version 1 (using WebClient):

Public Function getUrlSource() As String
    Dim urlSource As String = String.Empty
    Dim client As New System.Net.WebClient

        'create request to web server (url)
        urlSource = client.DownloadString(_url)
        If Not client Is Nothing Then
        End If
    End Try

    Return urlSource
End Function

Version 2 (using HttpWebRequest):

Public Function getUrlSource() As String
    Dim errMsg As String = String.Empty
    Dim urlSource As String = String.Empty
    Dim request As System.Net.HttpWebRequest = Nothing
    Dim response As System.Net.HttpWebResponse = Nothing
    Dim sr As System.IO.StreamReader = Nothing

        'create request to web server (url)
        request = HttpWebRequest.Create(_url)

        'set value for AutoRedirect
        request.AllowAutoRedirect = True

        'receives response from request sent to 
        'web server
        response = request.GetResponse()

        If Not response.StatusCode = HttpStatusCode.OK Then
            errMsg = "Response status code: " & response.StatusCode
            MessageBox.Show(errMsg, "Error - Response", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return errMsg
        End If

        'get encoding
        Dim encoding = System.Text.Encoding.GetEncoding(response.CharacterSet)

        'use StreamReader to read urlSource
        sr = New StreamReader(response.GetResponseStream(), encoding)
        urlSource = sr.ReadToEnd()

        'close StreamReader
        If Not sr Is Nothing Then
        End If
    End Try

    Return urlSource
End Function

Then get the information from the html source code:

First I create a class to hold the desired data. I will call it "YTInfo.vb"


Public Class YTnfo
    Public Property Author As String
    Public Property ChannelId As String
    Public Property Description As String
    Public Property Duration As String
    Public Property ThumbnailUrl As String
    Public Property Title As String
    Public Property Url As String
    Public Property VideoId As String

End Class

You can use a different method to get your desired data from the html source, but I use a WebBrowser and HtmlDocument.


Private Function extractDataFromHtml(ByVal urlSource As String) As YTnfo

    Dim elemContent As String = String.Empty
    Dim elemHref As String = String.Empty
    Dim elemName As String = String.Empty
    Dim elemItemProp As String = String.Empty
    Dim elemProperty As String = String.Empty

    Dim htmlDoc As System.Windows.Forms.HtmlDocument
    Dim metaElements As System.Windows.Forms.HtmlElementCollection
    Dim linkElements As System.Windows.Forms.HtmlElementCollection
    Dim spanElements As System.Windows.Forms.HtmlElementCollection
    Dim webBrowser1 As New System.Windows.Forms.WebBrowser

    Dim info As New YTnfo

    If Not String.IsNullOrEmpty(urlSource) Then
        Console.WriteLine("getting tags...")

        'suppress scripting errors
        webBrowser1.ScriptErrorsSuppressed = True

        'open a blank web page

        'set htmlDoc = to a new WebBrowser document
        htmlDoc = webBrowser1.Document.OpenNew(True)

        'write html to the blank
        'HTML document

        'get "meta" elements
        metaElements = htmlDoc.GetElementsByTagName("meta")

        For Each element As System.Windows.Forms.HtmlElement In metaElements

            elemContent = element.GetAttribute("content")
            elemHref = element.GetAttribute("href")
            elemName = element.GetAttribute("name")
            elemItemProp = element.GetAttribute("itemprop")
            elemProperty = element.GetAttribute("property")

            If elemName = "title" Then
                info.Title = elemContent
            End If

            If elemItemProp = "channelId" Then
                info.ChannelId = elemContent
            ElseIf elemItemProp = "description" Then
                info.Description = elemContent
            ElseIf elemItemProp = "duration" Then
                info.Duration = elemContent
            ElseIf elemItemProp = "videoId" Then
                info.VideoId = elemContent
            End If

            If elemProperty = "og:title" Then
                info.Title = elemContent
            ElseIf elemProperty = "og:url" Then
                info.Url = elemContent
            End If

        'get "link" elements
        linkElements = htmlDoc.GetElementsByTagName("link")

        For Each element As System.Windows.Forms.HtmlElement In linkElements

            elemContent = String.Empty
            elemHref = String.Empty
            elemName = String.Empty
            elemItemProp = String.Empty
            elemProperty = String.Empty

            elemHref = element.GetAttribute("href")
            elemItemProp = element.GetAttribute("itemprop")

            If elemItemProp = "thumbnailUrl" Then
                info.ThumbnailUrl = elemHref
            ElseIf elemItemProp = "url" Then
                Console.WriteLine("URL: " & elemHref)
            End If

        'get "span" elements - to get Author
        spanElements = htmlDoc.GetElementsByTagName("span")

        For Each element As System.Windows.Forms.HtmlElement In spanElements

            elemHref = element.GetAttribute("href")
            elemItemProp = element.GetAttribute("itemprop")

            If elemItemProp = "author" Then

                'get "link" elements inside of the "span" element
                linkElements = element.GetElementsByTagName("link")

                For Each spanLinkElement As System.Windows.Forms.HtmlElement In linkElements

                    If spanLinkElement.GetAttribute("itemprop") = "url" Then
                        If spanLinkElement.GetAttribute("href").StartsWith("") Then
                            info.Author = spanLinkElement.GetAttribute("href")
                        End If
                    End If
            End If
    End If

    Return info
End Function

Another option would be to use regex. You can see how to use regex in my post here.

Look at "extractData".

A regex pattern for "Title" would look like:

Dim patternTitle As String = "<meta name=""title"" content=""(?<title>.*)"">"


Dim patternTitle As String = "<meta property=""og:title"" content=""(?<title>.*)"">"

However, I've read that one should not use regex to parse html.

Here is some of the info you might look for:


<span itemprop="author" itemscope itemtype="">
  <link itemprop="url" href="">


<meta itemprop="channelId" content="UC8Tvbkn57bAs_yOjaI1XiCg">


<meta name="description" content="Bear to the rescue. Filmed at Budapest ZOO (Hungary), 19. 6. 2014 Camera: Panasonic Lumix DMC-FZ72">


<meta itemprop="duration" content="PT2M13S">


<meta property="og:title" content="Crow rescue">

<meta name="title" content="Crow rescue">

Thumbnail URL:

<meta property="og:image" content="">

<link itemprop="thumbnailUrl" href="">


<meta property="og:url" content="">

<meta name="twitter:url" content="">


<meta itemprop="videoId" content="gJ_3BN0m7S8">

WebClient.DownloadString Method (String)

HtmlDocument.Write Method

How to obtain HtmlDocument from a string of a webpage?

Read text from response

commented: thank you very much for this, well detailed! +0

For duration, you see the following:

<meta itemprop="duration" content="PT2M13S">

It appears that “PT” marks the start of the time part of the value. "M" is for minute(s). "S" is for seconds.

So in the above: 2 minutes and 13 seconds

commented: ty! +1

thank you very much cgeier i will try this tomorrow after work and come back with feedback, much appreciated for this well detailed!