Compare commits
No commits in common. "4f021d5a3eb998b03c1380096a45af17b5b2dff8" and "20f3709ac9dea156ade5f0d26326ad6ae68761e6" have entirely different histories.
4f021d5a3e
...
20f3709ac9
@ -18,7 +18,6 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NativeFileDialogSharp" Version="0.5.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
|
||||
<PackageReference Include="TMDbLib" Version="2.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@ -1,11 +0,0 @@
|
||||
namespace BangumiRenamer.Config;
|
||||
|
||||
public class ConfigItemAttribute : System.Attribute
|
||||
{
|
||||
public string Name;
|
||||
|
||||
public ConfigItemAttribute(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
namespace BangumiRenamer.Config;
|
||||
|
||||
[ConfigItem("Proxy")]
|
||||
public class ProxyConfig : IConfigItem
|
||||
{
|
||||
public string HttpProxy = "";
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
namespace BangumiRenamer.Config;
|
||||
|
||||
[ConfigItem("TMDB")]
|
||||
public class TMDBConfig : IConfigItem
|
||||
{
|
||||
public string ApiKey = "";
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
namespace BangumiRenamer.Config;
|
||||
|
||||
public interface IConfigItem;
|
||||
15
Src/ConfigManager/Attribute/ConfigItemAttribute.cs
Normal file
15
Src/ConfigManager/Attribute/ConfigItemAttribute.cs
Normal file
@ -0,0 +1,15 @@
|
||||
namespace BangumiRenamer.ConfigManager;
|
||||
|
||||
public class ConfigItemAttribute : Attribute
|
||||
{
|
||||
public string Name;
|
||||
|
||||
public ConfigItemAttribute()
|
||||
{
|
||||
}
|
||||
|
||||
public ConfigItemAttribute(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
}
|
||||
@ -1,24 +1,16 @@
|
||||
namespace BangumiRenamer.Config;
|
||||
using System.Reflection;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
public class Config(string configPath)
|
||||
namespace BangumiRenamer.ConfigManager;
|
||||
|
||||
public class ConfigManager(string configPath)
|
||||
{
|
||||
private static readonly Lazy<Config> _lazy = new (() =>
|
||||
{
|
||||
var config = new Config("config.json");
|
||||
config.ReLoad();
|
||||
return config;
|
||||
});
|
||||
public static Config Default => _lazy.Value;
|
||||
|
||||
|
||||
private static readonly Dictionary<Type, string> Cache = new();
|
||||
private readonly Dictionary<string, object> _configObjects = new();
|
||||
private readonly Dictionary<string, JObject> _configs = new();
|
||||
|
||||
private static string GetConfigItemName(Type type)
|
||||
private static string GetConfigName(Type type)
|
||||
{
|
||||
if (Cache.TryGetValue(type, out var name)) return name;
|
||||
name = type.Name;
|
||||
@ -30,9 +22,9 @@ public class Config(string configPath)
|
||||
return name;
|
||||
}
|
||||
|
||||
public T Get<T>() where T : class, IConfigItem, new()
|
||||
public T Get<T>() where T : class, new()
|
||||
{
|
||||
var name = GetConfigItemName(typeof(T));
|
||||
var name = GetConfigName(typeof(T));
|
||||
if (_configObjects.TryGetValue(name, out var value))
|
||||
{
|
||||
return (T) value;
|
||||
@ -50,9 +42,9 @@ public class Config(string configPath)
|
||||
return result;
|
||||
}
|
||||
|
||||
public void Reset<T>() where T : class, IConfigItem, new()
|
||||
public void Reset<T>()
|
||||
{
|
||||
var name = GetConfigItemName(typeof(T));
|
||||
var name = GetConfigName(typeof(T));
|
||||
_configs.Remove(name);
|
||||
_configObjects.Remove(name);
|
||||
}
|
||||
@ -63,7 +55,7 @@ public class Config(string configPath)
|
||||
_configObjects.Clear();
|
||||
}
|
||||
|
||||
public void ReLoad()
|
||||
public void Load()
|
||||
{
|
||||
_configs.Clear();
|
||||
_configObjects.Clear();
|
||||
@ -84,32 +76,4 @@ public class Config(string configPath)
|
||||
}
|
||||
File.WriteAllText(configPath, JsonConvert.SerializeObject(_configs, Formatting.Indented));
|
||||
}
|
||||
|
||||
public static void CreateEmptyConfig()
|
||||
{
|
||||
var configItemTypes = AppDomain.CurrentDomain.GetAssemblies()
|
||||
.SelectMany(assembly =>
|
||||
{
|
||||
try
|
||||
{
|
||||
return assembly.GetTypes();
|
||||
}
|
||||
catch (ReflectionTypeLoadException)
|
||||
{
|
||||
return Array.Empty<Type>();
|
||||
}
|
||||
})
|
||||
.Where(type => type.IsClass &&
|
||||
!type.IsAbstract &&
|
||||
typeof(IConfigItem).IsAssignableFrom(type))
|
||||
.ToList();
|
||||
|
||||
var configs = new Dictionary<string, JObject>();
|
||||
foreach (var type in configItemTypes)
|
||||
{
|
||||
var name = GetConfigItemName(type);
|
||||
configs[name] = JObject.FromObject(Activator.CreateInstance(type));
|
||||
}
|
||||
File.WriteAllText("config_default.json", JsonConvert.SerializeObject(configs, Formatting.Indented));
|
||||
}
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
namespace BangumiRenamer.Data;
|
||||
|
||||
public class Show
|
||||
{
|
||||
public string title;
|
||||
public List<Session> sessions;
|
||||
}
|
||||
|
||||
public class Session
|
||||
{
|
||||
public int id;
|
||||
public List<int> episodes;
|
||||
}
|
||||
@ -1,5 +1,16 @@
|
||||
class Program
|
||||
using BangumiRenamer.Utils;
|
||||
|
||||
class Program
|
||||
{
|
||||
public static void PrintResNames()
|
||||
{
|
||||
var names = ResourceLoader.GetAllResNames();
|
||||
foreach (var name in names)
|
||||
{
|
||||
Console.WriteLine(name);
|
||||
}
|
||||
}
|
||||
|
||||
static void Main()
|
||||
{
|
||||
|
||||
|
||||
@ -1,15 +0,0 @@
|
||||
using BangumiRenamer.Utils;
|
||||
|
||||
namespace BangumiRenamer.Tools;
|
||||
|
||||
public class EmbededResourceViewer
|
||||
{
|
||||
public static void PrintResourceNames()
|
||||
{
|
||||
var names = ResourceLoader.GetAllResNames();
|
||||
foreach (var name in names)
|
||||
{
|
||||
Console.WriteLine(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -13,7 +13,7 @@ public static class FolderCloner
|
||||
|
||||
result = Dialog.FolderPicker();
|
||||
if (!result.IsOk) return;
|
||||
var dest = Path.Combine(result.Path, Path.GetFileNameWithoutExtension(source.Replace("\\\\", "")));
|
||||
var dest = Path.Combine(result.Path, Path.GetFileNameWithoutExtension(source));
|
||||
|
||||
var finalDest = dest;
|
||||
int suffix = 1;
|
||||
|
||||
@ -1,95 +0,0 @@
|
||||
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<Show> FindShows(string checkPath)
|
||||
{
|
||||
var shows = new List<Show>();
|
||||
var showPaths = Directory.GetDirectories(checkPath);
|
||||
foreach (var showPath in showPaths)
|
||||
{
|
||||
var sessions = new List<Session>();
|
||||
var sessionPaths = Directory.GetDirectories(showPath);
|
||||
foreach (var sessionPath in sessionPaths)
|
||||
{
|
||||
var episodePaths = Directory.GetFiles(sessionPath);
|
||||
HashSet<int> episodes = new HashSet<int>();
|
||||
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<TMDBConfig>().ApiKey ,
|
||||
proxy: new WebProxy(Config.Default.Get<ProxyConfig>().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);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user