From 23b925b31470936e0ff095871fc819ce8c9546ff Mon Sep 17 00:00:00 2001 From: Elwador <75888166+Elwador@users.noreply.github.com> Date: Sun, 26 May 2024 02:27:31 +0200 Subject: [PATCH] Chg - Use identifier for some season numbers --- CRD/Downloader/CrEpisode.cs | 7 ++++--- CRD/Downloader/CrSeries.cs | 7 ++++--- CRD/Downloader/Crunchyroll.cs | 4 ++-- CRD/Downloader/History.cs | 18 +++++++++--------- CRD/Utils/Files/FileNameManager.cs | 4 ++++ CRD/Utils/Helpers.cs | 20 ++++++++++++++++++++ CRD/Utils/Structs/EpisodeStructs.cs | 2 +- 7 files changed, 44 insertions(+), 18 deletions(-) diff --git a/CRD/Downloader/CrEpisode.cs b/CRD/Downloader/CrEpisode.cs index 7e4d098..b37c315 100644 --- a/CRD/Downloader/CrEpisode.cs +++ b/CRD/Downloader/CrEpisode.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Collections.Specialized; +using System.Globalization; using System.Linq; using System.Net.Http; using System.Text.RegularExpressions; @@ -134,7 +135,7 @@ public class CrEpisode(){ ?? Regex.Replace(item.Items[0].SeasonTitle, @"\(\w+ Dub\)", "").TrimEnd(); var title = item.Items[0].Title; - var seasonNumber = item.Items[0].SeasonNumber; + var seasonNumber = Helpers.ExtractNumberAfterS(item.Items[0].Identifier) ?? item.Items[0].SeasonNumber.ToString(); var languages = item.Items.Select((a, index) => $"{(a.IsPremiumOnly ? "+ " : "")}{item.Langs.ElementAtOrDefault(index).Name ?? "Unknown"}").ToArray(); //☆ @@ -158,7 +159,7 @@ public class CrEpisode(){ E = key.StartsWith("E") ? key.Substring(1) : key, Lang = value.Langs.Select(a => a.Code).ToList(), Name = value.Items[0].Title, - Season = value.Items[0].SeasonNumber.ToString(), + Season = Helpers.ExtractNumberAfterS(value.Items[0].Identifier) ?? value.Items[0].SeasonNumber.ToString(), SeriesTitle = Regex.Replace(value.Items[0].SeriesTitle, @"\(\w+ Dub\)", "").TrimEnd(), SeasonTitle = Regex.Replace(value.Items[0].SeasonTitle, @"\(\w+ Dub\)", "").TrimEnd(), EpisodeNum = value.Items[0].EpisodeNumber?.ToString() ?? value.Items[0].Episode ?? "?", @@ -210,7 +211,7 @@ public class CrEpisode(){ epMeta.EpisodeNumber = item.Episode; epMeta.EpisodeTitle = item.Title; epMeta.SeasonId = item.SeasonId; - epMeta.Season = item.SeasonNumber; + epMeta.Season = Helpers.ExtractNumberAfterS(item.Identifier) ?? item.SeasonNumber + ""; epMeta.ShowId = item.SeriesId; epMeta.AbsolutEpisodeNumberE = epNum; epMeta.Image = images[images.Count / 2].FirstOrDefault().Source; diff --git a/CRD/Downloader/CrSeries.cs b/CRD/Downloader/CrSeries.cs index f6f34b9..b1a4e64 100644 --- a/CRD/Downloader/CrSeries.cs +++ b/CRD/Downloader/CrSeries.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Collections.Specialized; +using System.Globalization; using System.Linq; using System.Net.Http; using System.Net.Http.Headers; @@ -75,7 +76,7 @@ public class CrSeries(){ epMeta.EpisodeNumber = item.Episode; epMeta.EpisodeTitle = item.Title; epMeta.SeasonId = item.SeasonId; - epMeta.Season = item.SeasonNumber; + epMeta.Season = Helpers.ExtractNumberAfterS(item.Identifier) ?? item.SeasonNumber + ""; epMeta.ShowId = item.SeriesId; epMeta.AbsolutEpisodeNumberE = epNum; epMeta.Image = images[images.Count / 2].FirstOrDefault().Source; @@ -238,7 +239,7 @@ public class CrSeries(){ ?? Regex.Replace(item.Items[0].SeasonTitle, @"\(\w+ Dub\)", "").TrimEnd(); var title = item.Items[0].Title; - var seasonNumber = item.Items[0].SeasonNumber; + var seasonNumber = Helpers.ExtractNumberAfterS(item.Items[0].Identifier) ?? item.Items[0].SeasonNumber.ToString(); var languages = item.Items.Select((a, index) => $"{(a.IsPremiumOnly ? "+ " : "")}{item.Langs.ElementAtOrDefault(index).Name ?? "Unknown"}").ToArray(); //☆ @@ -262,7 +263,7 @@ public class CrSeries(){ E = key.StartsWith("E") ? key.Substring(1) : key, Lang = value.Langs.Select(a => a.Code).ToList(), Name = value.Items[0].Title, - Season = value.Items[0].SeasonNumber.ToString(), + Season = Helpers.ExtractNumberAfterS(value.Items[0].Identifier) ?? value.Items[0].SeasonNumber.ToString(), SeriesTitle = Regex.Replace(value.Items[0].SeriesTitle, @"\(\w+ Dub\)", "").TrimEnd(), SeasonTitle = Regex.Replace(value.Items[0].SeasonTitle, @"\(\w+ Dub\)", "").TrimEnd(), EpisodeNum = value.Items[0].EpisodeNumber?.ToString() ?? value.Items[0].Episode ?? "?", diff --git a/CRD/Downloader/Crunchyroll.cs b/CRD/Downloader/Crunchyroll.cs index 42e610f..3e9fdd7 100644 --- a/CRD/Downloader/Crunchyroll.cs +++ b/CRD/Downloader/Crunchyroll.cs @@ -639,8 +639,8 @@ public class Crunchyroll{ variables.Add(new Variable("episode", (int.TryParse(data.EpisodeNumber, out int episodeNum) ? (object)episodeNum : data.AbsolutEpisodeNumberE) ?? string.Empty, false)); variables.Add(new Variable("seriesTitle", data.SeriesTitle ?? string.Empty, true)); variables.Add(new Variable("showTitle", data.SeasonTitle ?? string.Empty, true)); - variables.Add(new Variable("season", data.Season ?? 0, false)); - + variables.Add(new Variable("season", data.Season != null ? Math.Round(double.Parse(data.Season, CultureInfo.InvariantCulture), 1) : 0, false)); + if (pbStreams?.Keys != null){ foreach (var key in pbStreams.Keys){ if ((key.Contains("hls") || key.Contains("dash")) && diff --git a/CRD/Downloader/History.cs b/CRD/Downloader/History.cs index df2fedb..e7d251b 100644 --- a/CRD/Downloader/History.cs +++ b/CRD/Downloader/History.cs @@ -112,14 +112,14 @@ public class History(){ if (historySeason != null){ historySeason.SeasonTitle = episode.SeasonTitle; - historySeason.SeasonNum = episode.SeasonNumber + ""; + historySeason.SeasonNum = Helpers.ExtractNumberAfterS(episode.Identifier) ?? episode.SeasonNumber + ""; if (historySeason.EpisodesList.All(e => e.EpisodeId != episode.Id)){ var newHistoryEpisode = new HistoryEpisode{ EpisodeTitle = episode.Identifier.Contains("|M|") ? episode.SeasonTitle : episode.Title, EpisodeDescription = episode.Description, EpisodeId = episode.Id, Episode = episode.Episode, - EpisodeSeasonNum = episode.SeasonNumber + "", + EpisodeSeasonNum = Helpers.ExtractNumberAfterS(episode.Identifier) ?? episode.SeasonNumber + "", SpecialEpisode = !int.TryParse(episode.Episode, out _), }; @@ -180,7 +180,7 @@ public class History(){ if (historySeason != null){ historySeason.SeasonTitle = firstEpisode.SeasonTitle; - historySeason.SeasonNum = firstEpisode.SeasonNumber + ""; + historySeason.SeasonNum = Helpers.ExtractNumberAfterS(firstEpisode.Identifier) ?? firstEpisode.SeasonNumber + ""; foreach (var crunchyEpisode in seasonData.Data){ var historyEpisode = historySeason.EpisodesList.Find(e => e.EpisodeId == crunchyEpisode.Id); @@ -190,7 +190,7 @@ public class History(){ EpisodeDescription = crunchyEpisode.Description, EpisodeId = crunchyEpisode.Id, Episode = crunchyEpisode.Episode, - EpisodeSeasonNum = crunchyEpisode.SeasonNumber + "", + EpisodeSeasonNum = Helpers.ExtractNumberAfterS(crunchyEpisode.Identifier) ?? crunchyEpisode.SeasonNumber + "", SpecialEpisode = !int.TryParse(crunchyEpisode.Episode, out _), }; @@ -202,7 +202,7 @@ public class History(){ historyEpisode.EpisodeDescription = crunchyEpisode.Description; historyEpisode.EpisodeId = crunchyEpisode.Id; historyEpisode.Episode = crunchyEpisode.Episode; - historyEpisode.EpisodeSeasonNum = crunchyEpisode.SeasonNumber + ""; + historyEpisode.EpisodeSeasonNum = Helpers.ExtractNumberAfterS(crunchyEpisode.Identifier) ?? crunchyEpisode.SeasonNumber + ""; } } @@ -277,7 +277,7 @@ public class History(){ var newSeason = new HistorySeason{ SeasonTitle = firstEpisode.SeasonTitle, SeasonId = firstEpisode.SeasonId, - SeasonNum = firstEpisode.SeasonNumber + "", + SeasonNum = Helpers.ExtractNumberAfterS(firstEpisode.Identifier) ?? firstEpisode.SeasonNumber + "", EpisodesList =[], SpecialSeason = CheckStringForSpecial(firstEpisode.Identifier) }; @@ -288,7 +288,7 @@ public class History(){ EpisodeDescription = crunchyEpisode.Description, EpisodeId = crunchyEpisode.Id, Episode = crunchyEpisode.Episode, - EpisodeSeasonNum = firstEpisode.SeasonNumber + "", + EpisodeSeasonNum = Helpers.ExtractNumberAfterS(firstEpisode.Identifier) ?? firstEpisode.SeasonNumber + "", SpecialEpisode = !int.TryParse(crunchyEpisode.Episode, out _), }; @@ -302,7 +302,7 @@ public class History(){ var newSeason = new HistorySeason{ SeasonTitle = episode.SeasonTitle, SeasonId = episode.SeasonId, - SeasonNum = episode.SeasonNumber + "", + SeasonNum = Helpers.ExtractNumberAfterS(episode.Identifier) ?? episode.SeasonNumber + "", EpisodesList =[], }; @@ -311,7 +311,7 @@ public class History(){ EpisodeDescription = episode.Description, EpisodeId = episode.Id, Episode = episode.Episode, - EpisodeSeasonNum = episode.SeasonNumber + "", + EpisodeSeasonNum = Helpers.ExtractNumberAfterS(episode.Identifier) ?? episode.SeasonNumber + "", SpecialEpisode = !int.TryParse(episode.Episode, out _), }; diff --git a/CRD/Utils/Files/FileNameManager.cs b/CRD/Utils/Files/FileNameManager.cs index b041b77..5649938 100644 --- a/CRD/Utils/Files/FileNameManager.cs +++ b/CRD/Utils/Files/FileNameManager.cs @@ -30,6 +30,10 @@ public class FileNameManager{ if (variable.Type == "int32"){ int len = replacement.Length; replacement = len < numbers ? new string('0', numbers - len) + replacement : replacement; + } else if (variable.Type == "double"){ + string[] parts = replacement.Split(','); + string formattedIntegerPart = parts[0].PadLeft(numbers, '0'); + replacement = formattedIntegerPart + "," + parts[1]; } else if (variable.Sanitize){ replacement = CleanupFilename(replacement); } diff --git a/CRD/Utils/Helpers.cs b/CRD/Utils/Helpers.cs index f71ac05..b8f8a52 100644 --- a/CRD/Utils/Helpers.cs +++ b/CRD/Utils/Helpers.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Runtime.Serialization; +using System.Text.RegularExpressions; using System.Threading.Tasks; using Newtonsoft.Json; @@ -117,4 +118,23 @@ public class Helpers{ return dotProduct / (normA * normB); } + + public static string? ExtractNumberAfterS(string input){ + // Define the regular expression pattern to match |S followed by a number and optionally C followed by another number + string pattern = @"\|S(\d+)(?:C(\d+))?"; + Match match = Regex.Match(input, pattern); + + if (match.Success){ + string sNumber = match.Groups[1].Value; + string cNumber = match.Groups[2].Value; + + if (!string.IsNullOrEmpty(cNumber)){ + return $"{sNumber}.{cNumber}"; + } else{ + return sNumber; + } + } else{ + return null; + } + } } \ No newline at end of file diff --git a/CRD/Utils/Structs/EpisodeStructs.cs b/CRD/Utils/Structs/EpisodeStructs.cs index 61819c0..49c170d 100644 --- a/CRD/Utils/Structs/EpisodeStructs.cs +++ b/CRD/Utils/Structs/EpisodeStructs.cs @@ -181,7 +181,7 @@ public class CrunchyEpMeta{ public string? EpisodeNumber{ get; set; } public string? EpisodeTitle{ get; set; } public string? SeasonId{ get; set; } - public int? Season{ get; set; } + public string? Season{ get; set; } public string? ShowId{ get; set; } public string? AbsolutEpisodeNumberE{ get; set; } public string? Image{ get; set; }