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:
parent
718931da98
commit
9dab77950a
2 changed files with 68 additions and 24 deletions
|
@ -496,19 +496,23 @@ static partial class Program
|
|||
var retrievedFolders = new HashSet<string>();
|
||||
bool succeeded = false;
|
||||
string? soulseekDir = null;
|
||||
int index = 0;
|
||||
|
||||
while (tle.list.Count > 0 && !Config.I.albumArtOnly)
|
||||
{
|
||||
int index = 0;
|
||||
bool wasInteractive = Config.I.interactiveMode;
|
||||
bool retrieveCurrent = true;
|
||||
index = 0;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
tracks = tle.list[index];
|
||||
else
|
||||
{
|
||||
tracks = tle.list[index];
|
||||
}
|
||||
|
||||
soulseekDir = Utils.GreatestCommonDirectorySlsk(tracks.Select(t => t.FirstDownload.Filename));
|
||||
|
||||
|
@ -527,7 +531,7 @@ static partial class Program
|
|||
{
|
||||
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...");
|
||||
|
||||
|
@ -567,7 +571,7 @@ static partial class Program
|
|||
if (Config.I.albumArtOnly || succeeded && Config.I.albumArtOption != AlbumArtOption.Default)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -724,14 +728,18 @@ static partial class Program
|
|||
{
|
||||
int index = 0;
|
||||
bool wasInteractive = Config.I.interactiveMode;
|
||||
List<Track> tracks;
|
||||
|
||||
if (Config.I.interactiveMode)
|
||||
{
|
||||
index = await InteractiveModeAlbum(albumArtLists, false, null);
|
||||
(index, tracks, _) = await InteractiveModeAlbum(albumArtLists, false, null);
|
||||
if (index == -1) break;
|
||||
}
|
||||
else
|
||||
{
|
||||
tracks = albumArtLists[index];
|
||||
}
|
||||
|
||||
var tracks = albumArtLists[index];
|
||||
albumArtLists.RemoveAt(index);
|
||||
|
||||
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;
|
||||
static string interactiveModeLoop()
|
||||
static string interactiveModeLoop() // bug: characters don't disappear when backspacing
|
||||
{
|
||||
string userInput = "";
|
||||
while (true)
|
||||
|
@ -890,13 +898,19 @@ static partial class Program
|
|||
}
|
||||
}
|
||||
|
||||
string retrieveAll1 = retrieveFolder ? "| [r] " : "";
|
||||
string retrieveAll2 = retrieveFolder ? "| Load All Files " : "";
|
||||
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();
|
||||
}
|
||||
|
||||
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();
|
||||
writeHelp();
|
||||
|
||||
while (true)
|
||||
{
|
||||
|
@ -906,11 +920,19 @@ static partial class Program
|
|||
|
||||
WriteLine($"[{aidx + 1} / {list.Count}]", ConsoleColor.DarkGray);
|
||||
|
||||
PrintAlbum(tracks);
|
||||
PrintAlbum(tracks, indices: true);
|
||||
Console.WriteLine();
|
||||
|
||||
Loop:
|
||||
string userInput = interactiveModeLoop().Trim().ToLower();
|
||||
string options = "";
|
||||
|
||||
if (userInput.StartsWith("d:"))
|
||||
{
|
||||
options = userInput.Substring(2).Trim();
|
||||
userInput = "d";
|
||||
}
|
||||
|
||||
switch (userInput)
|
||||
{
|
||||
case "p":
|
||||
|
@ -920,10 +942,10 @@ static partial class Program
|
|||
aidx = (aidx + 1) % list.Count;
|
||||
break;
|
||||
case "s":
|
||||
return -1;
|
||||
return (-1, new List<Track>(), false);
|
||||
case "q":
|
||||
Config.I.interactiveMode = false;
|
||||
return aidx;
|
||||
return (aidx, tracks, true);
|
||||
case "r":
|
||||
if (!retrieveFolder)
|
||||
break;
|
||||
|
@ -944,8 +966,24 @@ static partial class Program
|
|||
}
|
||||
}
|
||||
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 "":
|
||||
return aidx;
|
||||
return (aidx, tracks, true);
|
||||
default:
|
||||
writeHelp();
|
||||
goto Loop;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
return;
|
||||
|
@ -63,6 +63,12 @@ public static class Printing
|
|||
{
|
||||
foreach (var x in tracks[i].Downloads)
|
||||
{
|
||||
if (indices)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.DarkGray;
|
||||
Console.Write($"[{i + 1:D2}]");
|
||||
Console.ResetColor();
|
||||
}
|
||||
if (ancestor.Length == 0)
|
||||
Console.WriteLine(" " + DisplayString(tracks[i], x.Item2, x.Item1, infoFirst: infoFirst, showUser: showUser));
|
||||
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)
|
||||
return;
|
||||
|
@ -245,7 +251,7 @@ public static class Printing
|
|||
var (parents, props) = FolderInfo(albumTracks.Select(x => x.FirstDownload));
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue