From 0026e905a494f579ad6e2a35c7d7c58efd4038ec Mon Sep 17 00:00:00 2001 From: Andy <88590076+AAndyProgram@users.noreply.github.com> Date: Tue, 19 Sep 2023 12:55:53 +0300 Subject: [PATCH] 2023.9.19.0 YT: add priority download protocol --- SCrawler.YouTube/Base/Structures.vb | 23 +++++++++++++++++++ SCrawler.YouTube/Base/YouTubeSettings.vb | 3 +++ .../Objects/YouTubeMediaContainerBase.vb | 20 ++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/SCrawler.YouTube/Base/Structures.vb b/SCrawler.YouTube/Base/Structures.vb index cf3bc77..5540dc1 100644 --- a/SCrawler.YouTube/Base/Structures.vb +++ b/SCrawler.YouTube/Base/Structures.vb @@ -6,6 +6,10 @@ ' ' This program is distributed in the hope that it will be useful, ' but WITHOUT ANY WARRANTY +Imports System.Drawing.Design +Imports System.ComponentModel +Imports PersonalUtilities.Tools.Grid.Attributes +Imports PersonalUtilities.Tools.Grid.EnumObjects Namespace API.YouTube.Base Public Structure Thumbnail : Implements IIndexable, IComparable(Of Thumbnail) Public ID As String @@ -47,6 +51,14 @@ Namespace API.YouTube.Base Channel = 2 PlayList = 3 End Enum + + Public Enum Protocols As Integer + + Undefined = -1 + Any = 0 + https = 1 + m3u8 = 2 + End Enum Public Structure MediaObject : Implements IIndexable, IComparable(Of MediaObject) Public Type As Plugin.UserMediaTypes Public ID As String @@ -59,6 +71,17 @@ Namespace API.YouTube.Base Public Size As Double Public Codec As String Public Protocol As String + Public ReadOnly Property ProtocolType As Protocols + Get + If Not Protocol.IsEmptyString Then + Select Case Protocol.StringToLower.StringTrim + Case "http", "https" : Return Protocols.https + Case "m3u8" : Return Protocols.m3u8 + End Select + End If + Return Protocols.Undefined + End Get + End Property Public URL As String Public Property Index As Integer Implements IIndexable.Index Private Function SetIndex(ByVal Obj As Object, ByVal Index As Integer) As Object Implements IIndexable.SetIndex diff --git a/SCrawler.YouTube/Base/YouTubeSettings.vb b/SCrawler.YouTube/Base/YouTubeSettings.vb index 68f2e35..9cbda9e 100644 --- a/SCrawler.YouTube/Base/YouTubeSettings.vb +++ b/SCrawler.YouTube/Base/YouTubeSettings.vb @@ -139,6 +139,9 @@ Namespace API.YouTube.Base Public ReadOnly Property DefaultUseCookies As XMLValue(Of Boolean) + + Public ReadOnly Property DefaultProtocol As XMLValue(Of Protocols) Public ReadOnly Property RemoveDownloadedAutomatically As XMLValue(Of Boolean) diff --git a/SCrawler.YouTube/Objects/YouTubeMediaContainerBase.vb b/SCrawler.YouTube/Objects/YouTubeMediaContainerBase.vb index 263745c..0b32d51 100644 --- a/SCrawler.YouTube/Objects/YouTubeMediaContainerBase.vb +++ b/SCrawler.YouTube/Objects/YouTubeMediaContainerBase.vb @@ -1309,9 +1309,29 @@ Namespace API.YouTube.Objects Next End If End Sub + Dim protocolCleaner As Action = + Sub() + If Not MyYouTubeSettings.DefaultProtocol.Value = Protocols.Undefined And + Not MyYouTubeSettings.DefaultProtocol.Value = Protocols.Any Then + Dim data As New List(Of MediaObject)(MediaObjects.Where(Function(mo) mo.ProtocolType = MyYouTubeSettings.DefaultProtocol.Value)) + If data.ListExists Then + Dim dRem As Protocols = IIf(MyYouTubeSettings.DefaultProtocol.Value = Protocols.https, Protocols.m3u8, Protocols.https) + Dim d As MediaObject + Dim dr As New FPredicate(Of MediaObject)(Function(mo) mo.Height = d.Height And mo.ProtocolType = dRem) + For Each d In data + If MediaObjects.Count = 0 Then + Exit For + ElseIf MediaObjects.LongCount(dr) > 0 Then + MediaObjects.RemoveAll(dr) + End If + Next + End If + End If + End Sub If MediaObjects.Count > 0 And Not MyYouTubeSettings.DefaultVideoIncludeNullSize Then MediaObjects.RemoveAll(Function(mo) mo.Size <= 0) If MediaObjects.Count > 0 Then DupRemover.Invoke(UMTypes.Audio) If MediaObjects.Count > 0 Then DupRemover.Invoke(UMTypes.Video) + If MediaObjects.Count > 0 Then protocolCleaner.Invoke If MediaObjects.Count > 0 Then MediaObjects.Sort() SelectedAudioIndex = MediaObjects.FindIndex(Function(mo) mo.Type = UMTypes.Audio)