Files
SCrawler/SCrawler/Download/DownloadProgress.vb
Andy 938042ea9e 2023.6.5.0
YT settings: removed property 'ItemsListLimit', add property 'ReplaceModificationDate'
YT.MediaItem: fix 'Pending'
YT.VideoListForm: add 'Shift' to add without downloading; add 'F5' hot key to start download; remove list items limit; fix item 'Pending', fixed items queue

UserDataBase: add 'IconBannerDownloaded' properties; add 'HOST.Available' check to 'DownloadSingleObject'; update file deletion in 'DownloadContentDefault'; add truncating '_TempPostsList' if number of ids > 1000
Instagram: add authorization headers
Mastodon: implement 'DownloadIconBanner'; update 'ReparseMissing' function
Reddit: implement 'DownloadIconBanner'
Twitter: implement 'DownloadIconBanner'; update parsers to parse posts with two videos; implement gallery-dl for all function; remove headers from settings
Download.DownloadProgress: remove main progress perform when downloading saved posts
VideoDownloaderForm: bind the 'BTT_ADD_URLS_ARR' button to the 'BTT_ADD_KeyClick' function
UsersInfoForm: add folder opening on double click on an item
ListImagesLoader: fix refill bug when the number of filtered profiles = 0
TrayIcon: add standalone downloader to context menu
DownloadableMediaHost: fix a bug when not downloaded videos do not appear in the list when loading the program
2023-06-05 19:36:35 +03:00

234 lines
11 KiB
VB.net

' 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 PersonalUtilities.Forms.Toolbars
Imports Download = SCrawler.Plugin.ISiteSettings.Download
Imports TDJob = SCrawler.DownloadObjects.TDownloader.Job
Namespace DownloadObjects
Friend Class DownloadProgress : Implements IDisposable
#Region "Events"
Friend Event DownloadDone As NotificationEventHandler
Friend Event ProgressMaximumChanged()
Friend Event ProgressMaximum0Changed()
#End Region
#Region "Declarations"
#Region "Controls"
Private ReadOnly TP_MAIN As TableLayoutPanel
Private ReadOnly TP_CONTROLS As TableLayoutPanel
Private WithEvents BTT_START As Button
Private WithEvents BTT_STOP As Button
Private WithEvents BTT_OPEN As Button
Private ReadOnly PR_MAIN As ProgressBar
Private ReadOnly LBL_INFO As Label
Private ReadOnly Icon As PictureBox
#End Region
Private ReadOnly Property Instance As API.Base.ProfileSaved
Friend ReadOnly Property Job As TDJob
#End Region
#Region "Initializer"
Friend Sub New(ByVal _Job As TDJob)
Job = _Job
TP_MAIN = New TableLayoutPanel With {.Margin = New Padding(0), .Dock = DockStyle.Fill}
TP_MAIN.ColumnStyles.Add(New ColumnStyle(SizeType.Percent, 100))
TP_MAIN.ColumnCount = 1
TP_CONTROLS = New TableLayoutPanel With {.Margin = New Padding(0), .Dock = DockStyle.Fill}
PR_MAIN = New ProgressBar With {.Dock = DockStyle.Fill}
LBL_INFO = New Label With {.Text = String.Empty, .Dock = DockStyle.Fill}
Icon = New PictureBox With {
.SizeMode = PictureBoxSizeMode.Zoom,
.Dock = DockStyle.Fill,
.Margin = New Padding(3),
.Padding = New Padding(3)
}
CreateButton(BTT_STOP, My.Resources.DeletePic_24)
Dim img As Image = Nothing
If Not _Job.Host Is Nothing Then
With Job.Host.Source
If Not .Icon Is Nothing Then img = .Icon.ToBitmap
If img Is Nothing AndAlso Not .Image Is Nothing Then img = .Image
End With
End If
If Not img Is Nothing Then Icon.Image = img : Icon.InitialImage = img
If Job.Type = Download.Main Then
LBL_INFO.Margin = New Padding(3)
LBL_INFO.TextAlign = ContentAlignment.MiddleLeft
With TP_MAIN
.RowStyles.Add(New RowStyle(SizeType.Percent, 100))
.RowCount = 1
End With
With TP_CONTROLS
.ColumnStyles.Add(New ColumnStyle(SizeType.Absolute, 30))
.ColumnStyles.Add(New ColumnStyle(SizeType.Absolute, 30))
.ColumnStyles.Add(New ColumnStyle(SizeType.Absolute, 150))
.ColumnStyles.Add(New ColumnStyle(SizeType.Percent, 100))
.ColumnCount = .ColumnStyles.Count
.RowStyles.Add(New RowStyle(SizeType.Percent, 100))
.RowCount = 1
With .Controls
If Not img Is Nothing Then .Add(Icon, 0, 0)
.Add(BTT_STOP, 1, 0)
.Add(PR_MAIN, 2, 0)
.Add(LBL_INFO, 3, 0)
End With
End With
TP_MAIN.Controls.Add(TP_CONTROLS, 0, 0)
Else
LBL_INFO.Padding = New Padding(3, 0, 3, 0)
LBL_INFO.TextAlign = ContentAlignment.TopCenter
CreateButton(BTT_START, My.Resources.StartPic_Green_16)
CreateButton(BTT_OPEN, PersonalUtilities.My.Resources.FolderOpenPic_Black_16)
With TP_CONTROLS
With .ColumnStyles
.Add(New ColumnStyle(SizeType.Absolute, 30))
.Add(New ColumnStyle(SizeType.Absolute, 30))
.Add(New ColumnStyle(SizeType.Absolute, 30))
.Add(New ColumnStyle(SizeType.Absolute, 30))
.Add(New ColumnStyle(SizeType.Percent, 100))
End With
.ColumnCount = .ColumnStyles.Count
.RowStyles.Add(New RowStyle(SizeType.Percent, 50))
.RowCount = 1
With .Controls
If Not img Is Nothing Then .Add(Icon, 0, 0)
.Add(BTT_START, 1, 0)
.Add(BTT_STOP, 2, 0)
.Add(BTT_OPEN, 3, 0)
.Add(PR_MAIN, 4, 0)
End With
End With
With TP_MAIN
With .RowStyles
.Add(New RowStyle(SizeType.Absolute, 30))
.Add(New RowStyle(SizeType.Percent, 100))
End With
.RowCount = 2
End With
TP_MAIN.Controls.Add(TP_CONTROLS, 0, 0)
TP_MAIN.Controls.Add(LBL_INFO, 0, 1)
End If
With Job
.Progress = New MyProgressExt(PR_MAIN, LBL_INFO) With {.ResetProgressOnMaximumChanges = False}
With DirectCast(.Progress, MyProgressExt)
AddHandler .ProgressChanged, AddressOf JobProgress_ProgressChanged
AddHandler .MaximumChanged, AddressOf JobProgress_MaximumChanged
AddHandler .Maximum0Changed, AddressOf JobProgress_Maximum0Changed
AddHandler .Progress0Changed, AddressOf JobProgress_Progress0Changed
End With
End With
If Job.Type = Download.SavedPosts And Not Job.Progress Is Nothing Then Job.Progress.InformationTemporary = Job.Host.Name
Instance = New API.Base.ProfileSaved(Job.Host, Job.Progress)
End Sub
Private Sub CreateButton(ByRef BTT As Button, ByVal Img As Image)
BTT = New Button With {
.BackgroundImage = Img,
.BackgroundImageLayout = ImageLayout.Zoom,
.Text = String.Empty,
.Dock = DockStyle.Fill
}
End Sub
#End Region
Friend Function [Get]() As TableLayoutPanel
Return TP_MAIN
End Function
#Region "Buttons"
Private Sub BTT_START_Click(sender As Object, e As EventArgs) Handles BTT_START.Click
Start()
End Sub
Private Sub BTT_STOP_Click(sender As Object, e As EventArgs) Handles BTT_STOP.Click
[Stop]()
End Sub
Private Sub BTT_OPEN_Click(sender As Object, e As EventArgs) Handles BTT_OPEN.Click
GlobalOpenPath(Job.Host.SavedPostsPath)
End Sub
#End Region
#Region "Start, Stop"
Private _IsMultiple As Boolean = False
Friend Sub Start(Optional ByVal Multiple As Boolean = False)
_IsMultiple = Multiple
Job.StartThread(AddressOf DownloadData)
End Sub
Friend Sub [Stop]()
Job.Cancel()
End Sub
#End Region
#Region "SavedPosts downloading"
Private Sub DownloadData()
Dim btte As Action(Of Button, Boolean) = Sub(b, e) If b.InvokeRequired Then b.Invoke(Sub() b.Enabled = e) Else b.Enabled = e
Try
btte.Invoke(BTT_START, False)
btte.Invoke(BTT_STOP, True)
Job.Progress.InformationTemporary = $"{Job.Host.Name} downloading started"
Job.Start()
Instance.Download(Job.Token, _IsMultiple)
RaiseEvent DownloadDone(SettingsCLS.NotificationObjects.SavedPosts, $"Downloading saved {Job.Host.Name} posts is completed")
Catch ex As Exception
Job.Progress.InformationTemporary = $"{Job.Host.Name} downloading error"
ErrorsDescriber.Execute(EDP.LogMessageValue, ex, {$"{Job.Host.Name} saved posts downloading error", "Saved posts"})
Finally
_IsMultiple = False
btte.Invoke(BTT_START, True)
btte.Invoke(BTT_STOP, False)
Job.Finish()
If Job.Type = Download.SavedPosts Then Job.Progress.Maximum = 0 : Job.Progress.Value = 0
End Try
End Sub
#End Region
#Region "Progress, Jobs count"
Private Sub JobProgress_MaximumChanged(ByVal Sender As Object, ByVal e As ProgressEventArgs)
RaiseEvent ProgressMaximumChanged()
End Sub
Private Sub JobProgress_Maximum0Changed(ByVal Sender As Object, ByVal e As ProgressEventArgs)
RaiseEvent ProgressMaximum0Changed()
End Sub
Private Sub JobProgress_ProgressChanged(ByVal Sender As Object, ByVal e As ProgressEventArgs)
If Not Job.Type = Download.SavedPosts Then
MainProgress.Value = DirectCast(Sender, MyProgressExt).Value
MainProgress.Perform(0)
End If
End Sub
Private Sub JobProgress_Progress0Changed(ByVal Sender As Object, ByVal e As ProgressEventArgs)
If Not Job.Type = Download.SavedPosts Then
MainProgress.Value0 = DirectCast(Sender, MyProgressExt).Value0
MainProgress.Perform0(0)
End If
End Sub
#End Region
#Region "IDisposable Support"
Private disposedValue As Boolean = False
Protected Overridable Overloads Sub Dispose(ByVal disposing As Boolean)
If Not disposedValue Then
If disposing Then
If Not BTT_START Is Nothing Then BTT_START.Dispose()
If Not BTT_STOP Is Nothing Then BTT_STOP.Dispose()
If Not BTT_OPEN Is Nothing Then BTT_OPEN.Dispose()
If Not Icon Is Nothing Then Icon.Dispose()
PR_MAIN.Dispose()
LBL_INFO.Dispose()
TP_CONTROLS.Controls.Clear()
TP_CONTROLS.Dispose()
TP_MAIN.Controls.Clear()
TP_MAIN.Dispose()
End If
disposedValue = True
End If
End Sub
Protected Overrides Sub Finalize()
Dispose(False)
MyBase.Finalize()
End Sub
Friend Overloads Sub Dispose() Implements IDisposable.Dispose
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
#End Region
End Class
End Namespace