• Earn real money by being active: Hello Guest, earn real money by simply being active on the forum — post quality content, get reactions, and help the community. Once you reach the minimum credit amount, you’ll be able to withdraw your balance directly. Learn how it works.

.NET [VB.NET] YouTubeHelper by fudmario

Status
Not open for further replies.

fudmario

Leech
User
Joined
Feb 23, 2013
Messages
202
Reputation
0
Reaction score
1,098
Points
143
Credits
0
‎12 Years of Service‎
68%
[HIDE-THANKS][LENGUAJE=vbnet]

' ***********************************************************************

' Assembly : Youtube Downloader

' Author : fudmario

' Created : 15-06-2015

'

' Last Modified By : fudmario

' Last Modified On : 11-20-2015

' ***********************************************************************

'

' ' Copyright © 2015

'

'

'

' *************************************************************************

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

'''

''' Class YoutubeHelper. Esta Clase no puede ser Heredada.

'''

Public NotInheritable Class YoutubeHelper

'''

''' Url para Obtener la Información del Video

'''

Private Const InfoUrl As String = "http://www.youtube.com/get_video_info?video_id="

'''

''' Expresión Regular para obtener el Link de la imagen del Video.

'''

''' The imagen.

Private Shared ReadOnly Property Imagen As Regex

Get

Return New Regex("")

End Get

End Property

'''

''' Expresion Regular para Obtener el Título del video.

'''

''' The title.

Private Shared ReadOnly Property Title As Regex

Get

Return New Regex("")

End Get

End Property

'''

''' Expresion Regular para obtener la Descripción del Video.

'''

''' Descripción del Video.

Private Shared ReadOnly Property Description As Regex

Get

Return New Regex("")

End Get

End Property

'''

''' Expresion Regular para obtener la Duracion del Video (en segundos).

'''

''' Duracion del Video (en segundos).

Private Shared ReadOnly Property Duration As Regex

Get

Return New Regex("length_seconds"":""(.*?)"",")

End Get

End Property

'''

''' Obtiene Informacion sobre la Url de Video de Youtube.

'''

''' Url del Video de YouTube.

''' Si se establece como true aplicamos el bypass.

''' YouTubeVideoInformation.

''' La no puede estar vacia;url

''' Formato de Invalido;Url

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

'''

''' Información Básica del Video.

'''

Public Class YoutubeVideoInfo

'''

''' Obtiene o Establece la Url Directa del Video.

'''

''' Url Directa del Video.

Public Property Url() As String

'''

''' Obtiene o Establece el Formato del Video.

'''

''' Formato del Video.

Public Property Format() As String

'''

''' Obtiene o Establece La Calidad del Video.

'''

''' Calidad del Video.

Public Property Quality() As String

End Class

'''

''' Información Completa del Video de YouTube.

'''

Public Class YouTubeVideoInformation

'''

''' Obtiene o Establece la lista de Link's Disponibles y Informacion Adicional.

'''

''' lista de Link's Disponibles.

Public Property LinksDetails() As List(Of YoutubeVideoInfo)

'''

''' Obtiene o Establece El Titulo del Video.

'''

''' El Titulo del Video.

Public Property Title() As String

'''

''' Obtiene o Establece El link de la Imagen del Video.

'''

''' El link de la Imagen del Video.

Public Property ImgLink() As String

'''

''' Obtiene o Establece la Descripción del Video.

'''

''' la Descripción del Video.

Public Property Description() As String

'''

''' Obtiene o Establece la Duracion del Video.

'''

''' Duracion del Video.

Public Property Duration() As Double

'''

''' Obtiene o Establece el codigo de Error: 0 = No Error, 1 = Error.

'''

''' codigo de Error: 0 = No Error, 1 = Error..

Public Property ErrorCode() As Integer

'''

''' Obtiene o Establece el Mensaje de Error.

'''

''' Mensaje de Error.

Public Property ErrorMsg() As String

End Class

[/LENGUAJE][/HIDE-THANKS]

  • [li]Ejemplo de Uso:[/li]


[LENGUAJE=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[/LENGUAJE]

  • [li]Retorna:

    [/li]
     



Code:
>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
 
Last edited by a moderator:
Status
Not open for further replies.
Back
Top