added token reusing, added error handling (.key files)

added reusing the access token (valid 300s in usage for ~270s)
added renewing the access token (via refresh token)
added .key file error detection (critical issue)
minor cleanup
This commit is contained in:
hama3254 2024-04-28 21:29:33 +02:00
parent 9be37f3904
commit a8aeceb617
12 changed files with 315 additions and 445 deletions

Binary file not shown.

View File

@ -479,7 +479,7 @@ Public Class Anime_Add
End Try
'My.Computer.Clipboard.SetText(EpisodeJson)
Debug.WriteLine("EpisodeJson: " + EpisodeJson)
'Debug.WriteLine("EpisodeJson: " + EpisodeJson)
FillCREpisodes(EpisodeJson)

View File

@ -129,9 +129,6 @@
<setting name="SaveThumbnail" serializeAs="String">
<value>False</value>
</setting>
<setting name="SaveMode" serializeAs="String">
<value>False</value>
</setting>
<setting name="DownloadScope" serializeAs="String">
<value>0</value>
</setting>

View File

@ -20,8 +20,8 @@ Public Class Browser
Private Sub WebView2_CoreWebView2InitializationCompleted(sender As Object, e As CoreWebView2InitializationCompletedEventArgs) Handles WebView2.CoreWebView2InitializationCompleted
Try
WebView2.CoreWebView2.AddWebResourceRequestedFilter("https://www.crunchyroll.com/*", CoreWebView2WebResourceContext.All)
AddHandler WebView2.CoreWebView2.WebResourceResponseReceived, AddressOf ObserveResponse
AddHandler WebView2.CoreWebView2.WebResourceRequested, AddressOf ObserveHttp
'AddHandler WebView2.CoreWebView2.WebResourceResponseReceived, AddressOf ObserveResponse
'AddHandler WebView2.CoreWebView2.WebResourceRequested, AddressOf ObserveHttp 'this is not the data we are looking for (anymore :( )
My.Settings.User_Agend = Chr(34) + "User-Agent: " + WebView2.CoreWebView2.Settings.UserAgent + Chr(34)
If WebView2.CoreWebView2.Source = "about:blank" Or WebView2.CoreWebView2.Source = Nothing Then
@ -162,60 +162,6 @@ Public Class Browser
End Sub
Private Async Sub ObserveResponse(ByVal sender As Object, ByVal e As CoreWebView2WebResourceResponseReceivedEventArgs)
If CBool(InStr(Main.LoadingUrl, "crunchyroll.com")) Then
If CBool(InStr(e.Request.Uri, "crunchyroll.com/")) And CBool(InStr(e.Request.Uri, "v1/token")) And Main.CR_v1Token = "Get" Then
Debug.WriteLine("Crunchyroll-v1_token: " + 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
Dim Loc_CR_Cookies = " -H " + Chr(34) + Main.CR_Cookies + Chr(34)
Dim Token() As String = ContentString.Split(New String() {Chr(34) + "access_token" + Chr(34) + ":" + Chr(34)}, System.StringSplitOptions.RemoveEmptyEntries)
Dim Token2() As String = Token(1).Split(New String() {Chr(34) + "," + Chr(34)}, System.StringSplitOptions.RemoveEmptyEntries)
Dim Auth As String = "Bearer " + Token2(0)
Dim Auth2 As String = " -H " + Chr(34) + "Authorization: " + Auth + Chr(34)
Main.ProcessLoading(Main.LoadingUrl, Auth2, Loc_CR_Cookies, 0)
Main.CR_v1Token = ""
Exit Sub
ElseIf CBool(InStr(e.Request.Uri, "crunchyroll.com/")) And CBool(InStr(e.Request.Uri, "seasons?preferred_audio_language=")) And CBool(InStr(Main.LoadingUrl, "/series/")) Then
Debug.WriteLine("Crunchyroll-Season: " + e.Request.Uri)
Main.LoadedUrls.Add(e.Request)
Exit Sub
'ElseIf CBool(InStr(e.Request.Uri, "crunchyroll.com/")) And CBool(InStr(e.Request.Uri, "content/v2/cms/objects/")) Then
' Debug.WriteLine("Crunchyroll-objects added to cache: " + e.Request.Uri)
' Main.LoadedUrls.Add(e.Request)
' Exit Sub
'ElseIf CBool(InStr(e.Request.Uri, "crunchyroll.com/")) And CBool(InStr(e.Request.Uri, "seasons?preferred_audio_language=")) And CBool(InStr(Main.LoadingUrl, "/series/")) Then
' Debug.WriteLine("Crunchyroll-objects added to cache: " + e.Request.Uri)
' Main.LoadedUrls.Add(e.Request)
' Exit Sub
End If
End If
End Sub
Private Sub ObserveHttp(ByVal sender As Object, ByVal e As CoreWebView2WebResourceRequestedEventArgs) 'Handles RequestResource.GetUrl

View File

@ -35,6 +35,25 @@ Public Class CR_Beta_Stream
End Class
Public Class CR_Tokens
Public access_token As String
Public refresh_token As String
Public expires_Unix As Integer
Public Sub New(ByVal access_token As String, ByVal refresh_token As String, ByVal expires_Unix As Integer)
Me.access_token = access_token
Me.refresh_token = refresh_token
Me.expires_Unix = expires_Unix
End Sub
Public Overrides Function ToString() As String
Return String.Format("{0}, {1}, {2}", Me.access_token, Me.refresh_token, Me.expires_Unix.ToString)
End Function
End Class
Public Class CR_MediaVersion
Public AudioLang As String

View File

@ -31,10 +31,15 @@ Public Class CRD_List_Item
Dim TempFolder As String = Nothing
Dim DownloadPfad As String = Nothing
Dim ThumbnailSource As String = Nothing
Dim Failed As Boolean = False
Dim FailedCount As Integer = 0
Dim FailedKey As Boolean = False
Dim HistoryDL_URL As String
Dim HistoryDL_Pfad As String
Dim HistoryFilename As String
Dim Retry As Boolean = False
Dim HybridMode As Boolean = False
@ -301,6 +306,32 @@ Public Class CRD_List_Item
StatusRunning = False
bt_pause.BackgroundImage = My.Resources.main_pause_play
ElseIf Failed = True And FailedKey = True Then
If Not Directory.Exists(Path.GetDirectoryName(HybridModePath)) Then
' Nein! Jetzt erstellen...
Try
Directory.Delete(Path.GetDirectoryName(HybridModePath))
Catch ex As Exception
Debug.WriteLine("folder issue - delete")
Exit Sub
End Try
End If
Dim Evaluator = New Thread(Sub() DownloadHybrid(HistoryDL_URL, HistoryDL_Pfad, HistoryFilename))
Evaluator.Start()
HybridMode = True
HybridRunning = True
StatusRunning = True
Failed = False
LastDate = Date.Now
LastSize = 0
LastDataRate1 = 0
LastDataRate2 = 0
LastDataRate3 = 0
FailedSegments.Clear()
LogText.Clear()
ZeitGesamtInteger = 0
ElseIf Failed = True Then
Dim Result As DialogResult = MessageBox.Show("The hybride mode has failed to download a fragment." + vbNewLine + "Press 'Retry' to retry the fragment or 'Ignore' to continue.", "Download Error", MessageBoxButtons.AbortRetryIgnore) '= DialogResult.Ignore Then
@ -445,8 +476,6 @@ Public Class CRD_List_Item
#Region "Download + Update UI"
Public Sub StartDownload(ByVal DL_URL As String, ByVal DL_Pfad As String, ByVal Filename As String, ByVal DownloadHybridMode As Boolean, ByVal TempFolder As String)
'MsgBox(DL_URL)
Me.StyleManager = MetroStyleManager1
@ -1073,7 +1102,16 @@ Public Class CRD_List_Item
Catch ex2 As Exception
FailedCount = FailedCount + 1
If Item_ErrorTolerance = 0 Then
If CBool(InStr(DL_Pfad, ".key")) Then
Failed = True
FailedKey = True
StatusRunning = False
bt_pause.BackgroundImage = My.Resources.main_pause_play
Me.Invoke(New Action(Function() As Object
Label_percent.Text = "fatal! Failed to download 'encryption.key'"
Return Nothing
End Function))
ElseIf Item_ErrorTolerance = 0 Then
ElseIf FailedCount >= Item_ErrorTolerance Then
FailedSegments.Add(New FailedSegemtsWithURL(DL_Pfad, DL_URL))
@ -1085,6 +1123,7 @@ Public Class CRD_List_Item
Label_percent.Text = "Missing segment detected, retry or resume with the play button"
Return Nothing
End Function))
End If
@ -1099,6 +1138,7 @@ Public Class CRD_List_Item
#End Region
Public Function DownloadHybrid(ByVal DL_URL As String, ByVal DL_Pfad As String, ByVal Filename As String) As String
'MsgBox(DL_URL)
LogText.Add(Date.Now.ToString + " " + DL_URL)
Dim Folder As String = GeräteID()
@ -1147,7 +1187,7 @@ Public Class CRD_List_Item
Return Nothing
End Function))
For i As Integer = 0 To InuputStreams.Count - 1
For i As Integer = 1 To InuputStreams.Count - 1
Dim int As Integer = i

View File

@ -40,7 +40,6 @@ Partial Class Main
Me.Btn_Close = New System.Windows.Forms.Button()
Me.ContextMenuStrip1 = New System.Windows.Forms.ContextMenuStrip(Me.components)
Me.QueueToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
Me.SaveModeToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
Me.SaveThumbnailAsImageToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
Me.ToggleDebugModeToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
Me.CheckCRBetaTokenToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
@ -50,9 +49,9 @@ Partial Class Main
Me.UrlJsonsToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
Me.DummyItemToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
Me.AudioOnlyQualityToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
Me.LoginFormToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
Me.Panel1 = New System.Windows.Forms.Panel()
Me.Btn_Queue = New System.Windows.Forms.Button()
Me.LoginFormToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
CType(Me.PictureBox5, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.ConsoleBar, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.MetroStyleManager1, System.ComponentModel.ISupportInitialize).BeginInit()
@ -161,7 +160,7 @@ Partial Class Main
'
'ContextMenuStrip1
'
Me.ContextMenuStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.QueueToolStripMenuItem, Me.SaveModeToolStripMenuItem, Me.SaveThumbnailAsImageToolStripMenuItem, Me.ToggleDebugModeToolStripMenuItem, Me.CheckCRBetaTokenToolStripMenuItem, Me.Timer3OffToolStripMenuItem, Me.ThreadCount, Me.CRCookieToolStripMenuItem, Me.UrlJsonsToolStripMenuItem, Me.DummyItemToolStripMenuItem, Me.AudioOnlyQualityToolStripMenuItem, Me.LoginFormToolStripMenuItem})
Me.ContextMenuStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.QueueToolStripMenuItem, Me.SaveThumbnailAsImageToolStripMenuItem, Me.ToggleDebugModeToolStripMenuItem, Me.CheckCRBetaTokenToolStripMenuItem, Me.Timer3OffToolStripMenuItem, Me.ThreadCount, Me.CRCookieToolStripMenuItem, Me.UrlJsonsToolStripMenuItem, Me.DummyItemToolStripMenuItem, Me.AudioOnlyQualityToolStripMenuItem, Me.LoginFormToolStripMenuItem})
Me.ContextMenuStrip1.Name = "ContextMenuStrip1"
resources.ApplyResources(Me.ContextMenuStrip1, "ContextMenuStrip1")
'
@ -170,11 +169,6 @@ Partial Class Main
Me.QueueToolStripMenuItem.Name = "QueueToolStripMenuItem"
resources.ApplyResources(Me.QueueToolStripMenuItem, "QueueToolStripMenuItem")
'
'SaveModeToolStripMenuItem
'
Me.SaveModeToolStripMenuItem.Name = "SaveModeToolStripMenuItem"
resources.ApplyResources(Me.SaveModeToolStripMenuItem, "SaveModeToolStripMenuItem")
'
'SaveThumbnailAsImageToolStripMenuItem
'
Me.SaveThumbnailAsImageToolStripMenuItem.Name = "SaveThumbnailAsImageToolStripMenuItem"
@ -220,6 +214,11 @@ Partial Class Main
Me.AudioOnlyQualityToolStripMenuItem.Name = "AudioOnlyQualityToolStripMenuItem"
resources.ApplyResources(Me.AudioOnlyQualityToolStripMenuItem, "AudioOnlyQualityToolStripMenuItem")
'
'LoginFormToolStripMenuItem
'
Me.LoginFormToolStripMenuItem.Name = "LoginFormToolStripMenuItem"
resources.ApplyResources(Me.LoginFormToolStripMenuItem, "LoginFormToolStripMenuItem")
'
'Panel1
'
resources.ApplyResources(Me.Panel1, "Panel1")
@ -236,11 +235,6 @@ Partial Class Main
Me.Btn_Queue.Name = "Btn_Queue"
Me.Btn_Queue.UseVisualStyleBackColor = False
'
'LoginFormToolStripMenuItem
'
Me.LoginFormToolStripMenuItem.Name = "LoginFormToolStripMenuItem"
resources.ApplyResources(Me.LoginFormToolStripMenuItem, "LoginFormToolStripMenuItem")
'
'Main
'
Me.ApplyImageInvert = True
@ -297,7 +291,6 @@ Partial Class Main
Friend WithEvents QueueToolStripMenuItem As ToolStripMenuItem
Friend WithEvents Btn_Queue As Button
Friend WithEvents SaveThumbnailAsImageToolStripMenuItem As ToolStripMenuItem
Friend WithEvents SaveModeToolStripMenuItem As ToolStripMenuItem
Friend WithEvents AudioOnlyQualityToolStripMenuItem As ToolStripMenuItem
Friend WithEvents LoginFormToolStripMenuItem As ToolStripMenuItem
End Class

View File

@ -489,12 +489,6 @@
<data name="&gt;&gt;QueueToolStripMenuItem.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;SaveModeToolStripMenuItem.Name" xml:space="preserve">
<value>SaveModeToolStripMenuItem</value>
</data>
<data name="&gt;&gt;SaveModeToolStripMenuItem.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;SaveThumbnailAsImageToolStripMenuItem.Name" xml:space="preserve">
<value>SaveThumbnailAsImageToolStripMenuItem</value>
</data>
@ -573,12 +567,6 @@
<data name="QueueToolStripMenuItem.Text" xml:space="preserve">
<value>ffmpeg option</value>
</data>
<data name="SaveModeToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>233, 22</value>
</data>
<data name="SaveModeToolStripMenuItem.Text" xml:space="preserve">
<value>*Save Mode*</value>
</data>
<data name="SaveThumbnailAsImageToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>233, 22</value>
</data>
@ -640,7 +628,7 @@
<value>Login Form</value>
</data>
<data name="ContextMenuStrip1.Size" type="System.Drawing.Size, System.Drawing">
<value>234, 290</value>
<value>234, 268</value>
</data>
<data name="&gt;&gt;ContextMenuStrip1.Name" xml:space="preserve">
<value>ContextMenuStrip1</value>

View File

@ -15,8 +15,7 @@ Imports System.Runtime.InteropServices
Imports MyProvider.MyProvider
Imports Microsoft.Web.WebView2.Core
Imports Crunchyroll_Downloader.CRD_Classes
Imports System.Runtime.CompilerServices
Public Class Main
Inherits MetroForm
@ -25,32 +24,21 @@ Public Class Main
Dim HTML As String = Nothing
Public CR_Cookies As String = "Cookie: "
Public CheckCRLogin As Boolean = True
Public CR_AuthToken As String = ""
Public CR_v1Token As String = ""
'Public GetBetaSeasonsRetry As Boolean = False
'Public GetBetaSeasonSingle As Boolean = False
Public CR_MassSeasons As New List(Of CR_Seasons)
Public CR_MassEpisodes As New List(Of CR_Seasons)
'Public CrBetaMass As String = Nothing
'Public CrBetaMassEpisodes As String = Nothing
'Public CrBetaMassParameters As String = Nothing
'Public CrBetaMassBaseURL As String = Nothing
Public Mail As String = Nothing
Public PW As String = Nothing
Public CrBetaBasic As String = "Basic dC1rZGdwMmg4YzNqdWI4Zm4wZnE6eWZMRGZNZnJZdktYaDRKWFMxTEVJMmNDcXUxdjVXYW4="
Public CR_Token As CR_Tokens = New CR_Tokens(Nothing, "", 0)
Public locale As String = Nothing
Public Url_locale As String = Nothing
'Public CrBetaObjects As String = Nothing
'Public CrBetaStreams As String = Nothing
'Public CrBetaStreamsUrl As String = Nothing
Public LoadingUrl As String = ""
Public LoadedUrls As New List(Of CoreWebView2WebResourceRequest)
@ -61,10 +49,8 @@ Public Class Main
Public KodiNaming As Boolean = False
Public ErrorTolerance As Integer = 0
Public CookieList As New List(Of CoreWebView2Cookie)
'Public liList As New List(Of String)
Public HTMLString As String = My.Resources.Startuphtml
Public ListBoxList As New List(Of String)
'Public ItemList As New List(Of CRD_List_Item)
Public RunningDownloads As Integer = 0
Public UseQueue As Boolean = False
Public StartServer As Integer = 0
@ -76,17 +62,12 @@ Public Class Main
Public LogBrowserData As Boolean = False
Public Thumbnail As String = Nothing
Public MergeSubs As Boolean = False
'Public IgnoreS1 As Boolean = False
Public IgnoreSeason As Integer = 0
Public HideFLInt As Integer = 0
Public KeepCache As Boolean = False
'Public SubsOnly As Boolean = False
Public DownloadScope As Integer = 0
Public VideoFormat As String = ".mp4"
Public MergeSubsFormat As String = "mov_text"
'Public LoginDialog As Boolean = False
'Public NonCR_Timeout As Integer = 5
'Public NonCR_URL As String = Nothing
Public DlSoftSubsRDY As Boolean = True
Public DialogTaskString As String
Dim NewAPIString1 As String
@ -1080,13 +1061,13 @@ Public Class Main
CR_EpisodeID = ObjectsURLBuilder4(0)
Debug.WriteLine(ObjectsURL)
'Debug.WriteLine(ObjectsURL)
ObjectJson = CurlAuthNew(ObjectsURL, Loc_CR_Cookies, Loc_AuthToken)
'Filter JSON esqaped characters
'Debug.WriteLine(Date.Now.ToString + "before:" + ObjectJson)
Debug.WriteLine("1750: " + ObjectJson)
'Debug.WriteLine("1750: " + ObjectJson)
ObjectJson = CleanJSON(ObjectJson)
'Debug.WriteLine(Date.Now.ToString + "after:" + ObjectJson)
@ -1160,7 +1141,6 @@ Public Class Main
End Select
Next
#Region "m3u8 suche"
@ -1183,7 +1163,7 @@ Public Class Main
Debug.WriteLine("NewAPI: " + NewAPI)
Dim NewAPIData As String = CurlAuthNew(NewAPI, "", Loc_AuthToken)
Debug.WriteLine("NewAPIData: " + NewAPIData)
'Debug.WriteLine("NewAPIData: " + NewAPIData)
Dim VideoJSON_New As String = CleanJSON(NewAPIData)
@ -1217,7 +1197,10 @@ Public Class Main
End Select
Next
Me.Invoke(New Action(Function() As Object
SetStatusLabel("Status: API data received")
Return Nothing
End Function))
Dim CR_URI_Master As New List(Of String)
@ -1273,23 +1256,11 @@ Public Class Main
End If
End If
'MsgBox(CR_URI_Master.Count.ToString)
Me.Invoke(New Action(Function() As Object
SetStatusLabel("Status: Language found")
Return Nothing
End Function))
'If CBool(InStr(CR_URI_Master(0), "master.m3u8")) Then
' Me.Invoke(New Action(Function() As Object
' Anime_Add.StatusLabel.Text = "Status: m3u8 found, looking for resolution"
' Me.Text = "Status: m3u8 found, looking for resolution"
' Me.Invalidate()
' Return Nothing
' End Function))
'Else
' If MessageBox.Show("The Url below failed a check, continue?" + vbNewLine + CR_URI_Master(0), "Mission failed?", MessageBoxButtons.OKCancel) = DialogResult.OK Then
' Else
' Throw New System.Exception("Premium Episode")
' End If
' Throw New System.Exception("Premium Episode")
'End If
#End Region
@ -1606,6 +1577,7 @@ Public Class Main
If DownloadScope = DownloadScopeEnum.SubsOnly Then
ffmpegInput = "-i [Subtitles only]"
Else
Dim str As String = CurlAuthNew(CR_URI_Master(0), "", Loc_AuthToken)
@ -1674,7 +1646,11 @@ Public Class Main
End If
Me.Invoke(New Action(Function() As Object
SetStatusLabel("Status: Resolution found")
Pause(2)
Return Nothing
End Function))
#End Region
@ -1686,7 +1662,6 @@ Public Class Main
'Dim SplitVideo As String() = VideoJson.Split(New String() {Chr(34) + "closed_captions" + Chr(34) + ":"}, System.StringSplitOptions.RemoveEmptyEntries)
'If SoftSubs.Count > 0 And My.Settings.Captions = True Then
@ -1698,6 +1673,11 @@ Public Class Main
'End If
'"language":"de-DE"
If SoftSubs.Count > 0 Then 'And CCAvailable.Count = 0 Then
Me.Invoke(New Action(Function() As Object
SetStatusLabel("Status: Checking Soft-Subs")
Return Nothing
End Function))
For i As Integer = 0 To SoftSubs.Count - 1
If CBool(InStr(VideoJSON_New, Chr(34) + "language" + Chr(34) + ":" + Chr(34) + SoftSubs(i) + Chr(34) + "," + Chr(34) + "url" + Chr(34) + ":" + Chr(34))) Then
SoftSubsAvailable.Add(SoftSubs(i))
@ -2311,84 +2291,6 @@ Public Class Main
#End Region
Public Sub ProcessUrls()
Debug.WriteLine(LoadedUrls.Count.ToString)
Debug.WriteLine(Date.Now.ToString + " Thread Name: " + Thread.CurrentThread.Name)
Dim SavedObjectsUrl = ""
For i As Integer = 0 To LoadedUrls.Count - 1
Dim Request As CoreWebView2WebResourceRequest = LoadedUrls.Item(i)
If CBool(InStr(Request.Uri, "crunchyroll.com/")) And CBool(InStr(Request.Uri, "streams?")) Then
If b = False Then
If Application.OpenForms().OfType(Of Anime_Add).Any = True Then
Anime_Add.StatusLabel.Text = "Status: Crunchyroll episode found."
End If
Me.Text = "Status: Crunchyroll episode found."
Debug.WriteLine("Crunchyroll episode found")
GetCRVideoProxy(Request.Uri, CR_AuthToken, WebbrowserURL, 0)
b = True
LoadedUrls.Clear()
Me.Text = "Crunchyroll Downloader"
Exit Sub
End If
ElseIf CBool(InStr(Request.Uri, "crunchyroll.com/")) And CBool(InStr(Request.Uri, "seasons?preferred_audio_language=")) And CBool(InStr(WebbrowserURL, "series")) Then
If b = False Then
If Application.OpenForms().OfType(Of Anime_Add).Any = True Then
Anime_Add.StatusLabel.Text = "Status: Crunchyroll season found."
End If
Me.Text = "Status: Crunchyroll season found."
Debug.WriteLine("Crunchyroll season found")
Dim Auth As String = " -H " + Chr(34) + "Authorization: " + Request.Headers.GetHeader("Authorization") + Chr(34)
Debug.WriteLine(Auth)
CR_Cookies = "Cookie: " + Request.Headers.GetHeader("Cookie")
GetBetaSeasons(WebbrowserURL, Request.Uri, Auth)
'Browser.WebBrowser1.LoadUrl(Request.Uri)
b = True
LoadedUrls.Clear()
Me.Text = "Crunchyroll Downloader"
Exit Sub
End If
ElseIf CBool(InStr(Request.Uri, "crunchyroll.com/")) And CBool(InStr(Request.Uri, "seasons?series_id=")) Then
If b = False Then
If Application.OpenForms().OfType(Of Anime_Add).Any = True Then
Anime_Add.StatusLabel.Text = "Status: Error found invalid data."
End If
b = True
LoadedUrls.Clear()
Me.Text = "Crunchyroll Downloader"
Exit Sub
End If
End If
Next
LoadedUrls.Clear()
If b = True Then
LoadedUrls.Clear()
Debug.WriteLine("Just Browsing after all, exiting...")
Grapp_RDY = True
Me.Text = "Crunchyroll Downloader"
Exit Sub
End If
End Sub
Public Sub Navigate(ByVal Url As String)
If Application.OpenForms().OfType(Of Browser).Any = True Then
@ -2996,10 +2898,6 @@ Public Class Main
LoadedUrls.Clear()
Dim NoBrowser As Boolean = False
If My.Settings.SaveMode = True Then
Browser.WebView2.CoreWebView2.Navigate(Url)
Exit Sub
End If
'CR_v1Token = "Get"
'Browser.WebView2.Source = New Uri(Url)
@ -3012,99 +2910,122 @@ Public Class Main
#Region "Get Cookies"
CR_Cookies = "Cookie: "
'MsgBox("Cookies")
If File.Exists("cookies.txt") = True Then
CR_Cookies = GetCookiesFromFile("crunchyroll.com")
NoBrowser = True
CrBetaBasic = "Basic bm9haWhkZXZtXzZpeWcwYThsMHE6"
'MsgBox(True.ToString)
Else
Browser.GetCookies(Url)
Debug.WriteLine(CookieList.Count.ToString)
If CookieList.Count = 0 Then
Browser.WebView2.CoreWebView2.Navigate(Url)
SetStatusLabel("Status: loading in browser...")
Me.Text = "Status: loading in browser..."
Exit Sub
End If
For i As Integer = 0 To CookieList.Count - 1
If CBool(InStr(CookieList.Item(i).Domain, ".crunchyroll.com")) And CBool(InStr(CookieList.Item(i).Name, "_evidon_suppress")) = False Then
CR_Cookies = CR_Cookies + CookieList.Item(i).Name + "=" + CookieList.Item(i).Value + ";"
End If
Next
End If
'MsgBox(Main.CR_Cookies)
Dim DeviceRegion As String = Nothing
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)
locale = Convert_locale(locale2(0))
If locale = "en-US" Then
Url_locale = ""
Else
Url_locale = locale2(0)
End If
ElseIf CBool(InStr(Url, "/watch")) Then
Dim locale1() As String = Url.Split(New String() {"crunchyroll.com/"}, System.StringSplitOptions.RemoveEmptyEntries)
Dim locale2() As String = locale1(1).Split(New String() {"/watch"}, System.StringSplitOptions.RemoveEmptyEntries)
'MsgBox(locale2(0))
locale = Convert_locale(locale2(0))
'End If
If locale = "en-US" Then
Url_locale = ""
Else
Url_locale = locale2(0)
End If
'If CBool(InStr(Url, "musicvideo/")) Then
' SetStatusLabel("Status: musicvideo detected - partial support only")
' Browser.WebView2.CoreWebView2.Navigate(Url)
' Exit Sub
'CR_Cookies = "Cookie: "
''MsgBox("Cookies")
'If File.Exists("cookies.txt") = True Then
' CR_Cookies = GetCookiesFromFile("crunchyroll.com")
' NoBrowser = True
' CrBetaBasic = "Basic bm9haWhkZXZtXzZpeWcwYThsMHE6"
' 'MsgBox(True.ToString)
'Else
'If CBool(InStr(Url, "/concert/")) Then
' Browser.GetCookies(Url)
' SetStatusLabel("Status: concert detected - partial support only")
' Debug.WriteLine(CookieList.Count.ToString)
' If CookieList.Count = 0 Then
' Browser.WebView2.CoreWebView2.Navigate(Url)
' SetStatusLabel("Status: loading in browser...")
' Me.Text = "Status: loading in browser..."
' Exit Sub
' End If
End If
'Debug.WriteLine("###" + CR_Cookies + "###")
' For i As Integer = 0 To CookieList.Count - 1
Dim Loc_CR_Cookies = " -H " + Chr(34) + CR_Cookies + Chr(34)
' If CBool(InStr(CookieList.Item(i).Domain, ".crunchyroll.com")) And CBool(InStr(CookieList.Item(i).Name, "_evidon_suppress")) = False Then
' CR_Cookies = CR_Cookies + CookieList.Item(i).Name + "=" + CookieList.Item(i).Value + ";"
' End If
' Next
'End If
''MsgBox(Main.CR_Cookies)
'Dim DeviceRegion As String = Nothing
'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)
' locale = Convert_locale(locale2(0))
' If locale = "en-US" Then
' Url_locale = ""
' Else
' Url_locale = locale2(0)
' End If
'CR_v1Token = "Get"
'Browser.WebView2.Source = New Uri(Url)
'Exit Sub
'ElseIf CBool(InStr(Url, "/watch")) Then
' Dim locale1() As String = Url.Split(New String() {"crunchyroll.com/"}, System.StringSplitOptions.RemoveEmptyEntries)
' Dim locale2() As String = locale1(1).Split(New String() {"/watch"}, System.StringSplitOptions.RemoveEmptyEntries)
' 'MsgBox(locale2(0))
' locale = Convert_locale(locale2(0))
' 'End If
' If locale = "en-US" Then
' Url_locale = ""
' Else
' Url_locale = locale2(0)
' End If
' 'If CBool(InStr(Url, "musicvideo/")) Then
' ' SetStatusLabel("Status: musicvideo detected - partial support only")
' ' Browser.WebView2.CoreWebView2.Navigate(Url)
' ' Exit Sub
' 'Else
' 'If CBool(InStr(Url, "/concert/")) Then
' ' SetStatusLabel("Status: concert detected - partial support only")
' ' Browser.WebView2.CoreWebView2.Navigate(Url)
' ' Exit Sub
' ' End If
'End If
''Debug.WriteLine("###" + CR_Cookies + "###")
'Dim Loc_CR_Cookies = " -H " + Chr(34) + CR_Cookies + Chr(34)
''CR_v1Token = "Get"
''Browser.WebView2.Source = New Uri(Url)
''Exit Sub
#End Region
Dim Loc_CR_Cookies As String = "" ' do we need that? does not seem like it.
Dim Auth As String = " -H " + Chr(34) + "Authorization: " + CrBetaBasic + Chr(34)
'Dim Post As String = " -d " + Chr(34) + "grant_type=etp_rt_cookie" + Chr(34) + " -X POST"
Dim Post As String = " -d " + Chr(34) + "username=" + UrlEncode(Mail) + "&password=" + UrlEncode(PW) + "&grant_type=password&scope=offline_access" + Chr(34) + " -X POST -H " + Chr(34) + "Content-Type: application/x-www-form-urlencoded; charset=utf-8" + Chr(34)
Dim Post As String = Nothing
Dim UnixTime As Integer
UnixTime = CInt((DateTime.UtcNow - New DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds)
If CBool(CR_Token.access_token = Nothing) = True Then ' *insert *First time* meme
Post = " -d " + Chr(34) + "username=" + UrlEncode(Mail) + "&password=" + UrlEncode(PW) + "&grant_type=password&scope=offline_access" + Chr(34) + " -X POST -H " + Chr(34) + "Content-Type: application/x-www-form-urlencoded; charset=utf-8" + Chr(34)
SetStatusLabel("Status: using login to authenticate")
Pause(2)
ElseIf CR_Token.expires_Unix + 30 > UnixTime Then 'we are not expired yet (+10% tolleranz)
Post = "Skip!"
SetStatusLabel("Status: Token not expired - skip auth")
Pause(2)
ElseIf CR_Token.expires_Unix + 30 < UnixTime Then 'we should renew it
Post = " -d " + Chr(34) + "refresh_token=" + CR_Token.refresh_token + "&grant_type=refresh_token&scope=offline_access" + Chr(34) + " -X POST -H " + Chr(34) + "Content-Type: application/x-www-form-urlencoded; charset=utf-8" + Chr(34)
SetStatusLabel("Status: Token expired - refreshing")
Pause(2)
End If
'
Dim CRBetaBearer As String = "Bearer "
If Post = "Skip!" Then
Dim Auth2 As String = " -H " + Chr(34) + "Authorization: " + CRBetaBearer + CR_Token.access_token + Chr(34)
ProcessLoading(Url, Auth2, Loc_CR_Cookies, RT_count)
Else
Dim v1Token As String = CurlPost("https://www.crunchyroll.com/auth/v1/token", Loc_CR_Cookies, Auth, Post, "add_main_4494")
If CBool(InStr(v1Token, "curl:")) = True And CBool(InStr(v1Token, "401")) = True Then
@ -3114,39 +3035,21 @@ Public Class Main
End If
If CBool(InStr(v1Token, "curl:")) = True And CBool(InStr(v1Token, "400")) = True Then
Debug.WriteLine("Post error!, 400")
Post = " -d " + Chr(34) + "grant_type=client_id&scope=offline_access" + Chr(34) + " -X POST"
Debug.WriteLine(Post.Replace("etp_rt_cookie", "client_id"))
v1Token = CurlPost("https://www.crunchyroll.com/auth/v1/token", Loc_CR_Cookies, Auth, Post.Replace("etp_rt_cookie", "client_id"), "add_main-4499")
End If
'MsgBox(v1Token)
If CBool(InStr(v1Token, "curl:")) = True And CBool(InStr(v1Token, "400")) = True Then
SetStatusLabel("Status: Failed - bad request, check CR login")
Me.Text = "Status: Failed - bad request, check CR login"
Debug.WriteLine("Status: Failed - bad request, check CR login")
b = True
MsgBox("CR reported error 400, idk why tbh", MsgBoxStyle.Exclamation, "CR-Error 400")
SetStatusLabel("Status: Unknown error. #3038")
Exit Sub
ElseIf CBool(InStr(v1Token, "curl:")) = True Then
v1Token = CurlPost("https://www.crunchyroll.com/auth/v1/token", Loc_CR_Cookies, Auth, Post, "add_main_4516")
End If
'MsgBox(v1Token)
If CBool(InStr(v1Token, "curl: (60)")) = True Then
SetStatusLabel("Status: Critical error. #4478")
SetStatusLabel("Status: Critical error. #3043")
MsgBox("Please try the '--insecure' option found on the 'Main' page of the settings.")
Exit Sub
'ElseIf CBool(InStr(v1Token, "curl:")) Then
ElseIf CBool(InStr(v1Token, "curl:")) = True Then
Browser.WebView2.CoreWebView2.Navigate(Url)
' Browser.WebView2.CoreWebView2.Navigate(Url)
SetStatusLabel("Status: Unknown error. #3050")
Exit Sub
End If
@ -3155,10 +3058,19 @@ Public Class Main
Dim Token2() As String = Token(1).Split(New String() {Chr(34) + "," + Chr(34)}, System.StringSplitOptions.RemoveEmptyEntries)
CRBetaBearer = CRBetaBearer + Token2(0)
Dim RefrehToken() As String = v1Token.Split(New String() {Chr(34) + "refresh_token" + Chr(34) + ":" + Chr(34)}, System.StringSplitOptions.RemoveEmptyEntries)
Dim RefrehToken2() As String = RefrehToken(1).Split(New String() {Chr(34) + "," + Chr(34)}, System.StringSplitOptions.RemoveEmptyEntries)
Dim TokenUnixTime As Integer
TokenUnixTime = CInt((DateTime.UtcNow - New DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds) + 300
CR_Token = New CR_Tokens(Token2(0), RefrehToken2(0), TokenUnixTime)
Dim Auth2 As String = " -H " + Chr(34) + "Authorization: " + CRBetaBearer + Chr(34)
ProcessLoading(Url, Auth2, Loc_CR_Cookies, RT_count)
End If
Else
'to do
End If
@ -3181,7 +3093,7 @@ Public Class Main
ElseIf CBool(InStr(url, "crunchyroll.com")) = True And CBool(InStr(url, "watch/")) = True And CBool(CrBetaBasic = Nothing) = False And CBool(InStr(url, "/musicvideo/")) = False And CBool(InStr(url, "/concert/")) = False Then
#Region "Anime"
SetStatusLabel("Status: Url match - Anime episode")
Dim ObjectsUrl As String = Nothing
@ -3254,7 +3166,7 @@ Public Class Main
#End Region
ElseIf CBool(InStr(url, "crunchyroll.com")) = True And CBool(InStr(url, "musicvideo/")) = True And CBool(CrBetaBasic = Nothing) = False Then
#Region "musik videos"
SetStatusLabel("Status: Url match - Music video")
Dim ObjectsUrl As String = Nothing
@ -3307,6 +3219,8 @@ Public Class Main
GetCRVideoProxy(StreamsUrl, Auth2, url, RT_Count)
#End Region
ElseIf CBool(InStr(url, "crunchyroll.com")) = True And CBool(InStr(url, "concert/")) = True And CBool(CrBetaBasic = Nothing) = False Then
#Region "concert"
SetStatusLabel("Status: Url match - Concert")
Dim ObjectsUrl As String = Nothing
@ -3357,8 +3271,10 @@ Public Class Main
GetCRVideoProxy(StreamsUrl, Auth2, url, RT_Count)
#End Region
Else
Browser.WebView2.CoreWebView2.Navigate(url)
'Browser.WebView2.CoreWebView2.Navigate(url)
End If
@ -3411,9 +3327,9 @@ Public Class Main
Sub SetStatusLabel(ByVal txt As String)
If Application.OpenForms().OfType(Of Anime_Add).Any = True Then
Anime_Add.StatusLabel.Text = txt
End If
Me.Text = txt
Debug.WriteLine("StatusLabel: " + Date.Now.ToString + " - " + txt)
End Sub
Private Sub SaveThumbnailAsImageToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SaveThumbnailAsImageToolStripMenuItem.Click
@ -3430,20 +3346,6 @@ Public Class Main
End If
End Sub
Private Sub SaveModeToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SaveModeToolStripMenuItem.Click
If My.Settings.SaveMode = False Then
My.Settings.SaveMode = True
MsgBox("SaveMode enabled")
My.Settings.Save()
Else
My.Settings.SaveMode = False
MsgBox("SaveMode disabled")
My.Settings.Save()
End If
End Sub
Private Sub Panel1_Paint(sender As Object, e As PaintEventArgs) Handles Panel1.Paint
End Sub

View File

@ -32,6 +32,6 @@ Imports System.Runtime.InteropServices
' übernehmen, indem Sie "*" eingeben:
' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("3.22.2")>
<Assembly: AssemblyFileVersion("3.22.2")>
<Assembly: AssemblyVersion("3.23")>
<Assembly: AssemblyFileVersion("3.23")>
<Assembly: NeutralResourcesLanguage("en")>

View File

@ -486,18 +486,6 @@ Namespace My
End Set
End Property
<Global.System.Configuration.UserScopedSettingAttribute(), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Configuration.DefaultSettingValueAttribute("False")> _
Public Property SaveMode() As Boolean
Get
Return CType(Me("SaveMode"),Boolean)
End Get
Set
Me("SaveMode") = value
End Set
End Property
<Global.System.Configuration.UserScopedSettingAttribute(), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Configuration.DefaultSettingValueAttribute("0")> _

View File

@ -110,9 +110,6 @@
<Setting Name="SaveThumbnail" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="SaveMode" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="DownloadScope" Type="System.Int32" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>