mirror of
https://github.com/AAndyProgram/SCrawler.git
synced 2026-03-15 08:12:17 +00:00
2023.4.28.0
Plugins IPluginContentProvider: added DownloadSingleObject function; added tokens to GetMedia and Download functions; removed GetSpecialData function Add IDownloadableMedia interface Removed 'Channel' option from all functions and enums ISiteSettings: added GetSingleMediaInstance function ExchangeOptions: removed 'IsChannel' UserMediaTypes: added Audio and AudioPre enums IUserMedia, PluginUserMedia: changed ContentType and DownloadState from integers to their enums SCrawler Add YouTube standalone downloader Add gallery-dl & yt-dlp support Remove 'UserInfo' requirement from 'ProfilesSaved' Update 'SiteSettingsBase' to use domains and Netscape cookies UserDataBase: remove channels; remove old 'Merge' const; standardize SavedPosts file naming; move 'ValidateMD5' function from Twitter to UserDataBase to use it in other UserData classes; add 'DownloadSingleObject' environment for single posts; add validating file extension for m3u8 during download; add reindex of video file during download Rewritten DomainsContainer Create a universal settings form and PSettingsArttribute Gfycat, Imgur: turn these classes into IUserData to download a single object All plugins: update 'GetInstance' function for saved posts; update domains where implemented; remove 'OptionForm' where it exists; update options where they exist; update unix date providers; reconfigure channels where they exist LPSG: fix attachments; update converters and regex Add sites: ThisVid, Mastodon, Pinterest, YouTube, YouTube music Reddit: standardize container parsing for all data types; new channel environment; fix 'ReparseMissing' function; redirect data downloading to the base download function, saved crossposts support Twitter: fixed gif path bug; fixed downloading saved posts PornHub: hide unnecessary errors; photo galleries bug RedGifs: add 'UserAgent' option Added icons to download progress Rename some objects Completely redesigned standalone downloader form and rewritten its environment WebClient2: update to use tokens Labels: update label form (save labels to file only when OK button is clicked); change removing labels.txt from recycle bin to permanent; disable storing label 'NoParsedUser' UserCreatorForm: remove the 'Channel' checkbox and related functions; ability to extract the user's URL from the buffer and apply parameters if found Remove temporary 'EncryptCookies' module MainFrame: added simplified way to create new users (Ctrl+Insert to create a new user with default parameters from clipboard URL); removed SCrawler command line argument "-v" (remove the ability to run SCrawler as video downloader) PropertyValueHost: update for option forms compatibility SettingsHost: removed 'GetSpecialData' fork; added 'GetSingleMediaInstance' fork UserDataHost: update functions with tokens; update events; add 'DownloadSingleObject' function Settings: add the ability to get environment from 4 destinations; add the ability to set the program environment manually; add CMDEncoding; add cache; remove the old function 'RemoveUnusedPlugins'; add 'STDownloader' properties; add YT compatibility; add new notification options; add deleting user settings file when 'SettingsCLS.Dispose()' if where are no users in SCrawler UserFinder: remove old 'Merge' const; remove channel option UserInfo: remove channel option
This commit is contained in:
198
SCrawler/Download/STDownloader/VideoDownloaderForm.vb
Normal file
198
SCrawler/Download/STDownloader/VideoDownloaderForm.vb
Normal file
@@ -0,0 +1,198 @@
|
||||
' Copyright (C) 2023 Andy https://github.com/AAndyProgram
|
||||
' This program is free software: you can redistribute it and/or modify
|
||||
' it under the terms of the GNU General Public License as published by
|
||||
' the Free Software Foundation, either version 3 of the License, or
|
||||
' (at your option) any later version.
|
||||
'
|
||||
' This program is distributed in the hope that it will be useful,
|
||||
' but WITHOUT ANY WARRANTY
|
||||
Imports SCrawler.Plugin.Hosts
|
||||
Imports SCrawler.API.YouTube.Base
|
||||
Imports SCrawler.API.YouTube.Objects
|
||||
Imports PersonalUtilities.Forms.Controls.KeyClick
|
||||
Namespace DownloadObjects.STDownloader
|
||||
Friend Class VideoDownloaderForm
|
||||
Private WithEvents BTT_ADD_URLS_ARR As ToolStripMenuItemKeyClick
|
||||
Private Const UrlsArrTag As String = "URLS_ARR"
|
||||
Private ReadOnly ControlNonYT As New FPredicate(Of MediaItem)(Function(i) Not i.MyContainer.SiteKey = API.YouTube.YouTubeSiteKey)
|
||||
Private ReadOnly ControlsDownloadedNonYT As New FPredicate(Of MediaItem)(Function(i) i.MyContainer.MediaState = Plugin.UserMediaStates.Downloaded And ControlNonYT.Invoke(i))
|
||||
Public Sub New()
|
||||
InitializeComponent()
|
||||
AppMode = False
|
||||
Icon = My.Resources.ArrowDownIcon_Blue_24
|
||||
BTT_ADD_PLS_ARR.Text = $"YouTube: {BTT_ADD_PLS_ARR.Text}"
|
||||
BTT_ADD_NO_SHORTS.Text = $"YouTube: {BTT_ADD_NO_SHORTS.Text}"
|
||||
BTT_ADD_SHORTS_ONLY.Text = $"YouTube: {BTT_ADD_SHORTS_ONLY.Text}"
|
||||
BTT_ADD_URLS_ARR = New ToolStripMenuItemKeyClick("Add an array of URLs", PersonalUtilities.My.Resources.PlusPic_Green_24) With {.Tag = UrlsArrTag}
|
||||
MENU_ADD.DropDownItems.Insert(1, BTT_ADD_URLS_ARR)
|
||||
Text = "Video downloader"
|
||||
End Sub
|
||||
Protected Overrides Function LoadData_GetFiles() As List(Of IYouTubeMediaContainer)
|
||||
Try
|
||||
Dim l As List(Of IYouTubeMediaContainer) = Nothing
|
||||
If Settings.STDownloader_LoadYTVideos Then l = MyBase.LoadData_GetFiles()
|
||||
If l Is Nothing Then l = New List(Of IYouTubeMediaContainer)
|
||||
Dim path As SFile = DownloaderDataFolder
|
||||
If path.Exists(SFO.Path, False) Then
|
||||
Dim files As List(Of SFile) = SFile.GetFiles(path, "*.xml",, EDP.ReturnValue)
|
||||
If files.Count > 0 Then files.ForEach(Sub(f) l.Add(New DownloadableMediaHost(f)))
|
||||
End If
|
||||
If l.Count > 0 Then l.ListDisposeRemoveAll(Function(c) Not c.Exists)
|
||||
Return l
|
||||
Catch ex As Exception
|
||||
Return ErrorsDescriber.Execute(EDP.SendToLog, ex, "VideoListForm.LoadData_GetFiles", New List(Of IYouTubeMediaContainer))
|
||||
End Try
|
||||
End Function
|
||||
Protected Overrides Sub BTT_ADD_KeyClick(ByVal Sender As ToolStripMenuItemKeyClick, ByVal e As KeyClickEventArgs)
|
||||
Dim __tag$ = UniversalFunctions.IfNullOrEmpty(Of Object)(Sender.Tag, String.Empty)
|
||||
If Not __tag = "a" And Not __tag = UrlsArrTag Then
|
||||
MyBase.BTT_ADD_KeyClick(Sender, e)
|
||||
Else
|
||||
Dim url$ = String.Empty
|
||||
Try
|
||||
url = BufferText
|
||||
Dim output As SFile = Settings.LatestSavingPath
|
||||
Dim isArr As Boolean = __tag = UrlsArrTag
|
||||
Dim formOpened As Boolean = False
|
||||
Dim media As IYouTubeMediaContainer
|
||||
Dim formValues As Func(Of DialogResult) = Function() As DialogResult
|
||||
formOpened = True
|
||||
If url.IsEmptyString OrElse Not url.StartsWith("http") Then url = String.Empty
|
||||
Using f As New DownloaderUrlForm With {.URL = url}
|
||||
f.ShowDialog()
|
||||
If f.DialogResult = DialogResult.OK Then
|
||||
url = f.URL
|
||||
output = f.OutputPath
|
||||
Settings.LatestSavingPath.Value = output
|
||||
If Settings.STDownloader_UpdateYouTubeOutputPath Then _
|
||||
API.YouTube.MyYouTubeSettings.OutputPath.Value = output
|
||||
Return DialogResult.OK
|
||||
Else
|
||||
Return DialogResult.Cancel
|
||||
End If
|
||||
End Using
|
||||
End Function
|
||||
Dim TryYouTube As Func(Of Boolean) = Function() As Boolean
|
||||
If YouTubeFunctions.IsMyUrl(url) Then
|
||||
BufferText = url
|
||||
MyBase.BTT_ADD_KeyClick(Sender, e)
|
||||
Return True
|
||||
Else
|
||||
Return False
|
||||
End If
|
||||
End Function
|
||||
Dim canProcessUrl As Func(Of String, Boolean, Boolean) =
|
||||
Function(ByVal __url As String, ByVal ShowMsg As Boolean) As Boolean
|
||||
Dim exists As Boolean = False
|
||||
If Not __url.IsEmptyString And TP_CONTROLS.Controls.Count > 0 Then _
|
||||
exists = ControlInvokeFast(TP_CONTROLS, Function() TP_CONTROLS.Controls.Cast(Of MediaItem).ListExists(Function(m) _
|
||||
If(m.MyContainer?.URL, String.Empty) = __url), False, EDP.ReturnValue)
|
||||
If exists Then
|
||||
If ShowMsg Then
|
||||
Return MsgBoxE({$"The URL you are trying to add already exists.{vbCr}Do you still want to add it again?{vbCr}{__url}",
|
||||
"Add URL..."}, vbExclamation,,, {"Add", "Cancel"}) = 0
|
||||
Else
|
||||
Return False
|
||||
End If
|
||||
Else
|
||||
Return True
|
||||
End If
|
||||
End Function
|
||||
|
||||
If output.IsEmptyString Then output = API.YouTube.MyYouTubeSettings.OutputPath
|
||||
|
||||
If isArr Then
|
||||
Dim urls As List(Of String)
|
||||
Dim cntAdded As Boolean = False
|
||||
Using fa As New DownloaderUrlsArrForm
|
||||
fa.ShowDialog()
|
||||
If fa.DialogResult = DialogResult.OK Then
|
||||
urls = fa.URLs.ToList
|
||||
output = fa.OutputPath
|
||||
Else
|
||||
Exit Sub
|
||||
End If
|
||||
End Using
|
||||
If urls.ListExists Then
|
||||
urls.ListForEach(Function(uu, ii) uu.StringTrim,, False)
|
||||
urls.RemoveAll(Function(uu) url.IsEmptyString OrElse Not url.StartsWith("http") OrElse Not canProcessUrl(uu, False))
|
||||
End If
|
||||
If urls.ListExists Then
|
||||
For Each url In urls
|
||||
If Not TryYouTube.Invoke Then
|
||||
media = FindSource(url, output)
|
||||
If Not media Is Nothing Then ControlCreateAndAdd(media, True) : cntAdded = True
|
||||
End If
|
||||
Next
|
||||
If cntAdded And Settings.STDownloader_DownloadAutomatically Then BTT_DOWN.PerformClick()
|
||||
urls.Clear()
|
||||
Else
|
||||
MsgBoxE({"There are no valid URLs in the list", "Add URLs array"}, vbCritical)
|
||||
End If
|
||||
Else
|
||||
If formValues.Invoke = DialogResult.Cancel Then Exit Sub
|
||||
If canProcessUrl(url, True) Then
|
||||
If TryYouTube.Invoke Then Exit Sub
|
||||
media = FindSource(url, output)
|
||||
Else
|
||||
Exit Sub
|
||||
End If
|
||||
If media Is Nothing And Not formOpened Then
|
||||
If formValues.Invoke = DialogResult.Cancel Then
|
||||
Exit Sub
|
||||
Else
|
||||
If canProcessUrl(url, True) Then
|
||||
If TryYouTube.Invoke Then Exit Sub
|
||||
media = FindSource(url, output)
|
||||
Else
|
||||
Exit Sub
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
If media Is Nothing Then
|
||||
MsgBoxE({$"The URL you entered is not recognized by existing plugins.{vbCr}{url}", "Download video"}, vbCritical)
|
||||
Else
|
||||
ControlCreateAndAdd(media)
|
||||
End If
|
||||
End If
|
||||
Catch ex As Exception
|
||||
ErrorsDescriber.Execute(EDP.LogMessageValue, ex, $"Error when trying to download video from URL: [{url}]")
|
||||
End Try
|
||||
End If
|
||||
End Sub
|
||||
Private Function FindSource(ByVal URL As String, ByVal OutputFile As SFile) As IYouTubeMediaContainer
|
||||
If Not URL.IsEmptyString Then
|
||||
If URL.Contains("gfycat") Then
|
||||
Return API.Gfycat.Envir.GetSingleMediaInstance(URL, OutputFile)
|
||||
ElseIf URL.Contains("imgur.com") Then
|
||||
Return API.Imgur.Envir.GetSingleMediaInstance(URL, OutputFile)
|
||||
Else
|
||||
For i% = 0 To Settings.Plugins.Count - 1
|
||||
With Settings.Plugins(i).Settings
|
||||
If .IsMyImageVideo(URL).Exists Then Return .GetSingleMediaInstance(URL, OutputFile)
|
||||
End With
|
||||
Next
|
||||
End If
|
||||
End If
|
||||
Return Nothing
|
||||
End Function
|
||||
Protected Overrides Sub BTT_CLEAR_DONE_Click(sender As Object, e As EventArgs)
|
||||
If Settings.STDownloader_RemoveYTVideosOnClear Then
|
||||
MyBase.BTT_CLEAR_DONE_Click(sender, e)
|
||||
Else
|
||||
RemoveControls(ControlsDownloadedNonYT)
|
||||
End If
|
||||
End Sub
|
||||
Protected Overrides Sub BTT_CLEAR_ALL_Click(sender As Object, e As EventArgs)
|
||||
If Settings.STDownloader_RemoveYTVideosOnClear Then
|
||||
MyBase.BTT_CLEAR_ALL_Click(sender, e)
|
||||
Else
|
||||
RemoveControls(ControlNonYT)
|
||||
End If
|
||||
End Sub
|
||||
Protected Overrides Sub MyJob_Finished(ByVal Sender As Object, ByVal e As EventArgs)
|
||||
MainFrameObj.UpdateLogButton()
|
||||
MyBase.MyJob_Finished(Sender, e)
|
||||
End Sub
|
||||
End Class
|
||||
End Namespace
|
||||
Reference in New Issue
Block a user