From ea7039967214aaefe1f4722521165be96ec9eaed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=B3=E9=88=9E?= Date: Tue, 21 May 2024 17:15:14 +0800 Subject: [PATCH] fix: refine PlatformType and DatabaseType handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Modify the handling of channel and video Ids for YouTube, Twitch, Twitcasting, and FC2 to better handle prefix changes for these platforms in `NameHelper.cs` - Correct the URL formation process in `YtdlpService.cs` to remove the unnecessary Id handling, thus directly appending `url` to the YouTube base URL Signed-off-by: 陳鈞 --- Helper/NameHelper.cs | 48 ++++++++++++------- .../Kubernetes/Downloader/YtdlpService.cs | 2 +- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/Helper/NameHelper.cs b/Helper/NameHelper.cs index 1368182..4aedd09 100644 --- a/Helper/NameHelper.cs +++ b/Helper/NameHelper.cs @@ -34,20 +34,28 @@ public static class ChannelId public static string PlatformType(string channelId, string platform) => platform switch { - "Youtube" or IYtarchiveService.Name or IYtdlpService.Name => channelId, // Youtube channelId already starts with "UC" - "Twitch" or IStreamlinkService.Name => channelId[2..], - "Twitcasting" or ITwitcastingRecorderService.Name => channelId[2..], - "FC2" or IFc2LiveDLService.Name => channelId[2..], + "Youtube" or IYtarchiveService.Name or IYtdlpService.Name + => channelId, // Youtube channelId already starts with "UC" + "Twitch" or IStreamlinkService.Name + => channelId.StartsWith("TW") ? channelId[2..] : channelId, + "Twitcasting" or ITwitcastingRecorderService.Name + => channelId.StartsWith("TC") ? channelId[2..] : channelId, + "FC2" or IFc2LiveDLService.Name + => channelId.StartsWith("FC") ? channelId[2..] : channelId, _ => throw new NotImplementedException(), }; public static string DatabaseType(string channelId, string platform) => platform switch { - "Youtube" or IYtarchiveService.Name or IYtdlpService.Name => channelId, // Youtube channelId always starts with "UC" - "Twitch" or IStreamlinkService.Name => "TW" + channelId, - "Twitcasting" or ITwitcastingRecorderService.Name => "TC" + channelId, - "FC2" or IFc2LiveDLService.Name => "FC" + channelId, + "Youtube" or IYtarchiveService.Name or IYtdlpService.Name + => channelId, // Youtube channelId always starts with "UC" + "Twitch" or IStreamlinkService.Name + => channelId.StartsWith("TW") ? channelId : "TW" + channelId, + "Twitcasting" or ITwitcastingRecorderService.Name + => channelId.StartsWith("TC") ? channelId : "TC" + channelId, + "FC2" or IFc2LiveDLService.Name + => channelId.StartsWith("FC") ? channelId : "FC" + channelId, _ => throw new NotImplementedException(), }; } @@ -57,20 +65,28 @@ public static class VideoId public static string PlatformType(string videoId, string platform) => platform switch { - "Youtube" or IYtarchiveService.Name or IYtdlpService.Name => videoId[1..], - "Twitch" or IStreamlinkService.Name => videoId[2..], - "Twitcasting" or ITwitcastingRecorderService.Name => videoId[2..], - "FC2" or IFc2LiveDLService.Name => videoId[2..], + "Youtube" or IYtarchiveService.Name or IYtdlpService.Name + => videoId.TrimStart('Y'), + "Twitch" or IStreamlinkService.Name + => videoId.StartsWith("TW") ? videoId[2..] : videoId, + "Twitcasting" or ITwitcastingRecorderService.Name + => videoId.StartsWith("TC") ? videoId[2..] : videoId, + "FC2" or IFc2LiveDLService.Name + => videoId.StartsWith("FC") ? videoId[2..] : videoId, _ => throw new NotImplementedException(), }; public static string DatabaseType(string videoId, string platform) => platform switch { - "Youtube" or IYtarchiveService.Name or IYtdlpService.Name => "Y" + videoId, - "Twitch" or IStreamlinkService.Name => "TW" + videoId, - "Twitcasting" or ITwitcastingRecorderService.Name => "TC" + videoId, - "FC2" or IFc2LiveDLService.Name => "FC" + videoId, + "Youtube" or IYtarchiveService.Name or IYtdlpService.Name + => videoId.StartsWith('Y') ? videoId : "Y" + videoId, + "Twitch" or IStreamlinkService.Name + => videoId.StartsWith("TW") ? videoId : "TW" + videoId, + "Twitcasting" or ITwitcastingRecorderService.Name + => videoId.StartsWith("TC") ? videoId : "TC" + videoId, + "FC2" or IFc2LiveDLService.Name + => videoId.StartsWith("FC") ? videoId : "FC" + videoId, _ => throw new NotImplementedException(), }; } diff --git a/SingletonServices/Kubernetes/Downloader/YtdlpService.cs b/SingletonServices/Kubernetes/Downloader/YtdlpService.cs index ff1afea..c72bc90 100644 --- a/SingletonServices/Kubernetes/Downloader/YtdlpService.cs +++ b/SingletonServices/Kubernetes/Downloader/YtdlpService.cs @@ -23,7 +23,7 @@ public override Task CreateJobAsync(Video video, url ??= NameHelper.ChangeId.VideoId.PlatformType(video.id, Name); if (!url.StartsWith("http")) - url = $"https://youtu.be/{NameHelper.ChangeId.VideoId.PlatformType(url, Name)}"; + url = $"https://youtu.be/{url}"; const string mountPath = "/download"; string fileName = NameHelper.GetFileName(video, IYtdlpService.Name);