Update
Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com>
This commit is contained in:
@@ -6,12 +6,14 @@
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{AAFB0AE9-6F89-4DDF-821B-1AE016FC4CFB}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>rename_anime_episodes_csharp</RootNamespace>
|
||||
<AssemblyName>rename_anime_episodes_csharp</AssemblyName>
|
||||
<RootNamespace>EpisodeRenamer</RootNamespace>
|
||||
<AssemblyName>EpisodeRenamer</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>true</Deterministic>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
@@ -33,6 +35,9 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
@@ -48,6 +53,17 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="config.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="packages\ILRepack.Lib.MSBuild.Task.2.0.43\build\ILRepack.Lib.MSBuild.Task.targets" Condition="Exists('packages\ILRepack.Lib.MSBuild.Task.2.0.43\build\ILRepack.Lib.MSBuild.Task.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>Данный проект ссылается на пакеты NuGet, отсутствующие на этом компьютере. Используйте восстановление пакетов NuGet, чтобы скачать их. Дополнительную информацию см. по адресу: http://go.microsoft.com/fwlink/?LinkID=322105. Отсутствует следующий файл: {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('packages\ILRepack.Lib.MSBuild.Task.2.0.43\build\ILRepack.Lib.MSBuild.Task.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\ILRepack.Lib.MSBuild.Task.2.0.43\build\ILRepack.Lib.MSBuild.Task.targets'))" />
|
||||
</Target>
|
||||
</Project>
|
||||
@@ -1,9 +1,9 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.13.35931.197 d17.13
|
||||
VisualStudioVersion = 17.13.35931.197
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "rename_anime_episodes_csharp", "rename_anime_episodes_csharp.csproj", "{AAFB0AE9-6F89-4DDF-821B-1AE016FC4CFB}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EpisodeRenamer", "EpisodeRenamer.csproj", "{AAFB0AE9-6F89-4DDF-821B-1AE016FC4CFB}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
79
Program.cs
79
Program.cs
@@ -1,24 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
class EpisodeRenamer
|
||||
{
|
||||
// Паттерны для поиска номера эпизода (регулярные выражения + правила обработки)
|
||||
private static readonly List<Pattern> patterns = new List<Pattern>
|
||||
private class PatternConfig
|
||||
{
|
||||
new Pattern(new Regex(@"\[\d+\]"), 1, -1),
|
||||
new Pattern(new Regex(@"[s]\d+[e]\d+", RegexOptions.IgnoreCase), 4, null),
|
||||
new Pattern(new Regex(@"[s]\d+[.][e]\d+", RegexOptions.IgnoreCase), 5, null),
|
||||
new Pattern(new Regex(@"\d+$"), 0, null)
|
||||
};
|
||||
public string Regex { get; set; }
|
||||
public int? Start { get; set; }
|
||||
public int? End { get; set; }
|
||||
public bool IgnoreCase { get; set; }
|
||||
}
|
||||
|
||||
// Поддерживаемые расширения файлов
|
||||
private static readonly HashSet<string> extensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
|
||||
private class Config
|
||||
{
|
||||
".mkv", ".avi", ".mp4"
|
||||
};
|
||||
public List<PatternConfig> Patterns { get; set; }
|
||||
public List<string> Extensions { get; set; }
|
||||
}
|
||||
|
||||
private static List<Pattern> patterns;
|
||||
private static HashSet<string> extensions;
|
||||
|
||||
private class Pattern
|
||||
{
|
||||
@@ -36,6 +40,20 @@ class EpisodeRenamer
|
||||
|
||||
static void Main()
|
||||
{
|
||||
Console.Title = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyTitleAttribute>().Title;
|
||||
|
||||
try
|
||||
{
|
||||
LoadConfiguration();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Ошибка загрузки конфигурации: {ex.Message}");
|
||||
Console.WriteLine("Программа будет завершена.");
|
||||
Console.ReadLine();
|
||||
return;
|
||||
}
|
||||
|
||||
Console.CancelKeyPress += (sender, e) =>
|
||||
{
|
||||
Console.WriteLine("\nВыход из программы.");
|
||||
@@ -50,7 +68,7 @@ class EpisodeRenamer
|
||||
try
|
||||
{
|
||||
Console.Write("\nВведите путь до папки с эпизодами: ");
|
||||
string input = Console.ReadLine()?.Trim() ?? string.Empty;
|
||||
string input = Console.ReadLine().Trim() ?? string.Empty;
|
||||
|
||||
string folder = string.IsNullOrEmpty(input)
|
||||
? Directory.GetCurrentDirectory()
|
||||
@@ -72,6 +90,34 @@ class EpisodeRenamer
|
||||
}
|
||||
}
|
||||
|
||||
private static void LoadConfiguration()
|
||||
{
|
||||
string configPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.json");
|
||||
|
||||
if (!File.Exists(configPath))
|
||||
{
|
||||
throw new FileNotFoundException("Конфигурационный файл config.json не найден");
|
||||
}
|
||||
|
||||
string json = File.ReadAllText(configPath);
|
||||
Config config = JsonConvert.DeserializeObject<Config>(json);
|
||||
|
||||
// Загружаем расширения файлов
|
||||
extensions = new HashSet<string>(config.Extensions, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
// Загружаем паттерны
|
||||
patterns = new List<Pattern>();
|
||||
foreach (PatternConfig patternConfig in config.Patterns)
|
||||
{
|
||||
RegexOptions options = patternConfig.IgnoreCase ? RegexOptions.IgnoreCase : RegexOptions.None;
|
||||
Regex regex = new Regex(patternConfig.Regex, options);
|
||||
patterns.Add(new Pattern(regex, patternConfig.Start, patternConfig.End));
|
||||
}
|
||||
|
||||
Console.WriteLine("Конфигурация успешно загружена.");
|
||||
Console.WriteLine($"Загружено {patterns.Count} паттернов и {extensions.Count} расширений.");
|
||||
}
|
||||
|
||||
private static void ProcessFolder(string folder)
|
||||
{
|
||||
foreach (string filePath in Directory.GetFiles(folder))
|
||||
@@ -93,7 +139,8 @@ class EpisodeRenamer
|
||||
foreach (var pattern in patterns)
|
||||
{
|
||||
Match match = pattern.Regex.Match(nameWithoutExt);
|
||||
if (!match.Success) continue;
|
||||
if (!match.Success)
|
||||
continue;
|
||||
|
||||
string found = match.Value;
|
||||
int startIndex = AdjustIndex(pattern.Start, found.Length);
|
||||
@@ -126,8 +173,10 @@ class EpisodeRenamer
|
||||
|
||||
private static int AdjustIndex(int? index, int length)
|
||||
{
|
||||
if (!index.HasValue) return length;
|
||||
if (index.Value < 0) return length + index.Value;
|
||||
if (!index.HasValue)
|
||||
return length;
|
||||
if (index.Value < 0)
|
||||
return length + index.Value;
|
||||
return index.Value;
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,12 @@ using System.Runtime.InteropServices;
|
||||
// Общие сведения об этой сборке предоставляются следующим набором
|
||||
// набора атрибутов. Измените значения этих атрибутов для изменения сведений,
|
||||
// связанные с этой сборкой.
|
||||
[assembly: AssemblyTitle("rename_anime_episodes_csharp")]
|
||||
[assembly: AssemblyTitle("EpisodeRenamer")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("rename_anime_episodes_csharp")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2025")]
|
||||
[assembly: AssemblyProduct("EpisodeRenamer")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2025")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
|
||||
27
config.json
Normal file
27
config.json
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"Patterns": [
|
||||
{
|
||||
"Regex": "\\[\\d+\\]",
|
||||
"Start": 1,
|
||||
"End": -1
|
||||
},
|
||||
{
|
||||
"Regex": "[s]\\d+[e]\\d+",
|
||||
"Start": 4,
|
||||
"End": null,
|
||||
"IgnoreCase": true
|
||||
},
|
||||
{
|
||||
"Regex": "[s]\\d+[.][e]\\d+",
|
||||
"Start": 5,
|
||||
"End": null,
|
||||
"IgnoreCase": true
|
||||
},
|
||||
{
|
||||
"Regex": "\\d+$",
|
||||
"Start": 0,
|
||||
"End": null
|
||||
}
|
||||
],
|
||||
"Extensions": [".mkv", ".avi", ".mp4"]
|
||||
}
|
||||
5
packages.config
Normal file
5
packages.config
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="ILRepack.Lib.MSBuild.Task" version="2.0.43" targetFramework="net48" developmentDependency="true" />
|
||||
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net48" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user