Skip to content

Commit

Permalink
fix: refine PlatformType and DatabaseType handling
Browse files Browse the repository at this point in the history
- 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: 陳鈞 <[email protected]>
  • Loading branch information
jim60105 committed May 21, 2024
1 parent 758d8f0 commit ea70399
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
48 changes: 32 additions & 16 deletions Helper/NameHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
}
Expand All @@ -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(),
};
}
Expand Down
2 changes: 1 addition & 1 deletion SingletonServices/Kubernetes/Downloader/YtdlpService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ea70399

Please sign in to comment.