public Task AddImage(OnlineImage image) { if (Collection.ContainsKey(image.Guid)) return TaskExtensions.CompletedTask; return AddImageRow(image, 1, image.Url); }
public YouTubeSearchResult(string title, string artist, string uploader, string videoId, TimeSpan duration, string imageUrl) { Title = title; Artist = artist; Duration = duration; Cover = new OnlineImage(imageUrl); Uploader = uploader; _videoId = videoId; }
private static OnlineImage GetSmallImage(IEnumerable<Image> images) { var imageUrl = images.OrderBy(x => x.size).First().text; if (ImageCache.ContainsKey(imageUrl)) return ImageCache[imageUrl]; var onlineImage = new OnlineImage(imageUrl); ImageCache.Add(imageUrl, onlineImage); return onlineImage; }
private static OnlineImage GetMediumImage(IEnumerable<Image> images) { var source = images.OrderBy(x => x.size); var imageUrl = (source.FirstOrDefault(x => x.size == ImageSize.large) ?? source.FirstOrDefault(x => x.size == ImageSize.medium) ?? source.First()).text; if (ImageCache.ContainsKey(imageUrl)) return ImageCache[imageUrl]; var onlineImage = new OnlineImage(imageUrl); ImageCache.Add(imageUrl, onlineImage); return onlineImage; }
public async Task<TrackInformation> GetTrackInformation(string title, string artist) { using (var wc = new WebClient {Proxy = null}) { var s = (await wc.DownloadStringTaskAsync(artist == null ? $"http://ws.audioscrobbler.com/2.0/?method=track.search&track={title}&api_key={SensitiveInformation.LastfmKey}&format=json&limit=1" : $"http://ws.audioscrobbler.com/2.0/?method=track.search&track={title}&artist={artist}&api_key={SensitiveInformation.LastfmKey}&format=json&limit=1")); var fixedString = s.FixJsonString(); SearchTrackResult result; try { result = JsonConvert.DeserializeObject<SearchTrackResult>(fixedString); } catch (JsonException) { return null; } var trackResult = result?.results?.Trackmatches?.track; if (trackResult != null) { OnlineImage image = null; if (trackResult.image?.Count > 0) { var imageUrl = trackResult.image.Last().text; if (ImageCache.ContainsKey(imageUrl)) image = ImageCache[imageUrl]; else { image = new OnlineImage(imageUrl); ImageCache.Add(imageUrl, image); } } return new TrackInformation { Artist = trackResult.artist, Name = trackResult.name, Url = trackResult.url, MusicBrainzId = trackResult.mbid, CoverImage = image }; } return null; } }