Compare commits

...

2 Commits

Author SHA1 Message Date
399691cb05 Enhanced Thread-waiting. Shorted delay for MusicBrainZ API requests 2026-02-05 10:08:45 +03:00
a59905073d Enhanced Genres parsing 2026-02-05 03:04:42 +03:00
3 changed files with 30 additions and 21 deletions

View File

@@ -6,7 +6,7 @@
- `-f <format>` **optional** - формат треков для фильтрованного чтения указанной директории (mp3, flac, wav и т.д)
- `-c <filename>` **optional** - ищет в указанной директории указанное изображение обложки тех или иных альбомов **(БУДЕТ ИЗМЕНЕНО)**
- `--fix-tags` **optional** - исправляет теги (меняет разделитель в теге исполнителей, заполняет пустой тег исполнителей альбома самими исполнителями и пытается найти жанры в MusicBrainz API)
- `--enhance-structure` **optional** - улучшает структуру
- `--enhance-structure` **optional** - улучшает структуру хранения треков(применяется вместе с `--fix-tags`)
## Примерный шаблон Windows .bat файла
```bat
@setlocal enableextensions

View File

@@ -75,7 +75,9 @@ public static class TagEditor {
if (albumResult != null)
{
IReleaseGroup fullAlbum = await query.LookupReleaseGroupAsync(albumResult.Id, Include.Genres);
file.Tag.Genres = fullAlbum.Genres?.Select(g => g.Name).ToArray();
file.Tag.Genres = fullAlbum.Genres?.Select(g =>
string.Join(" ", g.Name.Split(" ").Select(n => n[0].ToString().ToUpper() + n[1..^0]))
).ToArray();
}
}
catch { }
@@ -92,19 +94,19 @@ public static class TagEditor {
{
FileInfo path = new FileInfo(filePath);
Console.WriteLine(file.Tag.Album);
string album = ReplaceSystemSymbols(file.Tag.Album);
string album = file.Tag.Year + " — " + ReplaceSystemSymbols(file.Tag.Album);
if (!Directory.Exists(Path.Combine(path.DirectoryName!, album)))
Directory.CreateDirectory(Path.Combine(path.DirectoryName!, album));
string output = Path.Combine(path.DirectoryName!,
album,
$"{file.Tag.Track}. {string.Join(", ", file.Tag.Performers.Select(p => ReplaceSystemSymbols(p)))} - {file.Tag.Title}.{format}");
$"{file.Tag.Track}. {string.Join(", ", file.Tag.Performers.Select(p => ReplaceSystemSymbols(p)))} - {ReplaceSystemSymbols(file.Tag.Title)}.{format}");
if (System.IO.File.Exists(output))
System.IO.File.Delete(filePath);
else
System.IO.File.Move(filePath, output);
await Task.Delay(1000);
await Task.Delay(500);
}
}
@@ -113,23 +115,23 @@ public static class TagEditor {
string result = origin;
if (result.Contains("/"))
result.Replace("/", "-");
result = result.Replace("/", "-");
if (result.Contains(":"))
result.Replace(":", "-");
result = result.Replace(":", "-");
if (result.Contains("|"))
result.Replace("|", "-");
result = result.Replace("|", "-");
if (result.Contains("\\"))
result.Replace("\\", "-");
result = result.Replace("\\", "-");
if (result.Contains("?"))
result.Replace("?", "");
result = result.Replace("?", "");
if (result.Contains("\""))
result.Replace("\"", "_");
result = result.Replace("\"", "_");
if (result.Contains("*"))
result.Replace("*", "_");
result = result.Replace("*", "_");
if (result.Contains("<"))
result.Replace("<", "_");
result = result.Replace("<", "_");
if (result.Contains(">"))
result.Replace(">", "_");
result = result.Replace(">", "_");
return result;
}

View File

@@ -16,6 +16,8 @@ class Program
bool fixTags = false;
bool enhanceStructure = false;
List<decimal> threads = new();
var query = new Query("NavidromeMetadataRecovery1", "1.0");
var query2 = new Query("NavidromeMetadataRecovery2", "1.0");
var query3 = new Query("NavidromeMetadataRecovery3", "1.0");
@@ -76,8 +78,9 @@ class Program
files.AddRange(Directory.GetFiles(directory, $"*.{format}"));
}
Func<List<string>, Query, Task> cycle = async (List<string> chunk, Query query) =>
Func<List<string>, Query, int, Task> cycle = async (List<string> chunk, Query query, int thread) =>
{
threads.Add(thread);
for (int i = 0; i < chunk.Count; i++)
{
if (fixTags)
@@ -86,29 +89,33 @@ class Program
TagEditor.Edit(chunk[i], album, i);
Console.WriteLine($"{i+1}. {chunk[i]} successfully edited");
}
threads.Remove(thread);
};
if ((int)(files.Count / 4) > 1)
{
Thread thread = new Thread(async () => await cycle(files.GetRange(0, (int)(files.Count / 4)), query)) { IsBackground = true };
Thread thread = new Thread(async () => await cycle(files.GetRange(0, (int)(files.Count / 4)), query, 1)) { IsBackground = true };
thread.Start();
Thread thread2 = new Thread(async () => await cycle(files.GetRange((int)(files.Count / 4), (int)(files.Count / 4)), query2)) { IsBackground = true };
Thread thread2 = new Thread(async () => await cycle(files.GetRange((int)(files.Count / 4), (int)(files.Count / 4)), query2, 2)) { IsBackground = true };
thread2.Start();
if ((int)(files.Count / 4) >= 3) {
Thread thread3 = new Thread(async () => await cycle(files.GetRange(((int)(files.Count / 4) * 2), (int)(files.Count / 4)), query3)) { IsBackground = true };
Thread thread3 = new Thread(async () => await cycle(files.GetRange(((int)(files.Count / 4) * 2), (int)(files.Count / 4)), query3, 3)) { IsBackground = true };
thread3.Start();
}
if ((int)(files.Count / 4) >= 4) {
Thread thread4 = new Thread(async () => await cycle(files.GetRange(((int)(files.Count / 4) * 3), files.Count - ((int)(files.Count / 4) * 3)), query4)) { IsBackground = true };
Thread thread4 = new Thread(async () => await cycle(files.GetRange(((int)(files.Count / 4) * 3), files.Count - ((int)(files.Count / 4) * 3)), query4, 4)) { IsBackground = true };
thread4.Start();
}
Console.WriteLine("Waiting for threads complete");
Console.ReadKey();
while(threads.Count > 0) { }
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\n\nTag fixing completed!");
Console.ResetColor();
}
else
await cycle(files, query);
await cycle(files, query, 1);
}
}