1
0
Fork 0
mirror of https://github.com/fiso64/slsk-batchdl.git synced 2024-12-22 06:22:41 +00:00

implement select individual files in interactive mode

This commit is contained in:
fiso64 2024-10-19 15:53:50 +02:00
parent 718931da98
commit 9dab77950a
2 changed files with 68 additions and 24 deletions

View file

@ -496,19 +496,23 @@ static partial class Program
var retrievedFolders = new HashSet<string>(); var retrievedFolders = new HashSet<string>();
bool succeeded = false; bool succeeded = false;
string? soulseekDir = null; string? soulseekDir = null;
int index = 0;
while (tle.list.Count > 0 && !Config.I.albumArtOnly) while (tle.list.Count > 0 && !Config.I.albumArtOnly)
{ {
int index = 0;
bool wasInteractive = Config.I.interactiveMode; bool wasInteractive = Config.I.interactiveMode;
bool retrieveCurrent = true;
index = 0;
if (Config.I.interactiveMode) if (Config.I.interactiveMode)
{ {
index = await InteractiveModeAlbum(tle.list, !Config.I.noBrowseFolder, retrievedFolders); (index, tracks, retrieveCurrent) = await InteractiveModeAlbum(tle.list, !Config.I.noBrowseFolder, retrievedFolders);
if (index == -1) break; if (index == -1) break;
} }
else
tracks = tle.list[index]; {
tracks = tle.list[index];
}
soulseekDir = Utils.GreatestCommonDirectorySlsk(tracks.Select(t => t.FirstDownload.Filename)); soulseekDir = Utils.GreatestCommonDirectorySlsk(tracks.Select(t => t.FirstDownload.Filename));
@ -527,7 +531,7 @@ static partial class Program
{ {
await RunAlbumDownloads(tle, organizer, tracks, semaphore, cts); await RunAlbumDownloads(tle, organizer, tracks, semaphore, cts);
if (!Config.I.noBrowseFolder && !retrievedFolders.Contains(soulseekDir)) if (!Config.I.noBrowseFolder && retrieveCurrent && !retrievedFolders.Contains(soulseekDir))
{ {
Console.WriteLine("Getting all files in folder..."); Console.WriteLine("Getting all files in folder...");
@ -567,7 +571,7 @@ static partial class Program
if (Config.I.albumArtOnly || succeeded && Config.I.albumArtOption != AlbumArtOption.Default) if (Config.I.albumArtOnly || succeeded && Config.I.albumArtOption != AlbumArtOption.Default)
{ {
Console.WriteLine($"\nDownloading additional images:"); Console.WriteLine($"\nDownloading additional images:");
additionalImages = await DownloadImages(tle, tle.list, Config.I.albumArtOption, tracks); additionalImages = await DownloadImages(tle, tle.list, Config.I.albumArtOption, tle.list[index]);
tracks?.AddRange(additionalImages); tracks?.AddRange(additionalImages);
} }
@ -724,14 +728,18 @@ static partial class Program
{ {
int index = 0; int index = 0;
bool wasInteractive = Config.I.interactiveMode; bool wasInteractive = Config.I.interactiveMode;
List<Track> tracks;
if (Config.I.interactiveMode) if (Config.I.interactiveMode)
{ {
index = await InteractiveModeAlbum(albumArtLists, false, null); (index, tracks, _) = await InteractiveModeAlbum(albumArtLists, false, null);
if (index == -1) break; if (index == -1) break;
} }
else
{
tracks = albumArtLists[index];
}
var tracks = albumArtLists[index];
albumArtLists.RemoveAt(index); albumArtLists.RemoveAt(index);
if (!needImageDownload(tracks)) if (!needImageDownload(tracks))
@ -866,10 +874,10 @@ static partial class Program
} }
static async Task<int> InteractiveModeAlbum(List<List<Track>> list, bool retrieveFolder, HashSet<string>? retrievedFolders) static async Task<(int index, List<Track> tracks, bool retrieveFolder)> InteractiveModeAlbum(List<List<Track>> list, bool retrieveFolder, HashSet<string>? retrievedFolders)
{ {
int aidx = 0; int aidx = 0;
static string interactiveModeLoop() static string interactiveModeLoop() // bug: characters don't disappear when backspacing
{ {
string userInput = ""; string userInput = "";
while (true) while (true)
@ -889,14 +897,20 @@ static partial class Program
userInput += key.KeyChar; userInput += key.KeyChar;
} }
} }
void writeHelp()
{
string retrieveAll1 = retrieveFolder ? "| [r] " : "";
string retrieveAll2 = retrieveFolder ? "| Load All Files " : "";
Console.WriteLine();
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);
Console.WriteLine();
}
string retrieveAll1 = retrieveFolder ? "| [r] " : ""; writeHelp();
string retrieveAll2 = retrieveFolder ? "| Load All Files " : "";
Console.WriteLine();
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();
while (true) while (true)
{ {
@ -906,11 +920,19 @@ static partial class Program
WriteLine($"[{aidx + 1} / {list.Count}]", ConsoleColor.DarkGray); WriteLine($"[{aidx + 1} / {list.Count}]", ConsoleColor.DarkGray);
PrintAlbum(tracks); PrintAlbum(tracks, indices: true);
Console.WriteLine(); Console.WriteLine();
Loop: Loop:
string userInput = interactiveModeLoop().Trim().ToLower(); string userInput = interactiveModeLoop().Trim().ToLower();
string options = "";
if (userInput.StartsWith("d:"))
{
options = userInput.Substring(2).Trim();
userInput = "d";
}
switch (userInput) switch (userInput)
{ {
case "p": case "p":
@ -920,10 +942,10 @@ static partial class Program
aidx = (aidx + 1) % list.Count; aidx = (aidx + 1) % list.Count;
break; break;
case "s": case "s":
return -1; return (-1, new List<Track>(), false);
case "q": case "q":
Config.I.interactiveMode = false; Config.I.interactiveMode = false;
return aidx; return (aidx, tracks, true);
case "r": case "r":
if (!retrieveFolder) if (!retrieveFolder)
break; break;
@ -944,8 +966,24 @@ static partial class Program
} }
} }
break; break;
case "d":
if (options.Length == 0)
return (aidx, tracks, true);
try
{
var indices = options.Split(',').Select(int.Parse).ToArray();
return (aidx, indices.Select(i => tracks[i - 1]).ToList(), false);
}
catch
{
writeHelp();
goto Loop;
}
case "": case "":
return aidx; return (aidx, tracks, true);
default:
writeHelp();
goto Loop;
} }
} }
} }

View file

@ -45,7 +45,7 @@ public static class Printing
} }
public static void PrintTracks(List<Track> tracks, int number = int.MaxValue, bool fullInfo = false, bool pathsOnly = false, bool showAncestors = true, bool infoFirst = false, bool showUser = true) public static void PrintTracks(List<Track> tracks, int number = int.MaxValue, bool fullInfo = false, bool pathsOnly = false, bool showAncestors = true, bool infoFirst = false, bool showUser = true, bool indices = false)
{ {
if (tracks.Count == 0) if (tracks.Count == 0)
return; return;
@ -63,6 +63,12 @@ public static class Printing
{ {
foreach (var x in tracks[i].Downloads) foreach (var x in tracks[i].Downloads)
{ {
if (indices)
{
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.Write($"[{i + 1:D2}]");
Console.ResetColor();
}
if (ancestor.Length == 0) if (ancestor.Length == 0)
Console.WriteLine(" " + DisplayString(tracks[i], x.Item2, x.Item1, infoFirst: infoFirst, showUser: showUser)); Console.WriteLine(" " + DisplayString(tracks[i], x.Item2, x.Item1, infoFirst: infoFirst, showUser: showUser));
else else
@ -235,7 +241,7 @@ public static class Printing
} }
public static void PrintAlbum(List<Track> albumTracks) public static void PrintAlbum(List<Track> albumTracks, bool indices = false)
{ {
if (albumTracks.Count == 0 && albumTracks[0].Downloads.Count == 0) if (albumTracks.Count == 0 && albumTracks[0].Downloads.Count == 0)
return; return;
@ -245,7 +251,7 @@ public static class Printing
var (parents, props) = FolderInfo(albumTracks.Select(x => x.FirstDownload)); var (parents, props) = FolderInfo(albumTracks.Select(x => x.FirstDownload));
WriteLine($"User : {userInfo}\nFolder: {parents}\nProps : {props}", ConsoleColor.White); WriteLine($"User : {userInfo}\nFolder: {parents}\nProps : {props}", ConsoleColor.White);
PrintTracks(albumTracks.ToList(), pathsOnly: true, showAncestors: false, showUser: false); PrintTracks(albumTracks.ToList(), pathsOnly: true, showAncestors: false, showUser: false, indices: true);
} }