[Vb.Net] YouTubeHelper by fudmario

Iniciado por fudmario, Noviembre 21, 2015, 12:22:57 AM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Código: vbnet

' ***********************************************************************
' Assembly         : Youtube Downloader
' Author           : fudmario
' Created          : 15-06-2015
'
' Last Modified By : fudmario
' Last Modified On : 11-20-2015
' ***********************************************************************
' <copyright file="YoutubeHelper.vb" company="FudmarioDev">
'     '     Copyright ©  2015
'
' </copyright>
' <summary></summary>
' *************************************************************************

Option Explicit On
Option Strict On
Option Infer On

Imports System.Collections.Specialized
Imports System.Net
Imports System.Text
Imports System.Text.RegularExpressions
Imports System.Web

''' <summary>
''' Class YoutubeHelper. Esta Clase no puede ser Heredada.
''' </summary>
Public NotInheritable Class YoutubeHelper
    ''' <summary>
    ''' Url para Obtener la Información del Video
    ''' </summary>
    Private Const InfoUrl As String = "http://www.youtube.com/get_video_info?video_id="

    ''' <summary>
    ''' Expresión Regular para obtener el Link de la imagen del Video.
    ''' </summary>
    ''' <value>The imagen.</value>
    Private Shared ReadOnly Property Imagen As Regex
        Get
            Return New Regex("<meta\sproperty=""og:image""\scontent=""(.*?default\.jpg)"">")
        End Get
    End Property

    ''' <summary>
    ''' Expresion Regular para Obtener el Título del video.
    ''' </summary>
    ''' <value>The title.</value>
    Private Shared ReadOnly Property Title As Regex
        Get
            Return New Regex("<meta\sproperty=""og:title""\scontent=""(.*?)"">")
        End Get
    End Property

    ''' <summary>
    ''' Expresion Regular para obtener la Descripción del Video.
    ''' </summary>
    ''' <value>Descripción del Video.</value>
    Private Shared ReadOnly Property Description As Regex
        Get
            Return New Regex("<meta\sproperty=""og:description""\scontent=""(.*?)"">")
        End Get
    End Property

    ''' <summary>
    ''' Expresion Regular para obtener la Duracion del Video (en segundos).
    ''' </summary>
    ''' <value> Duracion del Video (en segundos).</value>
    Private Shared ReadOnly Property Duration As Regex
        Get
            Return New Regex("length_seconds"":""(.*?)"",")
        End Get
    End Property

''' <summary>
    ''' Obtiene Informacion sobre la Url de Video de Youtube.
    ''' </summary>
    ''' <param name="url">Url del Video de YouTube.</param>
    ''' <param name="byPass">Si se establece como <c>true</c> aplicamos el bypass.</param>
    ''' <returns>YouTubeVideoInformation.</returns>
    ''' <exception cref="ArgumentNullException">La <paramref name="url" /> no puede estar vacia;url</exception>
    ''' <exception cref="FormatException">Formato de <paramref name="url" /> Invalido;Url</exception>
    Public Shared Function GetYouTubeVideoInfo(url As String, Optional ByVal byPass As Boolean = False) As YouTubeVideoInformation

        If String.IsNullOrEmpty(url) Then Throw New ArgumentNullException(message:="La Url no puede estar vacia", paramName:="URL")

        If Not Regex.IsMatch(url, "(http|https):..(www\.)?youtube.com.watch\?v=") Then Throw New FormatException(message:="Formato de Url Invalido")

        Dim videoInfoFull As New YouTubeVideoInformation
        Dim infoVideo As New List(Of YoutubeVideoInfo)
        Dim adInfoVideo As YoutubeVideoInfo
        Dim mSource As String
        Dim arrayParams As NameValueCollection

        Using c As New WebClient
            c.Encoding = Encoding.GetEncoding(1252)
            mSource = c.DownloadString(url)

            Select Case byPass
                Case True
                    arrayParams = HttpUtility.ParseQueryString(HttpUtility.HtmlDecode(c.DownloadString(String.Format("{0}{1}&el=vevo", InfoUrl, HttpUtility.ParseQueryString(New Uri(url).Query).Get("v")))))
                Case Else
                    arrayParams = HttpUtility.ParseQueryString(HttpUtility.HtmlDecode(c.DownloadString(String.Format("{0}{1}", InfoUrl, HttpUtility.ParseQueryString(New Uri(url).Query).Get("v")))))
            End Select
        End Using

        Dim ytTitle As String = HttpUtility.HtmlDecode(Title.Match(mSource).Groups(1).Value)
        Dim ytDescription As String = HttpUtility.HtmlDecode(Description.Match(mSource).Groups(1).Value)
        Dim ytDuration As Double = CDbl(Duration.Match(mSource).Groups(1).Value)
        Dim ytImg As String = Imagen.Match(mSource).Groups(1).Value

        If arrayParams("status") = "ok" Then

            Dim urLs As String() = arrayParams("url_encoded_fmt_stream_map").Split(","c)
            Dim sb As New StringBuilder()
            For i = 0 To urLs.Length - 1
                adInfoVideo = New YoutubeVideoInfo()
                sb.Clear()
                Dim mUriDec As String = HttpUtility.HtmlDecode(urLs(i))
                Dim urlParams As NameValueCollection = HttpUtility.ParseQueryString(mUriDec)
                Dim vidFormat As String = HttpUtility.HtmlDecode(urlParams("type"))
                sb.Append(HttpUtility.HtmlDecode(urlParams("Url")))
                sb.AppendFormat("&signature={0}", HttpUtility.HtmlDecode(urlParams("sig")))
                sb.AppendFormat("&type={0}", vidFormat)
                sb.AppendFormat("&title={0}", HttpUtility.HtmlDecode(arrayParams("title")))

                Dim format As String = vidFormat.Split(";"c)(0).Split("/"c)(1)
                If format.Contains("x-flv") Then
                    format = "flv"
                End If

                adInfoVideo.Url = sb.ToString
                adInfoVideo.Quality = urlParams("quality")
                adInfoVideo.Format = format
                infoVideo.Add(adInfoVideo)
            Next
            videoInfoFull.ErrorCode = 0
            videoInfoFull.LinksDetails = infoVideo
            videoInfoFull.Title = ytTitle
            videoInfoFull.Duration = ytDuration
            videoInfoFull.Description = ytDescription
            videoInfoFull.ImgLink = ytImg
            Return videoInfoFull
        Else
            videoInfoFull.ErrorCode = 1
            videoInfoFull.ErrorMsg = HttpUtility.HtmlDecode(arrayParams("reason"))
            Return videoInfoFull
        End If

    End Function
End Class

''' <summary>
''' Información Básica del Video.
''' </summary>
Public Class YoutubeVideoInfo
    ''' <summary>
    ''' Obtiene o Establece la Url Directa del Video.
    ''' </summary>
    ''' <value>Url Directa del Video.</value>
    Public Property Url() As String
    ''' <summary>
    ''' Obtiene o Establece el Formato del Video.
    ''' </summary>
    ''' <value>Formato del Video.</value>
    Public Property Format() As String

    ''' <summary>
    ''' Obtiene o Establece La Calidad del Video.
    ''' </summary>
    ''' <value>Calidad del Video.</value>
    Public Property Quality() As String

End Class

''' <summary>
''' Información Completa del Video de YouTube.
''' </summary>
Public Class YouTubeVideoInformation
    ''' <summary>
    ''' Obtiene o Establece la lista de Link's Disponibles y Informacion Adicional.
    ''' </summary>
    ''' <value>lista de Link's Disponibles.</value>
    Public Property LinksDetails() As List(Of YoutubeVideoInfo)

    ''' <summary>
    ''' Obtiene o Establece El Titulo del Video.
    ''' </summary>
    ''' <value>El Titulo del Video.</value>
    Public Property Title() As String

    ''' <summary>
    ''' Obtiene o Establece El link de la Imagen del Video.
    ''' </summary>
    ''' <value>El link de la Imagen del Video.</value>
    Public Property ImgLink() As String

    ''' <summary>
    ''' Obtiene o Establece la Descripción del Video.
    ''' </summary>
    ''' <value>la Descripción del Video.</value>
    Public Property Description() As String

    ''' <summary>
    ''' Obtiene o Establece la Duracion del Video.
    ''' </summary>
    ''' <value>Duracion del Video.</value>
    Public Property Duration() As Double
    ''' <summary>
    ''' Obtiene o Establece el codigo de Error: 0 = No Error, 1 = Error.
    ''' </summary>
    ''' <value>codigo de Error: 0 = No Error, 1 = Error..</value>
    Public Property ErrorCode() As Integer

    ''' <summary>
    ''' Obtiene o Establece el Mensaje de Error.
    ''' </summary>
    ''' <value>Mensaje de Error.</value>
    Public Property ErrorMsg() As String
End Class





  • Ejemplo de Uso:

Código: vbnet
Dim response As YouTubeVideoInformation
        response = YoutubeHelper.GetYouTubeVideoInfo("https://www.youtube.com/watch?v=mWRsgZuwf_8", True)
        If response.ErrorCode = 0 Then

            Dim sb As New System.Text.StringBuilder
            sb.AppendLine(String.Format("Titulo: {0}", response.Title))
            sb.AppendLine(String.Format("Descripción: {0}", response.Description))
            sb.AppendLine(String.Format("Duración: {0}", TimeSpan.FromSeconds(response.Duration).ToString("hh\:mm\:ss")))
            sb.AppendLine(String.Format("Url de la Imagen: {0}", response.ImgLink))
            sb.AppendLine()
            sb.AppendLine("Urls: ")
            For Each urldetails As YoutubeVideoInfo In response.LinksDetails

                sb.AppendLine("*************************")
                sb.AppendLine(String.Format("Url: {0}", urldetails.Url))
                sb.AppendLine(String.Format("Formato: {0}", urldetails.Format))
                sb.AppendLine(String.Format("Calidad: {0}", urldetails.Quality))

            Next
            MessageBox.Show(sb.ToString)
        Else
            MessageBox.Show(response.ErrorMsg)
        End If

      

  • Retorna:


Código: php
Titulo: Imagine Dragons - Demons (Official)
Descripción: Get Smoke + Mirrors on iTunes now: http://smarturl.it/IDSmokeMirrors Get Smoke + Mirrors Deluxe version with 4 exclusive songs only at Target: http://smartur...
Duración: 00:03:57
Url de la Imagen: https://i.ytimg.com/vi/mWRsgZuwf_8/maxresdefault.jpg

Urls:
*************************
Url: http://r1---sn-o0x85uxa-a2ce.googlevideo.com/videoplayback?mt=1448075110&mv=m&initcwndbps=180000&itag=22&ms=au&upn=hhv_O7PIcl0&pcm2=no&mm=31&mn=sn-o0x85uxa-a2ce&expire=1448096854&mime=video%2Fmp4&pl=20&source=youtube&ratebypass=yes&dur=236.170&lmt=1429535723891505&key=yt6&ipbits=0&gcr=bo&sparams=dur%2Cgcr%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpcm2%2Cpcm2cms%2Cpl%2Cratebypass%2Csource%2Cupn%2Cexpire&fexp=9407156%2C9408710%2C9413137%2C9416126%2C9417683%2C9419445%2C9419837%2C9420452%2C9421097%2C9421166%2C9421411%2C9422323%2C9422541%2C9422596%2C9422618%2C9422838%2C9422992%2C9423042%2C9423431%2C9423489%2C9423643%2C9423662%2C9423667%2C9424509%2C9424740&id=o-APsq1d2t11trGfv2qYsVS9NyPHMMqsQcMSBaV7pEXwYP&sver=3&ip=161.22.129.235&signature=5582F3AC476FB6403987BF9C3CAE4DC4661C5FBB.4079167906F1B6388735F66E18D9F1C47FCF4137&pcm2cms=yes&signature=&type=video/mp4; codecs="avc1.64001F, mp4a.40.2"&title=Imagine Dragons - Demons (Official)
Formato: mp4
Calidad: hd720
*************************
Url: http://r1---sn-o0x85uxa-a2ce.googlevideo.com/videoplayback?mt=1448075110&mv=m&initcwndbps=180000&itag=43&ms=au&upn=hhv_O7PIcl0&pcm2=no&mm=31&mn=sn-o0x85uxa-a2ce&expire=1448096854&mime=video%2Fwebm&pl=20&source=youtube&ratebypass=yes&dur=0.000&lmt=1367614381944548&key=yt6&ipbits=0&gcr=bo&sparams=dur%2Cgcr%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpcm2%2Cpcm2cms%2Cpl%2Cratebypass%2Csource%2Cupn%2Cexpire&fexp=9407156%2C9408710%2C9413137%2C9416126%2C9417683%2C9419445%2C9419837%2C9420452%2C9421097%2C9421166%2C9421411%2C9422323%2C9422541%2C9422596%2C9422618%2C9422838%2C9422992%2C9423042%2C9423431%2C9423489%2C9423643%2C9423662%2C9423667%2C9424509%2C9424740&id=o-APsq1d2t11trGfv2qYsVS9NyPHMMqsQcMSBaV7pEXwYP&sver=3&ip=161.22.129.235&signature=554A1CF81CD9B1BA71DCD24B2FCD5A0AE436A91E.937BA2CFC7599B38359F410DB6C3A15BE977131E&pcm2cms=yes&signature=&type=video/webm; codecs="vp8.0, vorbis"&title=Imagine Dragons - Demons (Official)
Formato: webm
Calidad: medium
*************************
Url: http://r1---sn-o0x85uxa-a2ce.googlevideo.com/videoplayback?mt=1448075110&mv=m&initcwndbps=180000&itag=18&ms=au&upn=hhv_O7PIcl0&pcm2=no&mm=31&mn=sn-o0x85uxa-a2ce&expire=1448096854&mime=video%2Fmp4&pl=20&source=youtube&ratebypass=yes&dur=236.170&lmt=1429535713281062&key=yt6&ipbits=0&gcr=bo&sparams=dur%2Cgcr%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpcm2%2Cpcm2cms%2Cpl%2Cratebypass%2Csource%2Cupn%2Cexpire&fexp=9407156%2C9408710%2C9413137%2C9416126%2C9417683%2C9419445%2C9419837%2C9420452%2C9421097%2C9421166%2C9421411%2C9422323%2C9422541%2C9422596%2C9422618%2C9422838%2C9422992%2C9423042%2C9423431%2C9423489%2C9423643%2C9423662%2C9423667%2C9424509%2C9424740&id=o-APsq1d2t11trGfv2qYsVS9NyPHMMqsQcMSBaV7pEXwYP&sver=3&ip=161.22.129.235&signature=D2B70E8991B19CB7C9485ACE6B3BBEDD33E0723F.568B020038DC5E2E55DDEE030D20904A49C60CA1&pcm2cms=yes&signature=&type=video/mp4; codecs="avc1.42001E, mp4a.40.2"&title=Imagine Dragons - Demons (Official)
Formato: mp4
Calidad: medium
*************************
Url: http://r1---sn-o0x85uxa-a2ce.googlevideo.com/videoplayback?mt=1448075110&mv=m&initcwndbps=180000&itag=5&ms=au&upn=hhv_O7PIcl0&sparams=dur%2Cgcr%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpcm2%2Cpcm2cms%2Cpl%2Csource%2Cupn%2Cexpire&mm=31&mn=sn-o0x85uxa-a2ce&expire=1448096854&pcm2=no&mime=video%2Fx-flv&pl=20&source=youtube&dur=236.173&lmt=1394291864022235&key=yt6&ipbits=0&gcr=bo&fexp=9407156%2C9408710%2C9413137%2C9416126%2C9417683%2C9419445%2C9419837%2C9420452%2C9421097%2C9421166%2C9421411%2C9422323%2C9422541%2C9422596%2C9422618%2C9422838%2C9422992%2C9423042%2C9423431%2C9423489%2C9423643%2C9423662%2C9423667%2C9424509%2C9424740&id=o-APsq1d2t11trGfv2qYsVS9NyPHMMqsQcMSBaV7pEXwYP&sver=3&ip=161.22.129.235&signature=8D3DBB8B362B16C5061F3400DE492270A3B5E015.958915343DB674110377E1F86EAA543A430485F4&pcm2cms=yes&signature=&type=video/x-flv&title=Imagine Dragons - Demons (Official)
Formato: flv
Calidad: small
*************************
Url: http://r1---sn-o0x85uxa-a2ce.googlevideo.com/videoplayback?mt=1448075110&mv=m&initcwndbps=180000&itag=36&ms=au&upn=hhv_O7PIcl0&sparams=dur%2Cgcr%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpcm2%2Cpcm2cms%2Cpl%2Csource%2Cupn%2Cexpire&mm=31&mn=sn-o0x85uxa-a2ce&expire=1448096854&pcm2=no&mime=video%2F3gpp&pl=20&source=youtube&dur=236.286&lmt=1394291766906263&key=yt6&ipbits=0&gcr=bo&fexp=9407156%2C9408710%2C9413137%2C9416126%2C9417683%2C9419445%2C9419837%2C9420452%2C9421097%2C9421166%2C9421411%2C9422323%2C9422541%2C9422596%2C9422618%2C9422838%2C9422992%2C9423042%2C9423431%2C9423489%2C9423643%2C9423662%2C9423667%2C9424509%2C9424740&id=o-APsq1d2t11trGfv2qYsVS9NyPHMMqsQcMSBaV7pEXwYP&sver=3&ip=161.22.129.235&signature=04F7754230405A8FC022D3537A2E316F4323C905.9A15CDF618BEB230096EE39F0EC26DAC16900FAE&pcm2cms=yes&signature=&type=video/3gpp; codecs="mp4v.20.3, mp4a.40.2"&title=Imagine Dragons - Demons (Official)
Formato: 3gpp
Calidad: small
*************************
Url: http://r1---sn-o0x85uxa-a2ce.googlevideo.com/videoplayback?mt=1448075110&mv=m&initcwndbps=180000&itag=17&ms=au&upn=hhv_O7PIcl0&sparams=dur%2Cgcr%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpcm2%2Cpcm2cms%2Cpl%2Csource%2Cupn%2Cexpire&mm=31&mn=sn-o0x85uxa-a2ce&expire=1448096854&pcm2=no&mime=video%2F3gpp&pl=20&source=youtube&dur=236.472&lmt=1394291698741556&key=yt6&ipbits=0&gcr=bo&fexp=9407156%2C9408710%2C9413137%2C9416126%2C9417683%2C9419445%2C9419837%2C9420452%2C9421097%2C9421166%2C9421411%2C9422323%2C9422541%2C9422596%2C9422618%2C9422838%2C9422992%2C9423042%2C9423431%2C9423489%2C9423643%2C9423662%2C9423667%2C9424509%2C9424740&id=o-APsq1d2t11trGfv2qYsVS9NyPHMMqsQcMSBaV7pEXwYP&sver=3&ip=161.22.129.235&signature=864F4C8D6C43652AA8CE344C5DBD12CA1B88FFBE.1996D808B12B0ED01CF517E5736FF2F9D0872855&pcm2cms=yes&signature=&type=video/3gpp; codecs="mp4v.20.3, mp4a.40.2"&title=Imagine Dragons - Demons (Official)
Formato: 3gpp
Calidad: small



Update: 27/03/2016
Add->Method: ConvertYoutubeToMp3


Código: vbnet

' ***********************************************************************
' Assembly         : Youtube Downloader by fudmario
' Author           : fudmario
' Created          : 15-06-2015
'
' Last Modified By : fudmario
' Last Modified On : 03-27-2016
' ***********************************************************************
' <copyright file="YoutubeHelper.vb" company="DeveloperTeam">
'     Copyright ©  2016
' </copyright>
' <summary></summary>
' *************************************************************************

Option Explicit On
Option Strict On
Option Infer On

Imports System.Collections.Specialized
Imports System.Net
Imports System.Text
Imports System.Text.RegularExpressions
Imports System.Web.Script.Serialization
Imports System.Web.HttpUtility
Imports System.Threading

''' <summary>
''' Class YoutubeHelper. This class cannot be inherited.
''' </summary>
''' <autogeneratedoc />
Public NotInheritable Class YoutubeHelper
    ''' <summary>
    ''' Address to Get Video Information
    ''' </summary>
    Private Const InfoUrl As String = "http://www.youtube.com/get_video_info?video_id="

    ''' <summary>
    ''' Regular expression to get Image Url.
    ''' </summary>
    ''' <value>Image Url.</value>
    Private Shared ReadOnly Property Imagen As Regex
        Get
            Return New Regex("<meta\sproperty=""og:image""\scontent=""(.*?default\.jpg)"">")
        End Get
    End Property

    ''' <summary>
    ''' Regular expression for the title of the video.
    ''' </summary>
    ''' <value>title of the video.</value>
    Private Shared ReadOnly Property Title As Regex
        Get
            Return New Regex("<meta\sproperty=""og:title""\scontent=""(.*?)"">")
        End Get
    End Property

    ''' <summary>
    ''' Regular expression for video description.
    ''' </summary>
    ''' <value>video description.</value>
    Private Shared ReadOnly Property Description As Regex
        Get
            Return New Regex("<meta\sproperty=""og:description""\scontent=""(.*?)"">")
        End Get
    End Property

    ''' <summary>
    ''' Regular expression for video length(in seconds).
    ''' </summary>
    ''' <value>video length(in seconds).</value>
    Private Shared ReadOnly Property Duration As Regex
        Get
            Return New Regex("length_seconds"":""(.*?)"",")
        End Get
    End Property
    ''' <summary>
    ''' Regular expression to validate an address Youtube.
    ''' </summary>
    ''' <value>validate an address Youtube.</value>
    ''' <autogeneratedoc />
    Private Shared ReadOnly Property YouTubeUrl() As Regex
        Get
            Return New Regex("(http|https):..(www\.)?youtube.com.watch\?v=")
        End Get
    End Property
    ''' <summary>
    ''' Gets the Id of YouTube Video.
    ''' </summary>
    ''' <param name="url">YouTube Video Address.</param>
    ''' <returns>System.String.</returns>
    ''' <autogeneratedoc />
    Private Shared Function GetId(url As String) As String
        Return ParseQueryString(New Uri(url).Query).Get("v")
    End Function

    ''' <summary>
    ''' Get YouTube Video Information.
    ''' </summary>
    ''' <param name="url">YouTube Video Address.</param>
    ''' <param name="byPass">If set to <c>true</c> apply the bypass.</param>
    ''' <returns>YouTubeVideoInformation.</returns>
    ''' <exception cref="ArgumentNullException">The <paramref name="url" /> can not be empty</exception>
    ''' <exception cref="FormatException">Invalid <paramref name="url" /> format</exception>
    Public Shared Function GetYouTubeVideoInfo(url As String, Optional ByVal byPass As Boolean = False) As YouTubeVideoInformation

        If String.IsNullOrEmpty(url) Then Throw New ArgumentNullException(message:="The URL can not be empty", paramName:="URL")

        If Not YouTubeUrl.IsMatch(url) Then Throw New FormatException(message:="Invalid URL format")

        Dim videoInfoFull As New YouTubeVideoInformation
        Dim infoVideo As New List(Of YoutubeVideoInfo)
        Dim adInfoVideo As YoutubeVideoInfo
        Dim mSource As String
        Dim arrayParams As NameValueCollection

        Using c As New WebClient
            c.Encoding = Encoding.GetEncoding(1252)
            mSource = c.DownloadString(url)

            Select Case byPass
                Case True
                    arrayParams = ParseQueryString(HtmlDecode(c.DownloadString(String.Format("{0}{1}&el=vevo", InfoUrl, GetId(url)))))
                Case Else
                    arrayParams = ParseQueryString(HtmlDecode(c.DownloadString(String.Format("{0}{1}", InfoUrl, GetId(url)))))
            End Select
        End Using

        Dim ytTitle As String = HtmlDecode(Title.Match(mSource).Groups(1).Value)
        Dim ytDescription As String = HtmlDecode(Description.Match(mSource).Groups(1).Value)
        Dim ytDuration As Double = CDbl(Duration.Match(mSource).Groups(1).Value)
        Dim ytImg As String = Imagen.Match(mSource).Groups(1).Value

        If Not arrayParams("status").Equals("ok") Then
            videoInfoFull.ErrorCode = 1
            videoInfoFull.ErrorMsg = HtmlDecode(arrayParams("reason"))

        Else
            Dim urLs As String() = arrayParams("url_encoded_fmt_stream_map").Split(","c)
            Dim sb As New StringBuilder()
            For i = 0 To urLs.Length - 1
                adInfoVideo = New YoutubeVideoInfo()
                sb.Clear()
                Dim mUriDec As String = HtmlDecode(urLs(i))
                Dim urlParams As NameValueCollection = ParseQueryString(mUriDec)
                Dim vidFormat As String = HtmlDecode(urlParams("type"))
                sb.Append(HtmlDecode(urlParams("Url")))
                sb.AppendFormat("&signature={0}", HtmlDecode(urlParams("sig")))
                sb.AppendFormat("&type={0}", vidFormat)
                sb.AppendFormat("&title={0}", HtmlDecode(arrayParams("title")))

                Dim format As String = vidFormat.Split(";"c)(0).Split("/"c)(1)
                If format.Contains("x-flv") Then
                    format = "flv"
                End If

                adInfoVideo.Url = sb.ToString
                adInfoVideo.Quality = urlParams("quality")
                adInfoVideo.Format = format
                infoVideo.Add(adInfoVideo)
            Next
            videoInfoFull.ErrorCode = 0
            videoInfoFull.LinksDetails = infoVideo
            videoInfoFull.Title = ytTitle
            videoInfoFull.Duration = ytDuration
            videoInfoFull.Description = ytDescription
            videoInfoFull.ImgLink = ytImg

        End If
        Return videoInfoFull
    End Function
    ''' <summary>
    ''' Converts the youtube to MP3.
    ''' </summary>
    ''' <param name="url">YouTube Video Address.</param>
    ''' <param name="interval">Request interval in seconds</param>
    ''' <returns>ResponseAudio.</returns>
    ''' <exception cref="FormatException"></exception>
    ''' <autogeneratedoc />
    Public Shared Function ConvertYoutubeToMp3(ByVal url As String, Optional interval As Integer = 2) As ResponseAudio
        If Not YouTubeUrl.IsMatch(url) Then Throw New FormatException(message:="Invalid URL format")
        Dim result As String
        Dim serializer As New JavaScriptSerializer()
        Dim response As ResponseAudio

        Dim query As String = String.Format("http://embed.yt-mp3.com/fetch?v={0}&referrer=", GetId(url))
        Using wc As New WebClient()
            result = wc.DownloadString(query)
            response = serializer.Deserialize(Of ResponseAudio)(result)
            While Not (response.status.Equals("ok") AndAlso response.ready = True)
                Thread.Sleep(interval * 1000)
                result = wc.DownloadString(query)
                response = serializer.Deserialize(Of ResponseAudio)(result)
            End While

            Return response
        End Using

    End Function
    ''' <summary>
    ''' Basic Video Information.
    ''' </summary>
    Public Class YoutubeVideoInfo
        ''' <summary>
        ''' Gets or sets the URL Direct Video.
        ''' </summary>
        ''' <value> URL Direct Video.</value>
        Public Property Url() As String
        ''' <summary>
        ''' Gets or sets the Video Format.
        ''' </summary>
        ''' <value>Video Format.</value>
        Public Property Format() As String

        ''' <summary>
        ''' Gets or sets the Video Quality.
        ''' </summary>
        ''' <value>Video Quality.</value>
        Public Property Quality() As String

    End Class

    ''' <summary>
    ''' Complete YouTube Video Information.
    ''' </summary>
    Public Class YouTubeVideoInformation
        ''' <summary>
        ''' Gets or sets the list of Link's available and additional information.
        ''' </summary>
        ''' <value>list of Link's available and additional information.</value>
        Public Property LinksDetails() As List(Of YoutubeVideoInfo)

        ''' <summary>
        ''' Gets or sets the Title Video.
        ''' </summary>
        ''' <value>Title Video.</value>
        Public Property Title() As String

        ''' <summary>
        ''' Gets or sets the Image Url.
        ''' </summary>
        ''' <value> Image Url.</value>
        Public Property ImgLink() As String

        ''' <summary>
        ''' Gets or sets the description of Video.
        ''' </summary>
        ''' <value>description of Video.</value>
        Public Property Description() As String

        ''' <summary>
        ''' Gets or sets the duration of Video.
        ''' </summary>
        ''' <value>duration of Video.</value>
        Public Property Duration() As Double
        ''' <summary>
        ''' Gets or sets the error code: 0 = No Error, 1 = Error.
        ''' </summary>
        ''' <value>error code.</value>
        Public Property ErrorCode() As Integer

        ''' <summary>
        ''' Gets or sets the error message.
        ''' </summary>
        ''' <value>error message.</value>
        Public Property ErrorMsg() As String
    End Class
    ''' <summary>
    ''' Class ResponseAudio.
    ''' </summary>
    Public Class ResponseAudio
        ''' <summary>
        ''' Gets or sets the status.
        ''' </summary>
        ''' <value>The status.</value>
        ''' <autogeneratedoc />
        Public Property status As String

        ''' <summary>
        ''' Gets or sets the identifier.
        ''' </summary>
        ''' <value>The identifier.</value>
        ''' <autogeneratedoc />
        Public Property id As String

        ''' <summary>
        ''' Gets or sets the title.
        ''' </summary>
        ''' <value>The title.</value>
        ''' <autogeneratedoc />
        Public Property title As String

        ''' <summary>
        ''' Gets or sets the thumbnail.
        ''' </summary>
        ''' <value>The thumbnail.</value>
        ''' <autogeneratedoc />
        Public Property thumbnail As String

        ''' <summary>
        ''' Gets or sets the length of time in seconds.
        ''' </summary>
        ''' <value>The length.</value>
        Public Property length As Integer

        ''' <summary>
        ''' Gets or sets the name artist.
        ''' </summary>
        ''' <value>The artist.</value>
        Public Property artist As String

        ''' <summary>
        ''' Gets or sets the categories.
        ''' </summary>
        ''' <value>The categories.</value>
        ''' <autogeneratedoc />
        Public Property categories As String

        ''' <summary>
        ''' Gets or sets the bitrate(kbps).
        ''' </summary>
        ''' <value>The bitrate (kbps).</value>
        ''' <autogeneratedoc />
        Public Property bitrate As String

        ''' <summary>
        ''' Gets or sets the average rating.
        ''' </summary>
        ''' <value>The average_rating.</value>
        Public Property average_rating As String

        ''' <summary>
        ''' Gets or sets the view count.
        ''' </summary>
        ''' <value>The view_count.</value>
        Public Property view_count As String

        ''' <summary>
        ''' Gets or sets the progress.
        ''' </summary>
        ''' <value>The progress.</value>
        ''' <autogeneratedoc />
        Public Property progress As Integer

        ''' <summary>
        ''' Gets or sets a value indicating whether this <see cref="ResponseAudio" /> is ready.
        ''' </summary>
        ''' <value><c>true</c> if ready; otherwise, <c>false</c>.</value>
        ''' <autogeneratedoc />
        Public Property ready As Boolean

        ''' <summary>
        ''' Gets or sets the expires.
        ''' </summary>
        ''' <value>The expires.</value>
        ''' <autogeneratedoc />
        Public Property expires As Integer

        ''' <summary>
        ''' Gets or sets the URL of MP3.
        ''' </summary>
        ''' <value>The URL.</value>
        Public Property url As String

        ''' <summary>
        ''' Gets or sets the video Information.
        ''' </summary>
        ''' <value>The video Information.</value>
        Public Property video_url As String
    End Class
End Class


How to Use:

Código: vbnet

        Dim res As YoutubeHelper.ResponseAudio = YoutubeHelper.ConvertYoutubeToMp3("https://www.youtube.com/watch?v=mWRsgZuwf_8")
        Dim sb As New System.Text.StringBuilder()
        sb.AppendLine(String.Format("ID..............: {0}", res.id))
        sb.AppendLine(String.Format("Title...........: {0}", res.title))
        sb.AppendLine(String.Format("Artist..........: {0}", res.artist))
        sb.AppendLine(String.Format("Length(sec).....: {0}", res.length))
        sb.AppendLine(String.Format("Bitrate(Kbps)...: {0}", res.bitrate))
        sb.AppendLine(String.Format("Categories......: {0}", res.categories))
        sb.AppendLine(String.Format("Average Rating..: {0}", res.average_rating))
        sb.AppendLine(String.Format("Ready?..........: {0}", res.ready))
        sb.AppendLine(String.Format("MP3 Url.........: {0}", res.url))
        MessageBox.Show(sb.ToString())



Return:
Código: php

ID..............: mWRsgZuwf_8
Title...........: Imagine Dragons - Demons (Official)
Artist..........: ImagineDragonsVEVO
Length(sec).....: 237
Bitrate(Kbps)...: 211
Categories......: Music
Average Rating..: 4.913
Ready?..........: True
MP3 Url.........: http://dl2.yt-mp3.com/download/imagine-dragons-demons-official.mp3?id=mWRsgZuwf_8&title=Imagine+Dragons+-+Demons+%28Official%29&t=1459086715&extra=a&h=7c6ea7b8be176f673a3b46d797b3a9a89d18c5ca