Fix playlist update
This commit is contained in:
parent
0ab8565dbf
commit
a0f3da27b6
|
@ -58,54 +58,60 @@ internal static class AutoTag {
|
|||
break;
|
||||
}
|
||||
case FolderType.Playlists: {
|
||||
foreach (var playlist in Directory.GetDirectories(inputDir.Path)) {
|
||||
var tracks = Directory.EnumerateFiles(playlist, "*.*", SearchOption.AllDirectories).Where(IsAllowed).OrderBy(s => s, new AlphanumComparator());
|
||||
|
||||
uint i = 1;
|
||||
var trackCount = tracks.Count();
|
||||
var playlistName = Path.GetFileName(playlist);
|
||||
|
||||
foreach (var track in tracks) {
|
||||
Console.WriteLine("<- " + track);
|
||||
var tagFile = TagFile.Create(track);
|
||||
var outputFileDirectory = inputDir.Path == outputDir ? outputDir : Path.Combine(outputDir, "Various Artists", CleanFileName(playlistName));
|
||||
Directory.CreateDirectory(outputFileDirectory);
|
||||
|
||||
var outputFilePath = Path.Combine(outputFileDirectory,
|
||||
CleanFileName(tagFile.Tag.Performers.Length == 0
|
||||
? $"{i}. {tagFile.Tag.Title}{Path.GetExtension(track)}"
|
||||
: $"{i}. {tagFile.Tag.Performers[0]} - {tagFile.Tag.Title}{Path.GetExtension(track)}"));
|
||||
|
||||
tagFile.Save();
|
||||
|
||||
if (inputDir.Path == outputDir)
|
||||
File.Move(track, outputFilePath, true);
|
||||
else
|
||||
File.Copy(track, outputFilePath, true);
|
||||
|
||||
var newTagFile = TagFile.Create(outputFilePath);
|
||||
newTagFile.Tag.Comment = null;
|
||||
newTagFile.Tag.Genres = null;
|
||||
newTagFile.Tag.Album = playlistName;
|
||||
newTagFile.Tag.Track = i++;
|
||||
newTagFile.Tag.TrackCount = (uint)trackCount;
|
||||
newTagFile.Tag.AlbumArtists = new[] { "Various Artists" };
|
||||
|
||||
if (newTagFile.Tag.Performers.Length == 0)
|
||||
newTagFile.Tag.Performers = new[] { "Various Artists" };
|
||||
|
||||
newTagFile.Save();
|
||||
|
||||
Console.WriteLine("-> " + outputFilePath);
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
if (inputDir.Path == outputDir)
|
||||
ProcessPlaylist(inputDir.Path, inputDir, outputDir);
|
||||
else
|
||||
foreach (var playlist in Directory.GetDirectories(inputDir.Path))
|
||||
ProcessPlaylist(playlist, inputDir, outputDir);
|
||||
|
||||
break;
|
||||
}
|
||||
default: throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
private static void ProcessPlaylist(string playlist, Folder inputDir, string outputDir) {
|
||||
var tracks = Directory.EnumerateFiles(playlist, "*.*", SearchOption.AllDirectories).Where(IsAllowed).OrderBy(s => s, new AlphanumComparator());
|
||||
|
||||
uint i = 1;
|
||||
var trackCount = tracks.Count();
|
||||
var playlistName = Path.GetFileName(playlist);
|
||||
|
||||
foreach (var track in tracks) {
|
||||
Console.WriteLine("<- " + track);
|
||||
var tagFile = TagFile.Create(track);
|
||||
var outputFileDirectory = inputDir.Path == outputDir ? outputDir : Path.Combine(outputDir, "Various Artists", CleanFileName(playlistName));
|
||||
Directory.CreateDirectory(outputFileDirectory);
|
||||
|
||||
var outputFilePath = Path.Combine(outputFileDirectory,
|
||||
CleanFileName(tagFile.Tag.Performers.Length == 0
|
||||
? $"{i}. {tagFile.Tag.Title}{Path.GetExtension(track)}"
|
||||
: $"{i}. {tagFile.Tag.Performers[0]} - {tagFile.Tag.Title}{Path.GetExtension(track)}"));
|
||||
|
||||
tagFile.Save();
|
||||
|
||||
if (inputDir.Path == outputDir)
|
||||
File.Move(track, outputFilePath, true);
|
||||
else
|
||||
File.Copy(track, outputFilePath, true);
|
||||
|
||||
var newTagFile = TagFile.Create(outputFilePath);
|
||||
newTagFile.Tag.Comment = null;
|
||||
newTagFile.Tag.Genres = null;
|
||||
newTagFile.Tag.Album = playlistName;
|
||||
newTagFile.Tag.Track = i++;
|
||||
newTagFile.Tag.TrackCount = (uint)trackCount;
|
||||
newTagFile.Tag.AlbumArtists = new[] { "Various Artists" };
|
||||
|
||||
if (newTagFile.Tag.Performers.Length == 0)
|
||||
newTagFile.Tag.Performers = new[] { "Various Artists" };
|
||||
|
||||
newTagFile.Save();
|
||||
|
||||
Console.WriteLine("-> " + outputFilePath);
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class Folder {
|
||||
|
|
Loading…
Reference in a new issue