Chg - Use identifier for some season numbers

This commit is contained in:
Elwador 2024-05-26 02:27:31 +02:00
parent 70ff8aca7b
commit 23b925b314
7 changed files with 44 additions and 18 deletions

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Globalization;
using System.Linq; using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
@ -134,7 +135,7 @@ public class CrEpisode(){
?? Regex.Replace(item.Items[0].SeasonTitle, @"\(\w+ Dub\)", "").TrimEnd(); ?? Regex.Replace(item.Items[0].SeasonTitle, @"\(\w+ Dub\)", "").TrimEnd();
var title = item.Items[0].Title; 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) => var languages = item.Items.Select((a, index) =>
$"{(a.IsPremiumOnly ? "+ " : "")}{item.Langs.ElementAtOrDefault(index).Name ?? "Unknown"}").ToArray(); //☆ $"{(a.IsPremiumOnly ? "+ " : "")}{item.Langs.ElementAtOrDefault(index).Name ?? "Unknown"}").ToArray(); //☆
@ -158,7 +159,7 @@ public class CrEpisode(){
E = key.StartsWith("E") ? key.Substring(1) : key, E = key.StartsWith("E") ? key.Substring(1) : key,
Lang = value.Langs.Select(a => a.Code).ToList(), Lang = value.Langs.Select(a => a.Code).ToList(),
Name = value.Items[0].Title, 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(), SeriesTitle = Regex.Replace(value.Items[0].SeriesTitle, @"\(\w+ Dub\)", "").TrimEnd(),
SeasonTitle = Regex.Replace(value.Items[0].SeasonTitle, @"\(\w+ Dub\)", "").TrimEnd(), SeasonTitle = Regex.Replace(value.Items[0].SeasonTitle, @"\(\w+ Dub\)", "").TrimEnd(),
EpisodeNum = value.Items[0].EpisodeNumber?.ToString() ?? value.Items[0].Episode ?? "?", EpisodeNum = value.Items[0].EpisodeNumber?.ToString() ?? value.Items[0].Episode ?? "?",
@ -210,7 +211,7 @@ public class CrEpisode(){
epMeta.EpisodeNumber = item.Episode; epMeta.EpisodeNumber = item.Episode;
epMeta.EpisodeTitle = item.Title; epMeta.EpisodeTitle = item.Title;
epMeta.SeasonId = item.SeasonId; epMeta.SeasonId = item.SeasonId;
epMeta.Season = item.SeasonNumber; epMeta.Season = Helpers.ExtractNumberAfterS(item.Identifier) ?? item.SeasonNumber + "";
epMeta.ShowId = item.SeriesId; epMeta.ShowId = item.SeriesId;
epMeta.AbsolutEpisodeNumberE = epNum; epMeta.AbsolutEpisodeNumberE = epNum;
epMeta.Image = images[images.Count / 2].FirstOrDefault().Source; epMeta.Image = images[images.Count / 2].FirstOrDefault().Source;

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Globalization;
using System.Linq; using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Net.Http.Headers; using System.Net.Http.Headers;
@ -75,7 +76,7 @@ public class CrSeries(){
epMeta.EpisodeNumber = item.Episode; epMeta.EpisodeNumber = item.Episode;
epMeta.EpisodeTitle = item.Title; epMeta.EpisodeTitle = item.Title;
epMeta.SeasonId = item.SeasonId; epMeta.SeasonId = item.SeasonId;
epMeta.Season = item.SeasonNumber; epMeta.Season = Helpers.ExtractNumberAfterS(item.Identifier) ?? item.SeasonNumber + "";
epMeta.ShowId = item.SeriesId; epMeta.ShowId = item.SeriesId;
epMeta.AbsolutEpisodeNumberE = epNum; epMeta.AbsolutEpisodeNumberE = epNum;
epMeta.Image = images[images.Count / 2].FirstOrDefault().Source; epMeta.Image = images[images.Count / 2].FirstOrDefault().Source;
@ -238,7 +239,7 @@ public class CrSeries(){
?? Regex.Replace(item.Items[0].SeasonTitle, @"\(\w+ Dub\)", "").TrimEnd(); ?? Regex.Replace(item.Items[0].SeasonTitle, @"\(\w+ Dub\)", "").TrimEnd();
var title = item.Items[0].Title; 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) => var languages = item.Items.Select((a, index) =>
$"{(a.IsPremiumOnly ? "+ " : "")}{item.Langs.ElementAtOrDefault(index).Name ?? "Unknown"}").ToArray(); //☆ $"{(a.IsPremiumOnly ? "+ " : "")}{item.Langs.ElementAtOrDefault(index).Name ?? "Unknown"}").ToArray(); //☆
@ -262,7 +263,7 @@ public class CrSeries(){
E = key.StartsWith("E") ? key.Substring(1) : key, E = key.StartsWith("E") ? key.Substring(1) : key,
Lang = value.Langs.Select(a => a.Code).ToList(), Lang = value.Langs.Select(a => a.Code).ToList(),
Name = value.Items[0].Title, 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(), SeriesTitle = Regex.Replace(value.Items[0].SeriesTitle, @"\(\w+ Dub\)", "").TrimEnd(),
SeasonTitle = Regex.Replace(value.Items[0].SeasonTitle, @"\(\w+ Dub\)", "").TrimEnd(), SeasonTitle = Regex.Replace(value.Items[0].SeasonTitle, @"\(\w+ Dub\)", "").TrimEnd(),
EpisodeNum = value.Items[0].EpisodeNumber?.ToString() ?? value.Items[0].Episode ?? "?", EpisodeNum = value.Items[0].EpisodeNumber?.ToString() ?? value.Items[0].Episode ?? "?",

View File

@ -639,7 +639,7 @@ 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("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("seriesTitle", data.SeriesTitle ?? string.Empty, true));
variables.Add(new Variable("showTitle", data.SeasonTitle ?? 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){ if (pbStreams?.Keys != null){
foreach (var key in pbStreams.Keys){ foreach (var key in pbStreams.Keys){

View File

@ -112,14 +112,14 @@ public class History(){
if (historySeason != null){ if (historySeason != null){
historySeason.SeasonTitle = episode.SeasonTitle; 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)){ if (historySeason.EpisodesList.All(e => e.EpisodeId != episode.Id)){
var newHistoryEpisode = new HistoryEpisode{ var newHistoryEpisode = new HistoryEpisode{
EpisodeTitle = episode.Identifier.Contains("|M|") ? episode.SeasonTitle : episode.Title, EpisodeTitle = episode.Identifier.Contains("|M|") ? episode.SeasonTitle : episode.Title,
EpisodeDescription = episode.Description, EpisodeDescription = episode.Description,
EpisodeId = episode.Id, EpisodeId = episode.Id,
Episode = episode.Episode, Episode = episode.Episode,
EpisodeSeasonNum = episode.SeasonNumber + "", EpisodeSeasonNum = Helpers.ExtractNumberAfterS(episode.Identifier) ?? episode.SeasonNumber + "",
SpecialEpisode = !int.TryParse(episode.Episode, out _), SpecialEpisode = !int.TryParse(episode.Episode, out _),
}; };
@ -180,7 +180,7 @@ public class History(){
if (historySeason != null){ if (historySeason != null){
historySeason.SeasonTitle = firstEpisode.SeasonTitle; historySeason.SeasonTitle = firstEpisode.SeasonTitle;
historySeason.SeasonNum = firstEpisode.SeasonNumber + ""; historySeason.SeasonNum = Helpers.ExtractNumberAfterS(firstEpisode.Identifier) ?? firstEpisode.SeasonNumber + "";
foreach (var crunchyEpisode in seasonData.Data){ foreach (var crunchyEpisode in seasonData.Data){
var historyEpisode = historySeason.EpisodesList.Find(e => e.EpisodeId == crunchyEpisode.Id); var historyEpisode = historySeason.EpisodesList.Find(e => e.EpisodeId == crunchyEpisode.Id);
@ -190,7 +190,7 @@ public class History(){
EpisodeDescription = crunchyEpisode.Description, EpisodeDescription = crunchyEpisode.Description,
EpisodeId = crunchyEpisode.Id, EpisodeId = crunchyEpisode.Id,
Episode = crunchyEpisode.Episode, Episode = crunchyEpisode.Episode,
EpisodeSeasonNum = crunchyEpisode.SeasonNumber + "", EpisodeSeasonNum = Helpers.ExtractNumberAfterS(crunchyEpisode.Identifier) ?? crunchyEpisode.SeasonNumber + "",
SpecialEpisode = !int.TryParse(crunchyEpisode.Episode, out _), SpecialEpisode = !int.TryParse(crunchyEpisode.Episode, out _),
}; };
@ -202,7 +202,7 @@ public class History(){
historyEpisode.EpisodeDescription = crunchyEpisode.Description; historyEpisode.EpisodeDescription = crunchyEpisode.Description;
historyEpisode.EpisodeId = crunchyEpisode.Id; historyEpisode.EpisodeId = crunchyEpisode.Id;
historyEpisode.Episode = crunchyEpisode.Episode; 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{ var newSeason = new HistorySeason{
SeasonTitle = firstEpisode.SeasonTitle, SeasonTitle = firstEpisode.SeasonTitle,
SeasonId = firstEpisode.SeasonId, SeasonId = firstEpisode.SeasonId,
SeasonNum = firstEpisode.SeasonNumber + "", SeasonNum = Helpers.ExtractNumberAfterS(firstEpisode.Identifier) ?? firstEpisode.SeasonNumber + "",
EpisodesList =[], EpisodesList =[],
SpecialSeason = CheckStringForSpecial(firstEpisode.Identifier) SpecialSeason = CheckStringForSpecial(firstEpisode.Identifier)
}; };
@ -288,7 +288,7 @@ public class History(){
EpisodeDescription = crunchyEpisode.Description, EpisodeDescription = crunchyEpisode.Description,
EpisodeId = crunchyEpisode.Id, EpisodeId = crunchyEpisode.Id,
Episode = crunchyEpisode.Episode, Episode = crunchyEpisode.Episode,
EpisodeSeasonNum = firstEpisode.SeasonNumber + "", EpisodeSeasonNum = Helpers.ExtractNumberAfterS(firstEpisode.Identifier) ?? firstEpisode.SeasonNumber + "",
SpecialEpisode = !int.TryParse(crunchyEpisode.Episode, out _), SpecialEpisode = !int.TryParse(crunchyEpisode.Episode, out _),
}; };
@ -302,7 +302,7 @@ public class History(){
var newSeason = new HistorySeason{ var newSeason = new HistorySeason{
SeasonTitle = episode.SeasonTitle, SeasonTitle = episode.SeasonTitle,
SeasonId = episode.SeasonId, SeasonId = episode.SeasonId,
SeasonNum = episode.SeasonNumber + "", SeasonNum = Helpers.ExtractNumberAfterS(episode.Identifier) ?? episode.SeasonNumber + "",
EpisodesList =[], EpisodesList =[],
}; };
@ -311,7 +311,7 @@ public class History(){
EpisodeDescription = episode.Description, EpisodeDescription = episode.Description,
EpisodeId = episode.Id, EpisodeId = episode.Id,
Episode = episode.Episode, Episode = episode.Episode,
EpisodeSeasonNum = episode.SeasonNumber + "", EpisodeSeasonNum = Helpers.ExtractNumberAfterS(episode.Identifier) ?? episode.SeasonNumber + "",
SpecialEpisode = !int.TryParse(episode.Episode, out _), SpecialEpisode = !int.TryParse(episode.Episode, out _),
}; };

View File

@ -30,6 +30,10 @@ public class FileNameManager{
if (variable.Type == "int32"){ if (variable.Type == "int32"){
int len = replacement.Length; int len = replacement.Length;
replacement = len < numbers ? new string('0', numbers - len) + replacement : replacement; 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){ } else if (variable.Sanitize){
replacement = CleanupFilename(replacement); replacement = CleanupFilename(replacement);
} }

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using Newtonsoft.Json; using Newtonsoft.Json;
@ -117,4 +118,23 @@ public class Helpers{
return dotProduct / (normA * normB); 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;
}
}
} }

View File

@ -181,7 +181,7 @@ public class CrunchyEpMeta{
public string? EpisodeNumber{ get; set; } public string? EpisodeNumber{ get; set; }
public string? EpisodeTitle{ get; set; } public string? EpisodeTitle{ get; set; }
public string? SeasonId{ get; set; } public string? SeasonId{ get; set; }
public int? Season{ get; set; } public string? Season{ get; set; }
public string? ShowId{ get; set; } public string? ShowId{ get; set; }
public string? AbsolutEpisodeNumberE{ get; set; } public string? AbsolutEpisodeNumberE{ get; set; }
public string? Image{ get; set; } public string? Image{ get; set; }