comment
IRC Chat
play_arrow
Este sitio utiliza cookies propias y de terceros. Si continúa navegando consideramos que acepta el uso de cookies. OK Más Información.

[Vb.Net] YouTubeHelper by fudmario

  • 1 Respuestas
  • 1961 Vistas

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

Desconectado fudmario

  • *
  • Cramel
  • *
  • Mensajes: 194
  • Actividad:
    1.67%
  • Reputación 11
    • Ver Perfil
    • fudmario - GitHub
  • Skype: fudmario
« en: Noviembre 21, 2015, 12:22:57 am »
Código: vb.net
  1. ' ***********************************************************************
  2. ' Assembly         : Youtube Downloader
  3. ' Author           : fudmario
  4. ' Created          : 15-06-2015
  5. '
  6. ' Last Modified By : fudmario
  7. ' Last Modified On : 11-20-2015
  8. ' ***********************************************************************
  9. ' <copyright file="YoutubeHelper.vb" company="FudmarioDev">
  10. '     '     Copyright ©  2015
  11. '
  12. ' </copyright>
  13. ' <summary></summary>
  14. ' *************************************************************************
  15.  
  16. Option Explicit On
  17. Option Strict On
  18. Option Infer On
  19.  
  20. Imports System.Collections.Specialized
  21. Imports System.Net
  22. Imports System.Text
  23. Imports System.Text.RegularExpressions
  24. Imports System.Web
  25.  
  26. ''' <summary>
  27. ''' Class YoutubeHelper. Esta Clase no puede ser Heredada.
  28. ''' </summary>
  29. Public NotInheritable Class YoutubeHelper
  30.     ''' <summary>
  31.     ''' Url para Obtener la Información del Video
  32.     ''' </summary>
  33.     Private Const InfoUrl As String = "http://www.youtube.com/get_video_info?video_id="
  34.  
  35.     ''' <summary>
  36.     ''' Expresión Regular para obtener el Link de la imagen del Video.
  37.     ''' </summary>
  38.     ''' <value>The imagen.</value>
  39.     Private Shared ReadOnly Property Imagen As Regex
  40.         Get
  41.             Return New Regex("<meta\sproperty=""og:image""\scontent=""(.*?default\.jpg)"">")
  42.         End Get
  43.     End Property
  44.  
  45.     ''' <summary>
  46.     ''' Expresion Regular para Obtener el Título del video.
  47.     ''' </summary>
  48.     ''' <value>The title.</value>
  49.     Private Shared ReadOnly Property Title As Regex
  50.         Get
  51.             Return New Regex("<meta\sproperty=""og:title""\scontent=""(.*?)"">")
  52.         End Get
  53.     End Property
  54.  
  55.     ''' <summary>
  56.     ''' Expresion Regular para obtener la Descripción del Video.
  57.     ''' </summary>
  58.     ''' <value>Descripción del Video.</value>
  59.     Private Shared ReadOnly Property Description As Regex
  60.         Get
  61.             Return New Regex("<meta\sproperty=""og:description""\scontent=""(.*?)"">")
  62.         End Get
  63.     End Property
  64.  
  65.     ''' <summary>
  66.     ''' Expresion Regular para obtener la Duracion del Video (en segundos).
  67.     ''' </summary>
  68.     ''' <value> Duracion del Video (en segundos).</value>
  69.     Private Shared ReadOnly Property Duration As Regex
  70.         Get
  71.             Return New Regex("length_seconds"":""(.*?)"",")
  72.         End Get
  73.     End Property
  74.        
  75.         ''' <summary>
  76.     ''' Obtiene Informacion sobre la Url de Video de Youtube.
  77.     ''' </summary>
  78.     ''' <param name="url">Url del Video de YouTube.</param>
  79.     ''' <param name="byPass">Si se establece como <c>true</c> aplicamos el bypass.</param>
  80.     ''' <returns>YouTubeVideoInformation.</returns>
  81.     ''' <exception cref="ArgumentNullException">La <paramref name="url" /> no puede estar vacia;url</exception>
  82.     ''' <exception cref="FormatException">Formato de <paramref name="url" /> Invalido;Url</exception>
  83.     Public Shared Function GetYouTubeVideoInfo(url As String, Optional ByVal byPass As Boolean = False) As YouTubeVideoInformation
  84.  
  85.         If String.IsNullOrEmpty(url) Then Throw New ArgumentNullException(message:="La Url no puede estar vacia", paramName:="URL")
  86.  
  87.         If Not Regex.IsMatch(url, "(http|https):..(www\.)?youtube.com.watch\?v=") Then Throw New FormatException(message:="Formato de Url Invalido")
  88.  
  89.         Dim videoInfoFull As New YouTubeVideoInformation
  90.         Dim infoVideo As New List(Of YoutubeVideoInfo)
  91.         Dim adInfoVideo As YoutubeVideoInfo
  92.         Dim mSource As String
  93.         Dim arrayParams As NameValueCollection
  94.  
  95.         Using c As New WebClient
  96.             c.Encoding = Encoding.GetEncoding(1252)
  97.             mSource = c.DownloadString(url)
  98.  
  99.             Select Case byPass
  100.                 Case True
  101.                     arrayParams = HttpUtility.ParseQueryString(HttpUtility.HtmlDecode(c.DownloadString(String.Format("{0}{1}&el=vevo", InfoUrl, HttpUtility.ParseQueryString(New Uri(url).Query).Get("v")))))
  102.                 Case Else
  103.                     arrayParams = HttpUtility.ParseQueryString(HttpUtility.HtmlDecode(c.DownloadString(String.Format("{0}{1}", InfoUrl, HttpUtility.ParseQueryString(New Uri(url).Query).Get("v")))))
  104.             End Select
  105.         End Using
  106.  
  107.         Dim ytTitle As String = HttpUtility.HtmlDecode(Title.Match(mSource).Groups(1).Value)
  108.         Dim ytDescription As String = HttpUtility.HtmlDecode(Description.Match(mSource).Groups(1).Value)
  109.         Dim ytDuration As Double = CDbl(Duration.Match(mSource).Groups(1).Value)
  110.         Dim ytImg As String = Imagen.Match(mSource).Groups(1).Value
  111.  
  112.         If arrayParams("status") = "ok" Then
  113.  
  114.             Dim urLs As String() = arrayParams("url_encoded_fmt_stream_map").Split(","c)
  115.             Dim sb As New StringBuilder()
  116.             For i = 0 To urLs.Length - 1
  117.                 adInfoVideo = New YoutubeVideoInfo()
  118.                 sb.Clear()
  119.                 Dim mUriDec As String = HttpUtility.HtmlDecode(urLs(i))
  120.                 Dim urlParams As NameValueCollection = HttpUtility.ParseQueryString(mUriDec)
  121.                 Dim vidFormat As String = HttpUtility.HtmlDecode(urlParams("type"))
  122.                 sb.Append(HttpUtility.HtmlDecode(urlParams("Url")))
  123.                 sb.AppendFormat("&signature={0}", HttpUtility.HtmlDecode(urlParams("sig")))
  124.                 sb.AppendFormat("&type={0}", vidFormat)
  125.                 sb.AppendFormat("&title={0}", HttpUtility.HtmlDecode(arrayParams("title")))
  126.  
  127.                 Dim format As String = vidFormat.Split(";"c)(0).Split("/"c)(1)
  128.                 If format.Contains("x-flv") Then
  129.                     format = "flv"
  130.                 End If
  131.  
  132.                 adInfoVideo.Url = sb.ToString
  133.                 adInfoVideo.Quality = urlParams("quality")
  134.                 adInfoVideo.Format = format
  135.                 infoVideo.Add(adInfoVideo)
  136.             Next
  137.             videoInfoFull.ErrorCode = 0
  138.             videoInfoFull.LinksDetails = infoVideo
  139.             videoInfoFull.Title = ytTitle
  140.             videoInfoFull.Duration = ytDuration
  141.             videoInfoFull.Description = ytDescription
  142.             videoInfoFull.ImgLink = ytImg
  143.             Return videoInfoFull
  144.         Else
  145.             videoInfoFull.ErrorCode = 1
  146.             videoInfoFull.ErrorMsg = HttpUtility.HtmlDecode(arrayParams("reason"))
  147.             Return videoInfoFull
  148.         End If
  149.  
  150.     End Function
  151. End Class
  152.  
  153. ''' <summary>
  154. ''' Información Básica del Video.
  155. ''' </summary>
  156. Public Class YoutubeVideoInfo
  157.     ''' <summary>
  158.     ''' Obtiene o Establece la Url Directa del Video.
  159.     ''' </summary>
  160.     ''' <value>Url Directa del Video.</value>
  161.     Public Property Url() As String
  162.     ''' <summary>
  163.     ''' Obtiene o Establece el Formato del Video.
  164.     ''' </summary>
  165.     ''' <value>Formato del Video.</value>
  166.     Public Property Format() As String
  167.  
  168.     ''' <summary>
  169.     ''' Obtiene o Establece La Calidad del Video.
  170.     ''' </summary>
  171.     ''' <value>Calidad del Video.</value>
  172.     Public Property Quality() As String
  173.  
  174. End Class
  175.  
  176. ''' <summary>
  177. ''' Información Completa del Video de YouTube.
  178. ''' </summary>
  179. Public Class YouTubeVideoInformation
  180.     ''' <summary>
  181.     ''' Obtiene o Establece la lista de Link's Disponibles y Informacion Adicional.
  182.     ''' </summary>
  183.     ''' <value>lista de Link's Disponibles.</value>
  184.     Public Property LinksDetails() As List(Of YoutubeVideoInfo)
  185.  
  186.     ''' <summary>
  187.     ''' Obtiene o Establece El Titulo del Video.
  188.     ''' </summary>
  189.     ''' <value>El Titulo del Video.</value>
  190.     Public Property Title() As String
  191.  
  192.     ''' <summary>
  193.     ''' Obtiene o Establece El link de la Imagen del Video.
  194.     ''' </summary>
  195.     ''' <value>El link de la Imagen del Video.</value>
  196.     Public Property ImgLink() As String
  197.  
  198.     ''' <summary>
  199.     ''' Obtiene o Establece la Descripción del Video.
  200.     ''' </summary>
  201.     ''' <value>la Descripción del Video.</value>
  202.     Public Property Description() As String
  203.  
  204.     ''' <summary>
  205.     ''' Obtiene o Establece la Duracion del Video.
  206.     ''' </summary>
  207.     ''' <value>Duracion del Video.</value>
  208.     Public Property Duration() As Double
  209.     ''' <summary>
  210.     ''' Obtiene o Establece el codigo de Error: 0 = No Error, 1 = Error.
  211.     ''' </summary>
  212.     ''' <value>codigo de Error: 0 = No Error, 1 = Error..</value>
  213.     Public Property ErrorCode() As Integer
  214.  
  215.     ''' <summary>
  216.     ''' Obtiene o Establece el Mensaje de Error.
  217.     ''' </summary>
  218.     ''' <value>Mensaje de Error.</value>
  219.     Public Property ErrorMsg() As String
  220. End Class
  221.  



  • Ejemplo de Uso:

Código: vb.net
  1. Dim response As YouTubeVideoInformation
  2.         response = YoutubeHelper.GetYouTubeVideoInfo("[youtube]https://www.youtube.com/watch?v=mWRsgZuwf_8[/youtube]", True)
  3.         If response.ErrorCode = 0 Then
  4.  
  5.             Dim sb As New System.Text.StringBuilder
  6.             sb.AppendLine(String.Format("Titulo: {0}", response.Title))
  7.             sb.AppendLine(String.Format("Descripción: {0}", response.Description))
  8.             sb.AppendLine(String.Format("Duración: {0}", TimeSpan.FromSeconds(response.Duration).ToString("hh\:mm\:ss")))
  9.             sb.AppendLine(String.Format("Url de la Imagen: {0}", response.ImgLink))
  10.             sb.AppendLine()
  11.             sb.AppendLine("Urls: ")
  12.             For Each urldetails As YoutubeVideoInfo In response.LinksDetails
  13.  
  14.                 sb.AppendLine("*************************")
  15.                 sb.AppendLine(String.Format("Url: {0}", urldetails.Url))
  16.                 sb.AppendLine(String.Format("Formato: {0}", urldetails.Format))
  17.                 sb.AppendLine(String.Format("Calidad: {0}", urldetails.Quality))
  18.  
  19.             Next
  20.             MessageBox.Show(sb.ToString)
  21.         Else
  22.             MessageBox.Show(response.ErrorMsg)
  23.         End If
      
  • Retorna:

Código: [Seleccionar]
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


Desconectado fudmario

  • *
  • Cramel
  • *
  • Mensajes: 194
  • Actividad:
    1.67%
  • Reputación 11
    • Ver Perfil
    • fudmario - GitHub
  • Skype: fudmario
« Respuesta #1 en: Marzo 27, 2016, 11:17:49 am »
Update: 27/03/2016
Add->Method: ConvertYoutubeToMp3


Código: vb.net
  1. ' ***********************************************************************
  2. ' Assembly         : Youtube Downloader by fudmario
  3. ' Author           : fudmario
  4. ' Created          : 15-06-2015
  5. '
  6. ' Last Modified By : fudmario
  7. ' Last Modified On : 03-27-2016
  8. ' ***********************************************************************
  9. ' <copyright file="YoutubeHelper.vb" company="DeveloperTeam">
  10. '     Copyright ©  2016
  11. ' </copyright>
  12. ' <summary></summary>
  13. ' *************************************************************************
  14.  
  15. Option Explicit On
  16. Option Strict On
  17. Option Infer On
  18.  
  19. Imports System.Collections.Specialized
  20. Imports System.Net
  21. Imports System.Text
  22. Imports System.Text.RegularExpressions
  23. Imports System.Web.Script.Serialization
  24. Imports System.Web.HttpUtility
  25. Imports System.Threading
  26.  
  27. ''' <summary>
  28. ''' Class YoutubeHelper. This class cannot be inherited.
  29. ''' </summary>
  30. ''' <autogeneratedoc />
  31. Public NotInheritable Class YoutubeHelper
  32.     ''' <summary>
  33.     ''' Address to Get Video Information
  34.     ''' </summary>
  35.     Private Const InfoUrl As String = "http://www.youtube.com/get_video_info?video_id="
  36.  
  37.     ''' <summary>
  38.     ''' Regular expression to get Image Url.
  39.     ''' </summary>
  40.     ''' <value>Image Url.</value>
  41.     Private Shared ReadOnly Property Imagen As Regex
  42.         Get
  43.             Return New Regex("<meta\sproperty=""og:image""\scontent=""(.*?default\.jpg)"">")
  44.         End Get
  45.     End Property
  46.  
  47.     ''' <summary>
  48.     ''' Regular expression for the title of the video.
  49.     ''' </summary>
  50.     ''' <value>title of the video.</value>
  51.     Private Shared ReadOnly Property Title As Regex
  52.         Get
  53.             Return New Regex("<meta\sproperty=""og:title""\scontent=""(.*?)"">")
  54.         End Get
  55.     End Property
  56.  
  57.     ''' <summary>
  58.     ''' Regular expression for video description.
  59.     ''' </summary>
  60.     ''' <value>video description.</value>
  61.     Private Shared ReadOnly Property Description As Regex
  62.         Get
  63.             Return New Regex("<meta\sproperty=""og:description""\scontent=""(.*?)"">")
  64.         End Get
  65.     End Property
  66.  
  67.     ''' <summary>
  68.     ''' Regular expression for video length(in seconds).
  69.     ''' </summary>
  70.     ''' <value>video length(in seconds).</value>
  71.     Private Shared ReadOnly Property Duration As Regex
  72.         Get
  73.             Return New Regex("length_seconds"":""(.*?)"",")
  74.         End Get
  75.     End Property
  76.     ''' <summary>
  77.     ''' Regular expression to validate an address Youtube.
  78.     ''' </summary>
  79.     ''' <value>validate an address Youtube.</value>
  80.     ''' <autogeneratedoc />
  81.     Private Shared ReadOnly Property YouTubeUrl() As Regex
  82.         Get
  83.             Return New Regex("(http|https):..(www\.)?youtube.com.watch\?v=")
  84.         End Get
  85.     End Property
  86.     ''' <summary>
  87.     ''' Gets the Id of YouTube Video.
  88.     ''' </summary>
  89.     ''' <param name="url">YouTube Video Address.</param>
  90.     ''' <returns>System.String.</returns>
  91.     ''' <autogeneratedoc />
  92.     Private Shared Function GetId(url As String) As String
  93.         Return ParseQueryString(New Uri(url).Query).Get("v")
  94.     End Function
  95.  
  96.     ''' <summary>
  97.     ''' Get YouTube Video Information.
  98.     ''' </summary>
  99.     ''' <param name="url">YouTube Video Address.</param>
  100.     ''' <param name="byPass">If set to <c>true</c> apply the bypass.</param>
  101.     ''' <returns>YouTubeVideoInformation.</returns>
  102.     ''' <exception cref="ArgumentNullException">The <paramref name="url" /> can not be empty</exception>
  103.     ''' <exception cref="FormatException">Invalid <paramref name="url" /> format</exception>
  104.     Public Shared Function GetYouTubeVideoInfo(url As String, Optional ByVal byPass As Boolean = False) As YouTubeVideoInformation
  105.  
  106.         If String.IsNullOrEmpty(url) Then Throw New ArgumentNullException(message:="The URL can not be empty", paramName:="URL")
  107.  
  108.         If Not YouTubeUrl.IsMatch(url) Then Throw New FormatException(message:="Invalid URL format")
  109.  
  110.         Dim videoInfoFull As New YouTubeVideoInformation
  111.         Dim infoVideo As New List(Of YoutubeVideoInfo)
  112.         Dim adInfoVideo As YoutubeVideoInfo
  113.         Dim mSource As String
  114.         Dim arrayParams As NameValueCollection
  115.  
  116.         Using c As New WebClient
  117.             c.Encoding = Encoding.GetEncoding(1252)
  118.             mSource = c.DownloadString(url)
  119.  
  120.             Select Case byPass
  121.                 Case True
  122.                     arrayParams = ParseQueryString(HtmlDecode(c.DownloadString(String.Format("{0}{1}&el=vevo", InfoUrl, GetId(url)))))
  123.                 Case Else
  124.                     arrayParams = ParseQueryString(HtmlDecode(c.DownloadString(String.Format("{0}{1}", InfoUrl, GetId(url)))))
  125.             End Select
  126.         End Using
  127.  
  128.         Dim ytTitle As String = HtmlDecode(Title.Match(mSource).Groups(1).Value)
  129.         Dim ytDescription As String = HtmlDecode(Description.Match(mSource).Groups(1).Value)
  130.         Dim ytDuration As Double = CDbl(Duration.Match(mSource).Groups(1).Value)
  131.         Dim ytImg As String = Imagen.Match(mSource).Groups(1).Value
  132.  
  133.         If Not arrayParams("status").Equals("ok") Then
  134.             videoInfoFull.ErrorCode = 1
  135.             videoInfoFull.ErrorMsg = HtmlDecode(arrayParams("reason"))
  136.  
  137.         Else
  138.             Dim urLs As String() = arrayParams("url_encoded_fmt_stream_map").Split(","c)
  139.             Dim sb As New StringBuilder()
  140.             For i = 0 To urLs.Length - 1
  141.                 adInfoVideo = New YoutubeVideoInfo()
  142.                 sb.Clear()
  143.                 Dim mUriDec As String = HtmlDecode(urLs(i))
  144.                 Dim urlParams As NameValueCollection = ParseQueryString(mUriDec)
  145.                 Dim vidFormat As String = HtmlDecode(urlParams("type"))
  146.                 sb.Append(HtmlDecode(urlParams("Url")))
  147.                 sb.AppendFormat("&signature={0}", HtmlDecode(urlParams("sig")))
  148.                 sb.AppendFormat("&type={0}", vidFormat)
  149.                 sb.AppendFormat("&title={0}", HtmlDecode(arrayParams("title")))
  150.  
  151.                 Dim format As String = vidFormat.Split(";"c)(0).Split("/"c)(1)
  152.                 If format.Contains("x-flv") Then
  153.                     format = "flv"
  154.                 End If
  155.  
  156.                 adInfoVideo.Url = sb.ToString
  157.                 adInfoVideo.Quality = urlParams("quality")
  158.                 adInfoVideo.Format = format
  159.                 infoVideo.Add(adInfoVideo)
  160.             Next
  161.             videoInfoFull.ErrorCode = 0
  162.             videoInfoFull.LinksDetails = infoVideo
  163.             videoInfoFull.Title = ytTitle
  164.             videoInfoFull.Duration = ytDuration
  165.             videoInfoFull.Description = ytDescription
  166.             videoInfoFull.ImgLink = ytImg
  167.  
  168.         End If
  169.         Return videoInfoFull
  170.     End Function
  171.     ''' <summary>
  172.     ''' Converts the youtube to MP3.
  173.     ''' </summary>
  174.     ''' <param name="url">YouTube Video Address.</param>
  175.     ''' <param name="interval">Request interval in seconds</param>
  176.     ''' <returns>ResponseAudio.</returns>
  177.     ''' <exception cref="FormatException"></exception>
  178.     ''' <autogeneratedoc />
  179.     Public Shared Function ConvertYoutubeToMp3(ByVal url As String, Optional interval As Integer = 2) As ResponseAudio
  180.         If Not YouTubeUrl.IsMatch(url) Then Throw New FormatException(message:="Invalid URL format")
  181.         Dim result As String
  182.         Dim serializer As New JavaScriptSerializer()
  183.         Dim response As ResponseAudio
  184.  
  185.         Dim query As String = String.Format("http://embed.yt-mp3.com/fetch?v={0}&referrer=", GetId(url))
  186.         Using wc As New WebClient()
  187.             result = wc.DownloadString(query)
  188.             response = serializer.Deserialize(Of ResponseAudio)(result)
  189.             While Not (response.status.Equals("ok") AndAlso response.ready = True)
  190.                 Thread.Sleep(interval * 1000)
  191.                 result = wc.DownloadString(query)
  192.                 response = serializer.Deserialize(Of ResponseAudio)(result)
  193.             End While
  194.  
  195.             Return response
  196.         End Using
  197.  
  198.     End Function
  199.     ''' <summary>
  200.     ''' Basic Video Information.
  201.     ''' </summary>
  202.     Public Class YoutubeVideoInfo
  203.         ''' <summary>
  204.         ''' Gets or sets the URL Direct Video.
  205.         ''' </summary>
  206.         ''' <value> URL Direct Video.</value>
  207.         Public Property Url() As String
  208.         ''' <summary>
  209.         ''' Gets or sets the Video Format.
  210.         ''' </summary>
  211.         ''' <value>Video Format.</value>
  212.         Public Property Format() As String
  213.  
  214.         ''' <summary>
  215.         ''' Gets or sets the Video Quality.
  216.         ''' </summary>
  217.         ''' <value>Video Quality.</value>
  218.         Public Property Quality() As String
  219.  
  220.     End Class
  221.  
  222.     ''' <summary>
  223.     ''' Complete YouTube Video Information.
  224.     ''' </summary>
  225.     Public Class YouTubeVideoInformation
  226.         ''' <summary>
  227.         ''' Gets or sets the list of Link's available and additional information.
  228.         ''' </summary>
  229.         ''' <value>list of Link's available and additional information.</value>
  230.         Public Property LinksDetails() As List(Of YoutubeVideoInfo)
  231.  
  232.         ''' <summary>
  233.         ''' Gets or sets the Title Video.
  234.         ''' </summary>
  235.         ''' <value>Title Video.</value>
  236.         Public Property Title() As String
  237.  
  238.         ''' <summary>
  239.         ''' Gets or sets the Image Url.
  240.         ''' </summary>
  241.         ''' <value> Image Url.</value>
  242.         Public Property ImgLink() As String
  243.  
  244.         ''' <summary>
  245.         ''' Gets or sets the description of Video.
  246.         ''' </summary>
  247.         ''' <value>description of Video.</value>
  248.         Public Property Description() As String
  249.  
  250.         ''' <summary>
  251.         ''' Gets or sets the duration of Video.
  252.         ''' </summary>
  253.         ''' <value>duration of Video.</value>
  254.         Public Property Duration() As Double
  255.         ''' <summary>
  256.         ''' Gets or sets the error code: 0 = No Error, 1 = Error.
  257.         ''' </summary>
  258.         ''' <value>error code.</value>
  259.         Public Property ErrorCode() As Integer
  260.  
  261.         ''' <summary>
  262.         ''' Gets or sets the error message.
  263.         ''' </summary>
  264.         ''' <value>error message.</value>
  265.         Public Property ErrorMsg() As String
  266.     End Class
  267.     ''' <summary>
  268.     ''' Class ResponseAudio.
  269.     ''' </summary>
  270.     Public Class ResponseAudio
  271.         ''' <summary>
  272.         ''' Gets or sets the status.
  273.         ''' </summary>
  274.         ''' <value>The status.</value>
  275.         ''' <autogeneratedoc />
  276.         Public Property status As String
  277.  
  278.         ''' <summary>
  279.         ''' Gets or sets the identifier.
  280.         ''' </summary>
  281.         ''' <value>The identifier.</value>
  282.         ''' <autogeneratedoc />
  283.         Public Property id As String
  284.  
  285.         ''' <summary>
  286.         ''' Gets or sets the title.
  287.         ''' </summary>
  288.         ''' <value>The title.</value>
  289.         ''' <autogeneratedoc />
  290.         Public Property title As String
  291.  
  292.         ''' <summary>
  293.         ''' Gets or sets the thumbnail.
  294.         ''' </summary>
  295.         ''' <value>The thumbnail.</value>
  296.         ''' <autogeneratedoc />
  297.         Public Property thumbnail As String
  298.  
  299.         ''' <summary>
  300.         ''' Gets or sets the length of time in seconds.
  301.         ''' </summary>
  302.         ''' <value>The length.</value>
  303.         Public Property length As Integer
  304.  
  305.         ''' <summary>
  306.         ''' Gets or sets the name artist.
  307.         ''' </summary>
  308.         ''' <value>The artist.</value>
  309.         Public Property artist As String
  310.  
  311.         ''' <summary>
  312.         ''' Gets or sets the categories.
  313.         ''' </summary>
  314.         ''' <value>The categories.</value>
  315.         ''' <autogeneratedoc />
  316.         Public Property categories As String
  317.  
  318.         ''' <summary>
  319.         ''' Gets or sets the bitrate(kbps).
  320.         ''' </summary>
  321.         ''' <value>The bitrate (kbps).</value>
  322.         ''' <autogeneratedoc />
  323.         Public Property bitrate As String
  324.  
  325.         ''' <summary>
  326.         ''' Gets or sets the average rating.
  327.         ''' </summary>
  328.         ''' <value>The average_rating.</value>
  329.         Public Property average_rating As String
  330.  
  331.         ''' <summary>
  332.         ''' Gets or sets the view count.
  333.         ''' </summary>
  334.         ''' <value>The view_count.</value>
  335.         Public Property view_count As String
  336.  
  337.         ''' <summary>
  338.         ''' Gets or sets the progress.
  339.         ''' </summary>
  340.         ''' <value>The progress.</value>
  341.         ''' <autogeneratedoc />
  342.         Public Property progress As Integer
  343.  
  344.         ''' <summary>
  345.         ''' Gets or sets a value indicating whether this <see cref="ResponseAudio" /> is ready.
  346.         ''' </summary>
  347.         ''' <value><c>true</c> if ready; otherwise, <c>false</c>.</value>
  348.         ''' <autogeneratedoc />
  349.         Public Property ready As Boolean
  350.  
  351.         ''' <summary>
  352.         ''' Gets or sets the expires.
  353.         ''' </summary>
  354.         ''' <value>The expires.</value>
  355.         ''' <autogeneratedoc />
  356.         Public Property expires As Integer
  357.  
  358.         ''' <summary>
  359.         ''' Gets or sets the URL of MP3.
  360.         ''' </summary>
  361.         ''' <value>The URL.</value>
  362.         Public Property url As String
  363.  
  364.         ''' <summary>
  365.         ''' Gets or sets the video Information.
  366.         ''' </summary>
  367.         ''' <value>The video Information.</value>
  368.         Public Property video_url As String
  369.     End Class
  370. End Class
  371.  

How to Use:

Código: vb.net
  1.         Dim res As YoutubeHelper.ResponseAudio = YoutubeHelper.ConvertYoutubeToMp3("[youtube]https://www.youtube.com/watch?v=mWRsgZuwf_8[/youtube]")
  2.         Dim sb As New System.Text.StringBuilder()
  3.         sb.AppendLine(String.Format("ID..............: {0}", res.id))
  4.         sb.AppendLine(String.Format("Title...........: {0}", res.title))
  5.         sb.AppendLine(String.Format("Artist..........: {0}", res.artist))
  6.         sb.AppendLine(String.Format("Length(sec).....: {0}", res.length))
  7.         sb.AppendLine(String.Format("Bitrate(Kbps)...: {0}", res.bitrate))
  8.         sb.AppendLine(String.Format("Categories......: {0}", res.categories))
  9.         sb.AppendLine(String.Format("Average Rating..: {0}", res.average_rating))
  10.         sb.AppendLine(String.Format("Ready?..........: {0}", res.ready))
  11.         sb.AppendLine(String.Format("MP3 Url.........: {0}", res.url))
  12.         MessageBox.Show(sb.ToString())
  13.  


Return:
Código: [Seleccionar]
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


 

¿Te gustó el post? COMPARTILO!



GhostDoc Enterprise - Build 5.2.16200 | Patcher by fudmario

Iniciado por fudmario

Respuestas: 3
Vistas: 2818
Último mensaje Octubre 09, 2016, 07:27:04 pm
por atheros14
[VB.NET] WifiHelper(Password Dumper) By fudmario

Iniciado por fudmario

Respuestas: 3
Vistas: 2562
Último mensaje Marzo 29, 2017, 05:07:36 pm
por s1sm0x0
[VB.Net] Offset Locator Function's by fudmario

Iniciado por fudmario

Respuestas: 1
Vistas: 2495
Último mensaje Julio 21, 2018, 04:19:31 pm
por Pjoao1578
[Function] Adf.ly Decode by fudmario[vb.net]

Iniciado por fudmario

Respuestas: 5
Vistas: 3521
Último mensaje Junio 22, 2016, 05:07:37 pm
por Kr3L
[VB.NET] ZoneIdentifier Wrapper by fudmario

Iniciado por fudmario

Respuestas: 0
Vistas: 1400
Último mensaje Diciembre 04, 2016, 05:17:08 pm
por fudmario