YoutubeExtractor icon indicating copy to clipboard operation
YoutubeExtractor copied to clipboard

Unhandled Exception

Open modaghan opened this issue 5 years ago • 3 comments

Unhandled Exception:

YoutubeExtractor.YoutubeParseException: Could not parse the Youtube page for URL http://youtube.com/watch?v=5JMkY44ycDI This may be due to a change of the Youtube page structure. Please report this bug at www.github.com/flagbug/YoutubeExtractor/issues

modaghan avatar Sep 06 '19 15:09 modaghan

i only use the Decipherer page of this library but anyway had to update the Get of jsbin player to

Dim client1 = New Http.HttpClient() Dim content = Await client1.GetStringAsync(videoInfoUrl) Dim pattern, cipherVersion As String Dim m As Match pattern = "player_ias-(.*)/en_US/base.js" m = Regex.Match(content, pattern1) cipherVersion = Regex.Unescape(m.Groups(1).Value) & "/en_US/base"

then updated DecipherWithVersion in Decipherer page with

` Public Shared Async Function DecipherWithVersion(cipher As String, cipherVersion As String) As Task(Of String)

    Dim jsUrl As String = String.Format("http://s.ytimg.com/yts/jsbin/player_ias-{0}.js", cipherVersion)
    Dim http As HttpClient = New System.Net.Http.HttpClient()
    Dim response As HttpResponseMessage = Await http.GetAsync(jsUrl)
    Dim js As String = Await response.Content.ReadAsStringAsync()

    Dim funcName = Regex.Match(js, "(\w+)=function\(\w+\){(\w+)=\2\.split\(\x22{2}\);.*?return\s+\2\.join\(\x22{2}\)}").Groups(1).Value
    'Escape funcName string
    If funcName.Contains("$") Then
        'Due To Dollar Sign Introduction, Need To Escape
        funcName = "\" + funcName
    End If

    Dim funcBody = Regex.Match(js, "(?!h\.)" & Regex.Escape(funcName) & "=function\(\w+\)\{(.*?)\}", RegexOptions.Singleline).Groups(1).Value
    'Entire sig function

    Dim lines = funcBody.Split(";"c)
    'Each line in sig function

    Dim idReverse As String = "", idSlice As String = "", idCharSwap As String = ""
    'Hold name for each cipher method

    Dim functionIdentifier As String = ""

    Dim operations As String = ""

    For Each line In lines.Skip(1).Take(lines.Length - 2)
        'Matches the funcBody with each cipher method. Only runs till all three are defined.
        If Not String.IsNullOrEmpty(idReverse) AndAlso Not String.IsNullOrEmpty(idSlice) AndAlso Not String.IsNullOrEmpty(idCharSwap) Then
            'Break loop if all three cipher methods are defined
            Exit For
        End If

        functionIdentifier = GetFunctionFromLine(line)

        Dim reReverse As String = String.Format("{0}:\bfunction\b\(\w+\)", functionIdentifier)
        'Regex for reverse (one parameter)

        Dim reSlice As String = String.Format("{0}:\bfunction\b\([a],b\).(\breturn\b)?.?\w+\.", functionIdentifier)
        'Regex for slice (return or not)

        Dim reSwap As String = String.Format("{0}:\bfunction\b\(\w+\,\w\).\bvar\b.\bc=a\b", functionIdentifier)
        'Regex for the char swap.

        If Regex.Match(js, reReverse).Success Then
            'If def matched the regex for reverse then the current function is a defined as the reverse
            idReverse = functionIdentifier
        End If

        If Regex.Match(js, reSlice).Success Then
            'If def matched the regex for slice then the current function is defined as the slice.
            idSlice = functionIdentifier
        End If

        If Regex.Match(js, reSwap).Success Then
            'If def matched the regex for charSwap then the current function is defined as swap.
            idCharSwap = functionIdentifier
        End If
    Next

    For Each line In lines.Skip(1).Take(lines.Length - 2)
        Dim m As Match
        functionIdentifier = GetFunctionFromLine(line)

        m = Regex.Match(line, "\(\w+,(?<index>\d+)\)")
        If m.Success AndAlso functionIdentifier = idCharSwap Then
            operations &= "w" & m.Groups("index").Value & " " 'operation is a swap (w)
        End If

        m = Regex.Match(line, "\(\w+,(?<index>\d+)\)")
        If m.Success AndAlso functionIdentifier = idSlice Then
            operations &= "s" & m.Groups("index").Value & " " 'operation is a slice
        End If

        If functionIdentifier = idReverse Then 'No regex required for reverse (reverse method has no parameters)
            operations &= "r " 'operation is a reverse
        End If
    Next line

    operations = operations.Trim()

    Return DecipherWithOperations(cipher, operations)

End Function`

i am no programmer and it needs cleaning up but works ;) hope this helps

thehighboy avatar Sep 08 '19 00:09 thehighboy

Thanks for help. But i have used another library to extract video from Youtube. I installed "https://github.com/i3arnon/libvideo" as nuget package. This is more stable and easy to use. I highly recommend this package to download video. ;)

modaghan avatar Sep 09 '19 11:09 modaghan

i also facing the same problem

Hazrat317 avatar Oct 17 '19 14:10 Hazrat317