Exemple #1
0
            public Match(GnResponseAlbums result)
            {
                foreach (var album in result.Albums)
                {
                    Albums.Add(album.GnUId);
                    Artists.Add(album.Artist.Contributor.GnUId);

                    foreach (var track in album.TracksMatched)
                    {
                        Tracks.Add(track.GnUId);
                        var trackArtist = track.Artist?.Contributor?.GnUId;
                        if (!string.IsNullOrWhiteSpace(trackArtist))
                        {
                            Artists.Add(trackArtist);
                        }
                    }
                }
            }
Exemple #2
0
        public override void MusicIdStreamAlbumResult(GnResponseAlbums result, IGnCancellable canceller)
        {
            if (result.ResultCount == 0)
            {
                Console.WriteLine("Failed to match =(");
                return;
            }
            else
            {
                Program.DidMatch = true;
            }

            var match = new Match(result);

            var dupe = _matches.Take(5).Any(x => x.AreMaybeTheSame(match));

            _matches.Push(match);
            if (dupe)
            {
                Console.WriteLine("Skipping same song.");
                return;
            }


            var first = true;

            foreach (var album in result.Albums)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.WriteLine();
                }

                var track = album.TracksMatched?.FirstOrDefault();

                var albumArtist = album.Artist.Name.Display;
                var trackArtist = track.Artist?.Name?.Display;
                var artist      = string.IsNullOrWhiteSpace(trackArtist) ? albumArtist : trackArtist;
                Console.WriteLine($"\tArtist: {artist}");

                Console.WriteLine($"\tAlbum: {album.Title.Display} ({album.Year})");

                Console.WriteLine($"\tTrack #{track.TrackNumber}: {track.Title.Display}");

                var spotifyUrl = new Uri("https://open.spotify.com/search/results/" + Uri.EscapeUriString($"artist:\"{artist.Replace("\"", "")}\" {track.Title.Display}"));
                Console.WriteLine($"\tSpotify Search: {spotifyUrl}");

                //var content = album.Content(GnContentType.kContentTypeImageCover);

                //if (content != null) {
                //  var extension = "";
                //  switch (content.MimeType) {
                //    case "image/jpeg":
                //      extension = "jpg";
                //      break;
                //    case "image/png":
                //      extension = "png";
                //      break;
                //    default:
                //      Console.WriteLine($"\tUnknown MimeType {content.MimeType}");
                //      break;
                //  }

                //  if (!string.IsNullOrWhiteSpace(extension)) {
                //    Directory.CreateDirectory("content");
                //    var file = new FileInfo($"content\\{album.GnUId}.{content.ContentType}.{extension}");
                //    if (!file.Exists) {
                //      var asset = content.Asset(GnImageSize.kImageSizeXLarge);
                //      var url = asset.UrlHttp();
                //      if (!string.IsNullOrWhiteSpace(url)) {
                //        Console.WriteLine($"\tSaving {url} to {file.FullName}");
                //        var wc = new WebClient();
                //        wc.DownloadFile(url, file.FullName);
                //      }
                //    }
                //  }
                //}
            }
        }