From 55571f4156d0ceaea995255e4071a1348952d9d6 Mon Sep 17 00:00:00 2001 From: fiso64 Date: Tue, 24 Dec 2024 12:18:59 +0100 Subject: [PATCH] improve track str parser --- slsk-batchdl/Config.cs | 4 ++-- slsk-batchdl/Extractors/String.cs | 18 +++++++++--------- slsk-batchdl/Program.cs | 1 + slsk-batchdl/Utilities/Printing.cs | 6 +++++- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/slsk-batchdl/Config.cs b/slsk-batchdl/Config.cs index 38a98f7..5680cf9 100644 --- a/slsk-batchdl/Config.cs +++ b/slsk-batchdl/Config.cs @@ -1088,7 +1088,7 @@ public class Config case "--pref-strict-title": setNullableFlag(ref preferredCond.StrictTitle, ref i); break; - case "--psa": + case "--psar": case "--pref-strict-artist": setNullableFlag(ref preferredCond.StrictArtist, ref i); break; @@ -1142,7 +1142,7 @@ public class Config case "--strict-title": setNullableFlag(ref necessaryCond.StrictTitle, ref i); break; - case "--sa": + case "--sar": case "--strict-artist": setNullableFlag(ref necessaryCond.StrictArtist, ref i); break; diff --git a/slsk-batchdl/Extractors/String.cs b/slsk-batchdl/Extractors/String.cs index 810d154..13d197c 100644 --- a/slsk-batchdl/Extractors/String.cs +++ b/slsk-batchdl/Extractors/String.cs @@ -131,11 +131,17 @@ namespace Extractors setProperty(currentKey, currentVal.Trim()); other = other.Trim(); - if (other.Length > 0) + if (other.Length > 0 && (isAlbum && track.Album.Length > 0 || !isAlbum && track.Title.Length > 0)) + { + Printing.WriteLine($"Warning: Input part '{other}' provided without a property name " + + $"and album or title is already set. Ignoring.", ConsoleColor.DarkYellow); + } + else if (other.Length > 0) { string artist = "", album = "", title = ""; - parts = other.Split(" - ", StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries); - if (parts.Length == 1 || parts.Length > 3) + parts = other.Split(" - ", 2, StringSplitOptions.TrimEntries); + + if (parts.Length == 1 || track.Artist.Length > 0) { if (isAlbum) album = other.Trim(); @@ -151,12 +157,6 @@ namespace Extractors else title = parts[1]; } - else if (parts.Length == 3) - { - artist = parts[0]; - album = parts[1]; - title = parts[2]; - } if (track.Artist.Length == 0) track.Artist = artist; diff --git a/slsk-batchdl/Program.cs b/slsk-batchdl/Program.cs index 1be6d82..210e5c5 100644 --- a/slsk-batchdl/Program.cs +++ b/slsk-batchdl/Program.cs @@ -1372,6 +1372,7 @@ static partial class Program .Replace("{uri}", track.URI) .Replace("{length}", track.Length.ToString()) .Replace("{row}", (track.CsvOrListRow == -1 ? -1 : track.CsvOrListRow + 1).ToString()) + .Replace("{line}", (track.CsvOrListRow == -1 ? -1 : track.CsvOrListRow + 1).ToString()) .Replace("{artist-maybe-wrong}", track.ArtistMaybeWrong.ToString()) .Replace("{type}", track.Type.ToString()) .Replace("{is-not-audio}", track.IsNotAudio.ToString()) diff --git a/slsk-batchdl/Utilities/Printing.cs b/slsk-batchdl/Utilities/Printing.cs index c1603ec..700cd53 100644 --- a/slsk-batchdl/Utilities/Printing.cs +++ b/slsk-batchdl/Utilities/Printing.cs @@ -94,6 +94,8 @@ public static class Printing Console.WriteLine($" Title: {tracks[i].Title}"); if (!string.IsNullOrEmpty(tracks[i].Album) || tracks[i].Type == TrackType.Album) Console.WriteLine($" Album: {tracks[i].Album}"); + if (tracks[i].MinAlbumTrackCount != -1 || tracks[i].MaxAlbumTrackCount != -1) + Console.WriteLine($" Min,Max tracks: {tracks[i].MinAlbumTrackCount},{tracks[i].MaxAlbumTrackCount}"); if (tracks[i].Length > -1 || tracks[i].Type == TrackType.Normal) Console.WriteLine($" Length: {tracks[i].Length}s"); if (!string.IsNullOrEmpty(tracks[i].DownloadPath)) @@ -132,7 +134,9 @@ public static class Printing } Console.WriteLine(); } - Console.WriteLine(); + + if (i < number - 1) + Console.WriteLine(); } }