-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDownload.cs
53 lines (48 loc) · 1.61 KB
/
Download.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System.Net;
using System.Diagnostics;
public class AlQuran
{
private string _curPath = Directory.GetCurrentDirectory();
private int _countDo = 0;
public delegate void OnDownloadedDelegate(int orderid, Stopwatch x);
public OnDownloadedDelegate OnDownloaded {get;set;}
private void run(int number, int downloadFileID)
{
var timer = new Stopwatch();
timer.Start();
using (var client = new WebClient())
{
client.DownloadFile($"https://ia803406.us.archive.org/27/items/AlQuranWithEnglishSaheehIntlTranslation--RecitationByMishariIbnRashidAl-AfasyWithIbrahimWalk/{number:D3}.mp3", $"{_curPath}/downloads/{number:D3}.mp3");
OnDownloaded?.Invoke(downloadFileID,timer);
}
}
public async void Download(int number)
{
if(1 <= number && number <= 114)
{
_countDo++;
Console.WriteLine($"#{_countDo}: Download started");
await Task.Run(() => run(number,_countDo));
}
else
{
ColorPrint("ERROR !!! : The surah you entered does not exist in our base!",_Colors.Red);
}
}
public enum _Colors
{
Red,
Green,
White
}
public void ColorPrint(string text,_Colors color)
{
var rang = color switch
{
_Colors.Red => Console.ForegroundColor = ConsoleColor.Red,
_Colors.Green => Console.ForegroundColor = ConsoleColor.Green
};
Console.WriteLine($"{text}",Console.ForegroundColor);
Console.ForegroundColor = ConsoleColor.White;
}
}