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>
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
<ProjectGuid>{AAFB0AE9-6F89-4DDF-821B-1AE016FC4CFB}</ProjectGuid>
|
<ProjectGuid>{AAFB0AE9-6F89-4DDF-821B-1AE016FC4CFB}</ProjectGuid>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<RootNamespace>rename_anime_episodes_csharp</RootNamespace>
|
<RootNamespace>EpisodeRenamer</RootNamespace>
|
||||||
<AssemblyName>rename_anime_episodes_csharp</AssemblyName>
|
<AssemblyName>EpisodeRenamer</AssemblyName>
|
||||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||||
<Deterministic>true</Deterministic>
|
<Deterministic>true</Deterministic>
|
||||||
|
<NuGetPackageImportStamp>
|
||||||
|
</NuGetPackageImportStamp>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
@@ -33,6 +35,9 @@
|
|||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<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" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
@@ -48,6 +53,17 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="App.config" />
|
<None Include="App.config" />
|
||||||
|
<None Include="config.json">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Include="packages.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<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>
|
</Project>
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.13.35931.197 d17.13
|
VisualStudioVersion = 17.13.35931.197
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
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
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
79
Program.cs
79
Program.cs
@@ -1,24 +1,28 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
class EpisodeRenamer
|
class EpisodeRenamer
|
||||||
{
|
{
|
||||||
// Паттерны для поиска номера эпизода (регулярные выражения + правила обработки)
|
private class PatternConfig
|
||||||
private static readonly List<Pattern> patterns = new List<Pattern>
|
|
||||||
{
|
{
|
||||||
new Pattern(new Regex(@"\[\d+\]"), 1, -1),
|
public string Regex { get; set; }
|
||||||
new Pattern(new Regex(@"[s]\d+[e]\d+", RegexOptions.IgnoreCase), 4, null),
|
public int? Start { get; set; }
|
||||||
new Pattern(new Regex(@"[s]\d+[.][e]\d+", RegexOptions.IgnoreCase), 5, null),
|
public int? End { get; set; }
|
||||||
new Pattern(new Regex(@"\d+$"), 0, null)
|
public bool IgnoreCase { get; set; }
|
||||||
};
|
}
|
||||||
|
|
||||||
// Поддерживаемые расширения файлов
|
private class Config
|
||||||
private static readonly HashSet<string> extensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
|
|
||||||
{
|
{
|
||||||
".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
|
private class Pattern
|
||||||
{
|
{
|
||||||
@@ -36,6 +40,20 @@ class EpisodeRenamer
|
|||||||
|
|
||||||
static void Main()
|
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.CancelKeyPress += (sender, e) =>
|
||||||
{
|
{
|
||||||
Console.WriteLine("\nВыход из программы.");
|
Console.WriteLine("\nВыход из программы.");
|
||||||
@@ -50,7 +68,7 @@ class EpisodeRenamer
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Console.Write("\nВведите путь до папки с эпизодами: ");
|
Console.Write("\nВведите путь до папки с эпизодами: ");
|
||||||
string input = Console.ReadLine()?.Trim() ?? string.Empty;
|
string input = Console.ReadLine().Trim() ?? string.Empty;
|
||||||
|
|
||||||
string folder = string.IsNullOrEmpty(input)
|
string folder = string.IsNullOrEmpty(input)
|
||||||
? Directory.GetCurrentDirectory()
|
? 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)
|
private static void ProcessFolder(string folder)
|
||||||
{
|
{
|
||||||
foreach (string filePath in Directory.GetFiles(folder))
|
foreach (string filePath in Directory.GetFiles(folder))
|
||||||
@@ -93,7 +139,8 @@ class EpisodeRenamer
|
|||||||
foreach (var pattern in patterns)
|
foreach (var pattern in patterns)
|
||||||
{
|
{
|
||||||
Match match = pattern.Regex.Match(nameWithoutExt);
|
Match match = pattern.Regex.Match(nameWithoutExt);
|
||||||
if (!match.Success) continue;
|
if (!match.Success)
|
||||||
|
continue;
|
||||||
|
|
||||||
string found = match.Value;
|
string found = match.Value;
|
||||||
int startIndex = AdjustIndex(pattern.Start, found.Length);
|
int startIndex = AdjustIndex(pattern.Start, found.Length);
|
||||||
@@ -126,8 +173,10 @@ class EpisodeRenamer
|
|||||||
|
|
||||||
private static int AdjustIndex(int? index, int length)
|
private static int AdjustIndex(int? index, int length)
|
||||||
{
|
{
|
||||||
if (!index.HasValue) return length;
|
if (!index.HasValue)
|
||||||
if (index.Value < 0) return length + index.Value;
|
return length;
|
||||||
|
if (index.Value < 0)
|
||||||
|
return length + index.Value;
|
||||||
return index.Value;
|
return index.Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,11 +5,11 @@ using System.Runtime.InteropServices;
|
|||||||
// Общие сведения об этой сборке предоставляются следующим набором
|
// Общие сведения об этой сборке предоставляются следующим набором
|
||||||
// набора атрибутов. Измените значения этих атрибутов для изменения сведений,
|
// набора атрибутов. Измените значения этих атрибутов для изменения сведений,
|
||||||
// связанные с этой сборкой.
|
// связанные с этой сборкой.
|
||||||
[assembly: AssemblyTitle("rename_anime_episodes_csharp")]
|
[assembly: AssemblyTitle("EpisodeRenamer")]
|
||||||
[assembly: AssemblyDescription("")]
|
[assembly: AssemblyDescription("")]
|
||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCompany("")]
|
[assembly: AssemblyCompany("")]
|
||||||
[assembly: AssemblyProduct("rename_anime_episodes_csharp")]
|
[assembly: AssemblyProduct("EpisodeRenamer")]
|
||||||
[assembly: AssemblyCopyright("Copyright © 2025")]
|
[assembly: AssemblyCopyright("Copyright © 2025")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark("")]
|
||||||
[assembly: AssemblyCulture("")]
|
[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