Skip to content

Commit 537fece

Browse files
committed
Auto accept yt-dlp download after 10 seconds
1 parent a9392c4 commit 537fece

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

Services/DownloaderService.cs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,40 @@ public async Task CheckExecutableExists()
3535
{
3636
if (!File.Exists(await _hostService.GetDownloaderExecutablePath()))
3737
{
38-
ConsoleKey response;
39-
do
38+
var response = true;
39+
var countdown = 10;
40+
41+
while (countdown > 0)
4042
{
41-
await LogHelper.Log("Seems like yt-dlp has not been found. Would you like me to download it for you? [y/n]");
42-
response = Console.ReadKey(false).Key;
43+
Console.SetCursorPosition(0, 0);
44+
Console.Write($"Seems like yt-dlp has not been found. Would you like me to download it for you? [y/n] ({countdown}s until auto accept) ");
4345

44-
if (response != ConsoleKey.Enter)
46+
if (Console.KeyAvailable)
4547
{
46-
await LogHelper.Log("");
48+
ConsoleKey key = Console.ReadKey(false).Key;
49+
50+
if (key == ConsoleKey.Y)
51+
{
52+
break;
53+
}
54+
55+
if (key == ConsoleKey.N)
56+
{
57+
response = false;
58+
break;
59+
}
4760
}
48-
} while (response != ConsoleKey.Y && response != ConsoleKey.N);
4961

50-
if (response == ConsoleKey.N)
62+
await Task.Delay(1000);
63+
countdown--;
64+
}
65+
66+
if (response == false)
5167
{
5268
await ErrorHelper.LogAndExit("You decided not to download yt-dlp, therefore the application must exit. yt-dlp is a requirement.");
5369
}
54-
else if (response == ConsoleKey.Y)
70+
71+
if (response == true)
5572
{
5673
await LogHelper.Log("Download starting");
5774

0 commit comments

Comments
 (0)