namespace BangumiRenamer.Tools; using Config; using TMDbLib.Client; using Data; using NativeFileDialogSharp; using System.Net; using System.Text; using System.Text.RegularExpressions; public static class ShowCompletionChecker { static List FindShows(string checkPath) { var shows = new List(); var showPaths = Directory.GetDirectories(checkPath); foreach (var showPath in showPaths) { var sessions = new List(); var sessionPaths = Directory.GetDirectories(showPath); foreach (var sessionPath in sessionPaths) { var episodePaths = Directory.GetFiles(sessionPath); HashSet episodes = new HashSet(); foreach (var episodePath in episodePaths) { var matches = Regex.Matches(episodePath, @".*S\d+E(\d+).*"); if (matches.Count == 0) continue; var episode = int.Parse(matches[0].Groups[1].Value); episodes.Add(episode); } var session = new Session { id = int.Parse(Path.GetFileName(sessionPath).Replace("Season ", "")), episodes = episodes.ToList() }; sessions.Add(session); } shows.Add(new Show { title = Path.GetFileName(showPath), sessions = sessions }); } return shows; } public static void Run() { var dir = Dialog.FolderPicker(); if (!dir.IsOk) return; var checkPath = dir.Path; var shows = FindShows(checkPath); Console.WriteLine($"Total Shows: {shows.Count}"); var client = new TMDbClient( apiKey: Config.Default.Get().ApiKey , proxy: new WebProxy(Config.Default.Get().HttpProxy)); var output = new StringBuilder(); foreach (var t in shows) { var match = Regex.Match(t.title, @"(.*) \((\d{4})\)"); var title = match.Groups[1].Value; var year = int.Parse(match.Groups[2].Value); var result = client.SearchTvShowAsync(title, firstAirDateYear: year).Result; var info = result.Results.FirstOrDefault(); if (info == null) { Console.WriteLine($"找不到对应的TV:{t.title}"); continue; } foreach (var session in t.sessions) { var sessionInfo = client.GetTvSeasonAsync(info.Id, session.id).Result; if (sessionInfo == null) { Console.WriteLine($"季度对不上,可能找错了:{t.title} -> {info.OriginalName}"); break; } foreach (var episode in sessionInfo.Episodes) { if (DateTime.Now.AddDays(-7) < episode.AirDate) continue; if (!session.episodes.Contains(episode.EpisodeNumber)) { output.AppendLine($"{title} 的第 {session.id} 季少了第 {episode.EpisodeNumber} 集"); } } } } Console.Write(output); } }