Skip to content
This repository has been archived by the owner on Jul 13, 2024. It is now read-only.

Commit

Permalink
CR api adjustments
Browse files Browse the repository at this point in the history
CR api adjustments #623
  • Loading branch information
hama3254 committed Dec 18, 2022
1 parent e76ad3b commit 37f10d3
Show file tree
Hide file tree
Showing 6 changed files with 304 additions and 218 deletions.
Binary file modified .vs/Crunchyroll Downloader/v17/.suo
Binary file not shown.
70 changes: 40 additions & 30 deletions Crunchyroll Downloader/Anime_Add.vb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ Public Class Anime_Add

Next

'MsgBox(Main.CR_Cookies)

'Browser.WebView2.Source = New Uri(Url)
'Exit Sub
If CBool(InStr(Url, "/series")) Then
Dim locale1() As String = Url.Split(New String() {"crunchyroll.com/"}, System.StringSplitOptions.RemoveEmptyEntries)
Dim locale2() As String = locale1(1).Split(New String() {"/series"}, System.StringSplitOptions.RemoveEmptyEntries)
Expand Down Expand Up @@ -99,7 +103,7 @@ Public Class Anime_Add


'MsgBox(Cookies)
Main.CR_Cookies = " -H " + Chr(34) + Main.CR_Cookies + Chr(34)
Dim Loc_CR_Cookies = " -H " + Chr(34) + Main.CR_Cookies + Chr(34)



Expand All @@ -109,13 +113,13 @@ Public Class Anime_Add

Dim CRBetaBearer As String = "Bearer "

Dim v1Token As String = Main.CurlPost("https://www.crunchyroll.com/auth/v1/token", Main.CR_Cookies, Auth, Post)
Dim v1Token As String = Main.CurlPost("https://www.crunchyroll.com/auth/v1/token", Loc_CR_Cookies, Auth, Post)



If CBool(InStr(v1Token, "curl:")) = True And CBool(InStr(v1Token, "400")) = True Then

v1Token = Main.CurlPost("https://www.crunchyroll.com/auth/v1/token", Main.CR_Cookies, Auth, Post.Replace("etp_rt_cookie", "client_id"))
v1Token = Main.CurlPost("https://www.crunchyroll.com/auth/v1/token", Loc_CR_Cookies, Auth, Post.Replace("etp_rt_cookie", "client_id"))

End If

Expand All @@ -135,7 +139,7 @@ Public Class Anime_Add
Exit Sub

ElseIf CBool(InStr(v1Token, "curl:")) = True Then
v1Token = Main.CurlPost("https://www.crunchyroll.com/auth/v1/token", Main.CR_Cookies, Auth, Post)
v1Token = Main.CurlPost("https://www.crunchyroll.com/auth/v1/token", Loc_CR_Cookies, Auth, Post)
End If

If CBool(InStr(v1Token, "curl:")) = True Then
Expand All @@ -154,37 +158,37 @@ Public Class Anime_Add


Dim Auth2 As String = " -H " + Chr(34) + "Authorization: " + CRBetaBearer + Chr(34)
Dim v2Content As String = Main.CurlAuth("https://www.crunchyroll.com/index/v2", Main.CR_Cookies, Auth2) 'client.DownloadString("https://www.crunchyroll.com/index/v2")

If CBool(InStr(v2Content, "curl:")) = True Then
v2Content = Main.CurlAuth("https://www.crunchyroll.com/index/v2", Main.CR_Cookies, Auth2)
End If

If CBool(InStr(v2Content, "curl:")) = True Then
Browser.WebView2.CoreWebView2.Navigate(Url)
StatusLabel.Text = "Status: loading in browser..."
Exit Sub
End If
If CBool(InStr(Url, "crunchyroll.com")) = True And CBool(InStr(Url, "series/")) = True Then

Dim v2Content As String = Main.CurlAuth("https://www.crunchyroll.com/index/v2", Main.CR_Cookies, Auth2)

Dim v2ContentBeta() As String = v2Content.Split(New String() {Chr(34) + "cms_web" + Chr(34) + ":"}, System.StringSplitOptions.RemoveEmptyEntries)
If CBool(InStr(v2Content, "curl:")) = True Then
v2Content = Main.CurlAuth("https://www.crunchyroll.com/index/v2", Main.CR_Cookies, Auth2)
End If

If CBool(InStr(v2Content, "curl:")) = True Then
Browser.WebView2.CoreWebView2.Navigate(Url)
StatusLabel.Text = "Status: loading in browser..."
Exit Sub
End If

Dim bucket() As String = v2ContentBeta(1).Split(New String() {Chr(34) + "bucket" + Chr(34) + ":" + Chr(34)}, System.StringSplitOptions.RemoveEmptyEntries)
Dim bucket2() As String = bucket(1).Split(New String() {Chr(34) + "," + Chr(34)}, System.StringSplitOptions.RemoveEmptyEntries)

Dim policy() As String = v2ContentBeta(1).Split(New String() {Chr(34) + "policy" + Chr(34) + ":" + Chr(34)}, System.StringSplitOptions.RemoveEmptyEntries)
Dim policy2() As String = policy(1).Split(New String() {Chr(34) + "," + Chr(34)}, System.StringSplitOptions.RemoveEmptyEntries)
Dim v2ContentBeta() As String = v2Content.Split(New String() {Chr(34) + "cms_web" + Chr(34) + ":"}, System.StringSplitOptions.RemoveEmptyEntries)

Dim signature() As String = v2ContentBeta(1).Split(New String() {Chr(34) + "signature" + Chr(34) + ":" + Chr(34)}, System.StringSplitOptions.RemoveEmptyEntries)
Dim signature2() As String = signature(1).Split(New String() {Chr(34) + "," + Chr(34)}, System.StringSplitOptions.RemoveEmptyEntries)

Dim key_pair_id() As String = v2ContentBeta(1).Split(New String() {Chr(34) + "key_pair_id" + Chr(34) + ":" + Chr(34)}, System.StringSplitOptions.RemoveEmptyEntries)
Dim key_pair_id2() As String = key_pair_id(1).Split(New String() {Chr(34) + "," + Chr(34)}, System.StringSplitOptions.RemoveEmptyEntries)
Dim bucket() As String = v2ContentBeta(1).Split(New String() {Chr(34) + "bucket" + Chr(34) + ":" + Chr(34)}, System.StringSplitOptions.RemoveEmptyEntries)
Dim bucket2() As String = bucket(1).Split(New String() {Chr(34) + "," + Chr(34)}, System.StringSplitOptions.RemoveEmptyEntries)

Dim policy() As String = v2ContentBeta(1).Split(New String() {Chr(34) + "policy" + Chr(34) + ":" + Chr(34)}, System.StringSplitOptions.RemoveEmptyEntries)
Dim policy2() As String = policy(1).Split(New String() {Chr(34) + "," + Chr(34)}, System.StringSplitOptions.RemoveEmptyEntries)

If CBool(InStr(Url, "crunchyroll.com")) = True And CBool(InStr(Url, "series/")) = True Then
Dim signature() As String = v2ContentBeta(1).Split(New String() {Chr(34) + "signature" + Chr(34) + ":" + Chr(34)}, System.StringSplitOptions.RemoveEmptyEntries)
Dim signature2() As String = signature(1).Split(New String() {Chr(34) + "," + Chr(34)}, System.StringSplitOptions.RemoveEmptyEntries)

Dim key_pair_id() As String = v2ContentBeta(1).Split(New String() {Chr(34) + "key_pair_id" + Chr(34) + ":" + Chr(34)}, System.StringSplitOptions.RemoveEmptyEntries)
Dim key_pair_id2() As String = key_pair_id(1).Split(New String() {Chr(34) + "," + Chr(34)}, System.StringSplitOptions.RemoveEmptyEntries)

Dim Series_idUrlBuilder() As String = Url.Split(New String() {"series/"}, System.StringSplitOptions.RemoveEmptyEntries)
Dim Series_idUrlBuilder2() As String = Series_idUrlBuilder(1).Split(New String() {"/"}, System.StringSplitOptions.RemoveEmptyEntries)
Expand All @@ -205,7 +209,7 @@ Public Class Anime_Add
Dim ObjectsURLBuilder4() As String = ObjectsURLBuilder3(1).Split(New String() {"/"}, System.StringSplitOptions.RemoveEmptyEntries)


ObjectsUrl = "https://www.crunchyroll.com/cms/v2" + bucket2(0) + "/objects/" + ObjectsURLBuilder4(0) + "?locale=" + Main.locale + "&Signature=" + signature2(0) + "&Policy=" + policy2(0) + "&Key-Pair-Id=" + key_pair_id2(0)
ObjectsUrl = "https://www.crunchyroll.com/content/v2/cms/objects/" + ObjectsURLBuilder4(0) + "?locale=" + Main.locale '+ "&Signature=" + signature2(0) + "&Policy=" + policy2(0) + "&Key-Pair-Id=" + key_pair_id2(0)
'End Using
'MsgBox(ObjectsUrl)

Expand All @@ -215,15 +219,21 @@ Public Class Anime_Add
Dim StreamsUrl As String = Nothing
Dim ObjectJson As String
Try
ObjectJson = Main.Curl(ObjectsUrl)
ObjectJson = Main.CurlAuth(ObjectsUrl, Loc_CR_Cookies, Auth2)


'"curl:" 'Main.Curl(ObjectsUrl)
'MsgBox(ObjectJson)

If CBool(InStr(ObjectJson, "curl:")) = True Then
ObjectJson = Main.Curl(ObjectsUrl)
End If
'If CBool(InStr(ObjectJson, "curl:")) = True Then
' ObjectJson = Main.Curl(ObjectsUrl)
'End If

If CBool(InStr(ObjectJson, "curl:")) = True Then
Browser.WebView2.CoreWebView2.Navigate(Url)
MsgBox(ObjectJson)
'Browser.WebView2.CoreWebView2.Navigate(ObjectsUrl)
' Main.LoadingUrl = ObjectsUrl

Exit Sub
ElseIf CBool(InStr(ObjectJson, "videos/")) = False Then

Expand Down Expand Up @@ -260,7 +270,7 @@ Public Class Anime_Add
Exit Sub
End Try

Main.GetBetaVideoProxy(StreamsUrl, Url)
Main.GetBetaVideoProxy(StreamsUrl, Auth2, Url)


Else
Expand Down
79 changes: 56 additions & 23 deletions Crunchyroll Downloader/Browser.vb
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,19 @@ Public Class Browser
' Dim HTML As String = WebView2.CoreWebView2.
'TextBox1.Text = WebView2.CoreWebView2.Source
' Exit Sub

If e.HttpStatusCode = 200 Then
Dim DocumentTitle As String = WebView2.CoreWebView2.DocumentTitle

Debug.WriteLine("NavigationCompleted: " + Date.Now.ToString)
Main.WebbrowserURL = WebView2.CoreWebView2.Source
TextBox1.Text = Main.WebbrowserURL

'Main.WebbrowserText = "" 'HTML
Main.WebbrowserTitle = DocumentTitle
Main.ProcessHTML("", Main.WebbrowserURL, DocumentTitle)

GetCookies(Main.WebbrowserURL)
End If

End If
End Sub

Public Async Sub GetCookies(ByVal Uri As String)
Expand Down Expand Up @@ -161,23 +159,44 @@ Public Class Browser
Dim reader As New StreamReader(Content)
ContentString = reader.ReadToEnd

Main.LoadedUrls.Add(e.Request.Uri)
Main.LoadedUrls.Add(e.Request)
Main.CR_VideoJson = New UrlJson(e.Request.Uri, ContentString)

Exit Sub
ElseIf CBool(InStr(e.Request.Uri, "crunchyroll.com/")) And CBool(InStr(e.Request.Uri, "/objects/")) And CBool(InStr(Main.LoadingUrl, "/watch/")) Then
'MsgBox(True.ToString)
Debug.WriteLine(e.Request.Uri)
Main.LoadedUrls.Add(e.Request.Uri)
'Main.LoadedUrls.Add(e.Request.Uri)
Dim Content As Stream = Await e.Response.GetContentAsync
Dim ContentString As String = Nothing
Dim reader As New StreamReader(Content)
ContentString = reader.ReadToEnd
Main.CR_ObjectsJson = New UrlJson(e.Request.Uri, ContentString)

'If CBool(InStr(WebView2.CoreWebView2.Source, "/objects/")) Then
' ' MsgBox("True2")
' Debug.WriteLine("Main.JSON: " + ContentString)
' Dim StreamsUrlBuilder() As String = ContentString.Split(New String() {"videos/"}, System.StringSplitOptions.RemoveEmptyEntries)
' Dim StreamsUrlBuilder2() As String = StreamsUrlBuilder(1).Split(New String() {"/streams"}, System.StringSplitOptions.RemoveEmptyEntries)
' ' MsgBox("True3")

' Dim StreamsUrlBuilder3() As String = e.Request.Uri.Split(New String() {"objects/"}, System.StringSplitOptions.RemoveEmptyEntries)
' Dim StreamsUrlBuilder4() As String = StreamsUrlBuilder3(1).Split(New String() {"?"}, System.StringSplitOptions.RemoveEmptyEntries)

' Dim StreamsUrl As String = StreamsUrlBuilder3(0) + "videos/" + StreamsUrlBuilder2(0) + "/streams?" + StreamsUrlBuilder4(1)
' MsgBox(StreamsUrl)
' WebView2.Source = New Uri(StreamsUrl)


'End If

Exit Sub


ElseIf CBool(InStr(e.Request.Uri, "crunchyroll.com/")) And CBool(InStr(e.Request.Uri, "seasons?series_id=")) And CBool(InStr(Main.LoadingUrl, "/series/")) Then
Debug.WriteLine("Crunchyroll-Season: " + e.Request.Uri)
Main.LoadedUrls.Add(e.Request.Uri)
Main.LoadedUrls.Add(e.Request.Uri)
Main.LoadedUrls.Add(e.Request)
Main.LoadedUrls.Add(e.Request)
Dim Content As Stream = Await e.Response.GetContentAsync
Dim ContentString As String = Nothing
Dim reader As New StreamReader(Content)
Expand All @@ -196,28 +215,28 @@ Public Class Browser
If CBool(InStr(e.Request.Uri, "https://title-api.prd.funimationsvc.com")) Then
Debug.WriteLine("Funimtaion: " + e.Request.Uri)
If (Me.InvokeRequired) Then
Me.Invoke(Sub() Main.LoadedUrls.Add(e.Request.Uri))
Me.Invoke(Sub() Main.LoadedUrls.Add(e.Request))
Exit Sub
Else
Main.LoadedUrls.Add(e.Request.Uri)
Main.LoadedUrls.Add(e.Request)
Exit Sub
End If
ElseIf CBool(InStr(e.Request.Uri, "/data/v2/shows/")) Then
Debug.WriteLine("Funimtaion: " + e.Request.Uri)
If (Me.InvokeRequired) Then
Me.Invoke(Sub() Main.LoadedUrls.Add(e.Request.Uri))
Me.Invoke(Sub() Main.LoadedUrls.Add(e.Request))
Exit Sub
Else
Main.LoadedUrls.Add(e.Request.Uri)
Main.LoadedUrls.Add(e.Request)
Exit Sub
End If
ElseIf CBool(InStr(e.Request.Uri, "/data/v1/episodes/")) Then
Debug.WriteLine("Funimtaion: " + e.Request.Uri)
If (Me.InvokeRequired) Then
Me.Invoke(Sub() Main.LoadedUrls.Add(e.Request.Uri))
Me.Invoke(Sub() Main.LoadedUrls.Add(e.Request))
Exit Sub
Else
Main.LoadedUrls.Add(e.Request.Uri)
Main.LoadedUrls.Add(e.Request)
Exit Sub
End If
End If
Expand All @@ -243,7 +262,21 @@ Public Class Browser
For i As Integer = 0 To Headers.Count
If CBool(InStr(Headers.Item(i).Value, "Basic")) Then
Main.CrBetaBasic = Headers.Item(i).Value
Debug.WriteLine(Main.CrBetaBasic)
Debug.WriteLine("Auth-Basic: " + Main.CrBetaBasic)
ElseIf CBool(InStr(Headers.Item(i).Value, "Bearer")) Then
Main.CR_AuthToken = Headers.Item(i).Value
Debug.WriteLine("Auth-Bearer: " + Main.CR_AuthToken)
End If
Next
End If

If CBool(InStr(e.Request.Uri, "crunchyroll.com/")) And CBool(InStr(e.Request.Uri, "streams?")) Then
Dim Headers As New List(Of KeyValuePair(Of String, String))
Headers.AddRange(e.Request.Headers.ToList)
For i As Integer = 0 To Headers.Count
If CBool(InStr(Headers.Item(i).Value, "Bearer")) Then
Main.CR_AuthToken = Headers.Item(i).Value
Debug.WriteLine("Auth-Bearer: " + Main.CR_AuthToken)
End If
Next
End If
Expand All @@ -260,17 +293,17 @@ Public Class Browser
'Content.Position = 0
'ContentString = Encoding.UTF8.GetString(Content.ToArray())
'MsgBox(ContentString)
Main.LoadedUrls.Add(e.Request.Uri)
Main.LoadedUrls.Add(e.Request)
'Main.CR_VideoJson = New UrlJson(e.Request.Uri, e.Request.Content.ToString)
Exit Sub
ElseIf CBool(InStr(e.Request.Uri, "crunchyroll.com/")) And CBool(InStr(e.Request.Uri, "/objects/")) And CBool(InStr(e.Request.Uri, "/watch/")) Then
Debug.WriteLine(e.Request.Uri)
Main.LoadedUrls.Add(e.Request.Uri)
Main.LoadedUrls.Add(e.Request)
'Main.CR_ObjectsJson = New UrlJson(e.Request.Uri, e.Request.Content.ToString)
Exit Sub
ElseIf CBool(InStr(e.Request.Uri, "crunchyroll.com/")) And CBool(InStr(e.Request.Uri, "seasons?series_id=")) Then
Debug.WriteLine("Crunchyroll-Season: " + e.Request.Uri)
Main.LoadedUrls.Add(e.Request.Uri)
Main.LoadedUrls.Add(e.Request)
'Main.CR_SeasonJson = New UrlJson(e.Request.Uri, e.Request.Content.ToString)
Exit Sub
End If
Expand All @@ -288,28 +321,28 @@ Public Class Browser
If CBool(InStr(e.Request.Uri, "https://title-api.prd.funimationsvc.com")) Then
Debug.WriteLine("Funimtaion: " + e.Request.Uri)
If (Me.InvokeRequired) Then
Me.Invoke(Sub() Main.LoadedUrls.Add(e.Request.Uri))
Me.Invoke(Sub() Main.LoadedUrls.Add(e.Request))
Exit Sub
Else
Main.LoadedUrls.Add(e.Request.Uri)
Main.LoadedUrls.Add(e.Request)
Exit Sub
End If
ElseIf CBool(InStr(e.Request.Uri, "/data/v2/shows/")) Then
Debug.WriteLine("Funimtaion: " + e.Request.Uri)
If (Me.InvokeRequired) Then
Me.Invoke(Sub() Main.LoadedUrls.Add(e.Request.Uri))
Me.Invoke(Sub() Main.LoadedUrls.Add(e.Request))
Exit Sub
Else
Main.LoadedUrls.Add(e.Request.Uri)
Main.LoadedUrls.Add(e.Request)
Exit Sub
End If
ElseIf CBool(InStr(e.Request.Uri, "/data/v1/episodes/")) Then
Debug.WriteLine("Funimtaion: " + e.Request.Uri)
If (Me.InvokeRequired) Then
Me.Invoke(Sub() Main.LoadedUrls.Add(e.Request.Uri))
Me.Invoke(Sub() Main.LoadedUrls.Add(e.Request))
Exit Sub
Else
Main.LoadedUrls.Add(e.Request.Uri)
Main.LoadedUrls.Add(e.Request)
Exit Sub
End If
End If
Expand Down
3 changes: 3 additions & 0 deletions Crunchyroll Downloader/ErrorDialog.vb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ Public Class ErrorDialog
ElseIf Main.DialogTaskString = "Language_CR_Beta" Then
'CheckBox1.Visible = False
StatusLabel.Text = Main.LabelLangNotFoundText
Debug.WriteLine("ResoNotFoundString")
Debug.WriteLine(Main.ResoNotFoundString)
Debug.WriteLine("ResoNotFoundString")

Dim lang_avalibe As String() = Main.ResoNotFoundString.Split(New String() {"hardsub_locale" + Chr(34) + ":" + Chr(34)}, System.StringSplitOptions.RemoveEmptyEntries)

Expand Down
Loading

0 comments on commit 37f10d3

Please sign in to comment.