Пример #1
0
 public void Add(Song song)
 {
     if (song == default(Song))
         throw new ArgumentNullException(nameof(song), @"Please enter a song.");
     Debug.WriteLine($"[Waiting] - Downloading song {song.SongName}");
     _songs.Add(song);
 }
Пример #2
0
 public async Task<Song> DownloadSongInformation(string id) {
     Over:
     try {
         string result;
         using (var web = new WebClient()) {
             result = await web.DownloadStringTaskAsync("https://api.spotify.com/v1/tracks/" + id);
         }
         var info = JsonConvert.DeserializeObject<JObject>(result);
         var song = new Song {
             Id = id,
             AlbumName = (string) info["album"]["name"],
             SongName = (string) info["name"],
             Image = (string) info["album"]["images"][0]["url"],
             Ico = (string) info["album"]["images"][2]["url"],
             Artists = new List<string>(),
             Doing = "Waiting...",
             Length = 0,
             Progress = 0,
             YoutubeId = ""
         };
         foreach (var artist in info["artists"]) {
             song.Artists.Add((string) artist["name"]);
         }
         return song;
     } catch (Exception ex) {
         Debug.WriteLine(ex);
         await Task.Delay(2000);
         goto Over;
     }
 }
Пример #3
0
 public async Task<List<string>> Find(Song song) {
     var searchListRequest = _youTubeService.Search.List("snippet");
     searchListRequest.Q = $"{song.Artists[0]} {song.SongName}";
     searchListRequest.MaxResults = 50;
     var searchListResponse = await searchListRequest.ExecuteAsync();
     var videos = (from searchResult in searchListResponse.Items
         where searchResult.Id.Kind == "youtube#video"
         select $"{searchResult.Snippet.Title} ({searchResult.Id.VideoId})").ToList();
     return videos;
 }
Пример #4
0
 public async void Download(Song song) {
     await Task.Factory.StartNew(async () => {
         try {
             using (var service = Client.For(YouTube.Default)) {
                 var video = await service.GetVideoAsync($"https://www.youtube.com/watch?v={song.YoutubeId}");
                 var bytes = video.GetBytes();
                 File.WriteAllBytes(
                     $@"./temp{(string.IsNullOrWhiteSpace(song.Artists[0]) ? $"/{song.Artists[0]}/" : "/")}{song
                         .SongName}.mp4", bytes);
             }
         } catch (Exception ex) {
             Debug.WriteLine(ex.Message);
         }
     });
 }