From 7689745d485ac9da5a5cc503ee4fae4cb7a83ac5 Mon Sep 17 00:00:00 2001 From: fiso64 Date: Sat, 19 Oct 2024 16:24:12 +0200 Subject: [PATCH] implement select individual files in interactive mode --- slsk-batchdl/Program.cs | 19 ++++++++++++++++--- slsk-batchdl/Utilities/Printing.cs | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/slsk-batchdl/Program.cs b/slsk-batchdl/Program.cs index cfd6cb7..749f7ba 100644 --- a/slsk-batchdl/Program.cs +++ b/slsk-batchdl/Program.cs @@ -906,7 +906,7 @@ static partial class Program WriteLine($" [Up/p] | [Down/n] | [Enter] | [q] {retrieveAll1}| [Esc/s]", ConsoleColor.Green); WriteLine($" Prev | Next | Accept | Accept & Quit Interactive {retrieveAll2}| Skip", ConsoleColor.Green); Console.WriteLine(); - WriteLine($" d:1,2,3 to download individual files", ConsoleColor.Green); + WriteLine($" d:1,2,3 or d:start:end to download individual files", ConsoleColor.Green); Console.WriteLine(); } @@ -970,8 +970,21 @@ static partial class Program if (options.Length == 0) return (aidx, tracks, true); try - { - var indices = options.Split(',').Select(int.Parse).ToArray(); + { + var indices = options.Split(',') + .SelectMany(option => + { + if (option.Contains(':')) + { + var parts = option.Split(':'); + int start = string.IsNullOrEmpty(parts[0]) ? 1 : int.Parse(parts[0]); + int end = string.IsNullOrEmpty(parts[1]) ? tracks.Count : int.Parse(parts[1]); + return Enumerable.Range(start, end - start + 1); + } + return new[] { int.Parse(option) }; + }) + .Distinct() + .ToArray(); return (aidx, indices.Select(i => tracks[i - 1]).ToList(), false); } catch diff --git a/slsk-batchdl/Utilities/Printing.cs b/slsk-batchdl/Utilities/Printing.cs index 661086d..6694c01 100644 --- a/slsk-batchdl/Utilities/Printing.cs +++ b/slsk-batchdl/Utilities/Printing.cs @@ -66,7 +66,7 @@ public static class Printing if (indices) { Console.ForegroundColor = ConsoleColor.DarkGray; - Console.Write($"[{i + 1:D2}]"); + Console.Write($" [{i + 1:D2}]"); Console.ResetColor(); } if (ancestor.Length == 0)