From 3ea59a6acdd259968312317ea321d51283a54a0a Mon Sep 17 00:00:00 2001 From: Andy <88590076+AAndyProgram@users.noreply.github.com> Date: Sun, 3 Sep 2023 19:38:18 +0300 Subject: [PATCH] 2023.8.27.0 YT: fix 'Shorts' downloading --- SCrawler.YouTube/Base/YouTubeFunctions.vb | 10 ++++++---- SCrawler.YouTube/Objects/IYouTubeMediaContainer.vb | 1 + SCrawler.YouTube/Objects/YouTubeMediaContainerBase.vb | 2 +- SCrawler/API/YouTube/SiteSettings.vb | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/SCrawler.YouTube/Base/YouTubeFunctions.vb b/SCrawler.YouTube/Base/YouTubeFunctions.vb index b686a33..5ffcff5 100644 --- a/SCrawler.YouTube/Base/YouTubeFunctions.vb +++ b/SCrawler.YouTube/Base/YouTubeFunctions.vb @@ -23,17 +23,19 @@ Namespace API.YouTube.Base Public Shared Function IsMyUrl(ByVal URL As String) As Boolean Return Not Info_GetUrlType(URL) = YouTubeMediaType.Undefined End Function - Public Shared Function Info_GetUrlType(ByVal URL As String, Optional ByRef IsMusic As Boolean = False, + Public Shared Function Info_GetUrlType(ByVal URL As String, Optional ByRef IsMusic As Boolean = False, Optional ByRef IsShorts As Boolean = False, Optional ByRef IsChannelUser As Boolean = False, Optional ByRef Id As String = Nothing) As YouTubeMediaType If Not URL.IsEmptyString Then IsMusic = URL.Contains("music.youtube.com") IsChannelUser = False + IsShorts = False Dim data As List(Of String) = RegexReplace(URL, RParams.DMS(UrlTypePattern, 0, RegexReturn.ListByMatch, EDP.ReturnValue)) If data.ListExists Then If data.Count >= 6 Then Id = data(5) If data.Count >= 3 And Not data(2).IsEmptyString Then Select Case data(2).ToLower Case "watch" : Return YouTubeMediaType.Single + Case "shorts" : IsShorts = True : Return YouTubeMediaType.Single Case "playlist" : Return YouTubeMediaType.PlayList Case UserChannelOption, "@" : IsChannelUser = data(2).ToLower = UserChannelOption : Return YouTubeMediaType.Channel End Select @@ -64,8 +66,8 @@ Namespace API.YouTube.Base Dim urlOrig$ = URL URL = RegexReplace(URL, TrueUrlRegEx) If URL.IsEmptyString Then Throw New ArgumentNullException("URL", $"Can't get true URL from [{urlOrig}]") - Dim isMusic As Boolean = False - Dim objType As YouTubeMediaType = Info_GetUrlType(URL, isMusic) + Dim isMusic As Boolean = False, isShorts As Boolean = False + Dim objType As YouTubeMediaType = Info_GetUrlType(URL, isMusic, isShorts) If Not objType = YouTubeMediaType.Undefined Then Dim __GetDefault As Boolean = If(GetDefault, True) Dim __GetShorts As Boolean = If(GetShorts, True) @@ -105,7 +107,7 @@ Namespace API.YouTube.Base If result Then container.Parse(Nothing, _CachePathDefault, isMusic, Token, Progress) - If Not container.HasError Then container.URL = URL : Return container + If Not container.HasError Then container.URL = URL : container.IsShorts = isShorts : Return container End If container.Dispose() End If diff --git a/SCrawler.YouTube/Objects/IYouTubeMediaContainer.vb b/SCrawler.YouTube/Objects/IYouTubeMediaContainer.vb index 2d2c7da..4447c7b 100644 --- a/SCrawler.YouTube/Objects/IYouTubeMediaContainer.vb +++ b/SCrawler.YouTube/Objects/IYouTubeMediaContainer.vb @@ -25,6 +25,7 @@ Namespace API.YouTube.Objects ReadOnly Property MediaType As UMTypes ReadOnly Property MediaState As UMStates Property IsMusic As Boolean + Property IsShorts As Boolean Property ID As String Property Description As String Property PlaylistID As String diff --git a/SCrawler.YouTube/Objects/YouTubeMediaContainerBase.vb b/SCrawler.YouTube/Objects/YouTubeMediaContainerBase.vb index dfd08d8..263745c 100644 --- a/SCrawler.YouTube/Objects/YouTubeMediaContainerBase.vb +++ b/SCrawler.YouTube/Objects/YouTubeMediaContainerBase.vb @@ -112,7 +112,7 @@ Namespace API.YouTube.Objects End Set End Property Public Property IsMusic As Boolean = False Implements IYouTubeMediaContainer.IsMusic - Public Property IsShorts As Boolean = False + Public Property IsShorts As Boolean = False Implements IYouTubeMediaContainer.IsShorts Public Property ID As String Implements IYouTubeMediaContainer.ID, IUserMedia.PostID Public Property Title As String Implements IDownloadableMedia.Title Public Property Description As String Implements IYouTubeMediaContainer.Description diff --git a/SCrawler/API/YouTube/SiteSettings.vb b/SCrawler/API/YouTube/SiteSettings.vb index 9163f25..243bad9 100644 --- a/SCrawler/API/YouTube/SiteSettings.vb +++ b/SCrawler/API/YouTube/SiteSettings.vb @@ -82,7 +82,7 @@ Namespace API.YouTube Dim isMusic As Boolean = False Dim id$ = String.Empty Dim isChannelUser As Boolean = False - Dim t As YouTubeMediaType = YouTubeFunctions.Info_GetUrlType(UserURL, isMusic, isChannelUser, id) + Dim t As YouTubeMediaType = YouTubeFunctions.Info_GetUrlType(UserURL, isMusic,, isChannelUser, id) If Not t = YouTubeMediaType.Undefined And Not t = YouTubeMediaType.Single And Not id.IsEmptyString Then Return New ExchangeOptions(Site, $"{id}@{CInt(t) + IIf(isMusic, UserMedia.Types.Audio, 0) + IIf(isChannelUser, ChannelUserInt, 0)}") End If