-
Notifications
You must be signed in to change notification settings - Fork 3
/
YMDownloader.cs
48 lines (41 loc) · 1.43 KB
/
YMDownloader.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
using System.IO;
using Yandex.Music.Api.Models.Track;
using Yandex.Music.Client;
using Yandex.Music.Client.Extensions;
using YMDB.Bot.Utils;
namespace YMDB.Bot.Yandex
{
public class YMDownloader
{
public YandexMusicClient Ymc { get; private set; }
private static YMDownloader Instance;
private string DownloadPath;
private YMDownloader(string login, string password, string downloadPath)
{
DownloadPath = downloadPath;
Ymc = new YandexMusicClient();
Ymc.Authorize(login, password);
}
public static YMDownloader GetInstance(string login = null, string password = null, string downloadPath = null)
{
return Instance ??= new YMDownloader(login, password, downloadPath);
}
public string DownloadTrack(string url)
{
// TODO: проверка на наличие файла
var track = UrlUtils.GetTrack(url);
var path = $"{DownloadPath}/{track.Id}.mp3";
if (!File.Exists(path))
track.Save(path);
return path;
}
public string DownloadTrack(YTrack track)
{
// TODO: проверка на наличие файла
var path = $"Data/{track.Id}.mp3";
if (!File.Exists(path))
track.Save(path);
return path;
}
}
}