public LastFMTrack GetTagInfo(Track track) { TrackInfo = new LastFMTrack(); var api = new XmlDocument(); var artist = PCLWebUtility.WebUtility.UrlEncode(track.Artist); var title = PCLWebUtility.WebUtility.UrlEncode(track.Title); var apiKey = _apiKey[_random.Next(3)]; try { api.Load(ApiUrl(apiKey, artist, title)); } catch (Exception ex) { Console.WriteLine(ex.Message); return(null); } var apiReturn = api.DocumentElement; if (apiReturn == null) { return(null); } var serializer = new XmlSerializer(typeof(LastFMTrack)); var node = apiReturn.SelectSingleNode("/lfm/track"); TrackInfo = serializer.Deserialize(new XmlNodeReader(node)) as LastFMTrack; return(TrackInfo); }
internal void MapLastFMAPITrackToTrack_ReturnsExpectedDetailedTrack() { var trackExtra = new LastFMTrack { Name = "Do not want updated Title from this api", Artist = new Artist { Name = "Do not want updated Artist from this api" }, Album = new Album { Title = "Album Title", Position = "5", Image = new List <Image> { new Image { Size = AlbumCoverSize.extralarge.ToString(), Url = "http://xlarge-cover-url.local" }, new Image { Size = AlbumCoverSize.large.ToString(), Url = "http://large-cover-url.local" }, new Image { Size = AlbumCoverSize.medium.ToString(), Url = "http://medium-cover-url.local" }, new Image { Size = AlbumCoverSize.small.ToString(), Url = "http://small-cover-url.local" } } }, Toptags = new Toptags { Tag = new List <Tag> { new Tag { Name = "Reggae", Url = "http://reggae-tag.local" }, new Tag { Name = "Rock", Url = "http://rock-tag.local" }, new Tag { Name = "Jazz", Url = "http://jazz-tag.local" } } }, Duration = 1337000 }; _lastFMAPI.MapLastFMTrackToTrack(_track, trackExtra); Assert.NotEqual(trackExtra.Name, _track.Title); Assert.NotEqual(trackExtra.Artist.Name, _track.Artist); Assert.Equal(trackExtra.Album.Title, _track.Album); Assert.Equal(5, _track.AlbumPosition); Assert.Equal(new[] { "Reggae", "Rock", "Jazz" }, _track.Genres); Assert.Equal(1337, _track.Length); Assert.Equal("http://xlarge-cover-url.local", _track.ArtExtraLargeUrl); Assert.Equal("http://large-cover-url.local", _track.ArtLargeUrl); Assert.Equal("http://medium-cover-url.local", _track.ArtMediumUrl); Assert.Equal("http://small-cover-url.local", _track.ArtSmallUrl); }
internal void MapLastFMAPIEmptyTrackToTrack_ReturnsExpectedTrack() { var previousTrack = new Track(_track); var trackExtra = new LastFMTrack(); _lastFMAPI.MapLastFMTrackToTrack(_track, trackExtra); Assert.NotNull(_track.Title); Assert.Equal(previousTrack, _track); }
private void MapLastFMTrackToTrack(Track track, LastFMTrack trackExtra) { track.Album = trackExtra.Album?.AlbumTitle; track.AlbumPosition = trackExtra.Album?.TrackPosition; track.Genres = trackExtra.Toptags?.Tag?.Select(x => x.Name).ToArray(); track.Length = trackExtra.Duration / 1000; track.ArtExtraLargeUrl = trackExtra.Album?.ExtraLargeCoverUrl; track.ArtLargeUrl = trackExtra.Album?.LargeCoverUrl; track.ArtMediumUrl = trackExtra.Album?.MediumCoverUrl; track.ArtSmallUrl = trackExtra.Album?.SmallCoverUrl; }
public void MapLastFMTrackToTrack(Track track, LastFMTrack trackExtra) { track.Album = trackExtra.Album?.AlbumTitle; track.AlbumPosition = trackExtra.Album?.TrackPosition; track.Genres = trackExtra.Toptags?.Tag?.Select(x => x?.Name).Where(x => x != null).ToArray(); track.Length = trackExtra.Duration.HasValue ? trackExtra.Duration / 1000 : null; track.ArtExtraLargeUrl = trackExtra.Album?.ExtraLargeCoverUrl; track.ArtLargeUrl = trackExtra.Album?.LargeCoverUrl; track.ArtMediumUrl = trackExtra.Album?.MediumCoverUrl; track.ArtSmallUrl = trackExtra.Album?.SmallCoverUrl; }
public LastFMTrack GetTrackInfo(LastFMTrack track) { using (var webClient = new WebClient()) { string url = $"http://ws.audioscrobbler.com/2.0/?method=track.getInfo&api_key={APIKEY}&artist={track.Artist.Name}&track={track.Name}&format=json"; var jsonStr = webClient.DownloadString(url); var response = JsonConvert.DeserializeObject <LastFMGetInfoResponse>(jsonStr); return(response.Track); } }
private Track MapLastFMTrackToTrack(LastFMTrack trackExtra) { return(new Track(Track) { Album = trackExtra.Album?.AlbumTitle, AlbumPosition = trackExtra.Album?.TrackPosition, Genres = trackExtra.Toptags?.Tag?.Select(x => x.Name).ToArray(), Length = trackExtra.Duration / 1000, ArtExtraLargeUrl = trackExtra.Album?.ExtraLargeCoverUrl, ArtLargeUrl = trackExtra.Album?.LargeCoverUrl, ArtMediumUrl = trackExtra.Album?.MediumCoverUrl, ArtSmallUrl = trackExtra.Album?.SmallCoverUrl }); }
internal void MapLastFMAPTrackToTrack_ReturnsExpectedMissingInfoTrack() { var track = new Track() { Artist = "Artist", Title = "Title", TitleExtended = "Live", TitleExtendedSeparatorType = TitleSeparatorType.Dash }; var trackExtra = new LastFMTrack() { Artist = new Artist(), Album = new Album() { Image = new List <Image>() { null, null, null, null, } }, Toptags = new Toptags() { Tag = new List <Tag>() { null, null, null, } }, }; _lastFMAPI.MapLastFMTrackToTrack(track, trackExtra); Assert.Equal("Artist - Title - Live", track.ToString()); Assert.Equal("Title", track.Title); Assert.Equal("Artist", track.Artist); Assert.Equal(trackExtra.Album.Title, _track.Album); Assert.Null(track.Album); Assert.Null(track.AlbumPosition); Assert.Equal(new string[] { }, track.Genres); Assert.Null(track.Length); Assert.Null(track.ArtExtraLargeUrl); Assert.Null(track.ArtLargeUrl); Assert.Null(track.ArtMediumUrl); Assert.Null(track.ArtSmallUrl); }
internal void MapLastFMAPITrackToTrack_KeepSpytifyTrackIfEmpty() { var trackExtra = new LastFMTrack() { Name = "", Artist = new Artist { Name = "" }, }; _lastFMAPI.MapLastFMTrackToTrack(_track, trackExtra); Assert.Equal("Title", _track.Title); Assert.Equal("Artist", _track.Artist); }
internal void MapLastFMAPITrackToTrack_OverwritesSpytifyTrack() { var trackExtra = new LastFMTrack() { Name = "Do not want updated Title from this api", Artist = new Artist { Name = "Do not want updated Artist from this api" }, }; _lastFMAPI.MapLastFMTrackToTrack(_track, trackExtra); Assert.Equal("Title", _track.Title); Assert.Equal("Artist", _track.Artist); Assert.NotEqual(trackExtra.Name, _track.Title); Assert.NotEqual(trackExtra.Artist.Name, _track.Artist); }
internal void MapLastFMAPTrackToTrack_ReturnsExpectedMissingInfoTrack() { var track = new Track(); var trackExtra = new LastFMTrack() { Album = new Album() { Image = new List <Image>() { null, null, null, null, } }, Toptags = new Toptags() { Tag = new List <Tag>() { null, null, null, } }, }; _lastFMAPI.MapLastFMTrackToTrack(track, trackExtra); Assert.Null(track.Album); Assert.Null(track.AlbumPosition); Assert.Equal(new string[] { }, track.Genres); Assert.Null(track.Length); Assert.Null(track.ArtExtraLargeUrl); Assert.Null(track.ArtLargeUrl); Assert.Null(track.ArtMediumUrl); Assert.Null(track.ArtSmallUrl); }
internal void MapLastFMAPITrackToTrack_ReturnsExpectedTrack() { var track = new Track(); var trackExtra = new LastFMTrack() { Album = new Album() { Title = "Album Title", Position = "5", Image = new List <Image>() { new Image() { Size = AlbumCoverSize.extralarge.ToString(), Url = "http://xlarge-cover-url.local" }, new Image() { Size = AlbumCoverSize.large.ToString(), Url = "http://large-cover-url.local" }, new Image() { Size = AlbumCoverSize.medium.ToString(), Url = "http://medium-cover-url.local" }, new Image() { Size = AlbumCoverSize.small.ToString(), Url = "http://small-cover-url.local" }, } }, Toptags = new Toptags() { Tag = new List <Tag>() { new Tag() { Name = "Reggae", Url = "http://reggae-tag.local" }, new Tag() { Name = "Rock", Url = "http://rock-tag.local" }, new Tag() { Name = "Jazz", Url = "http://jazz-tag.local" }, } }, Duration = 1337000, }; _lastFMAPI.MapLastFMTrackToTrack(track, trackExtra); Assert.Equal("Album Title", track.Album); Assert.Equal(5, track.AlbumPosition); Assert.Equal(new[] { "Reggae", "Rock", "Jazz" }, track.Genres); Assert.Equal(1337, track.Length); Assert.Equal("http://xlarge-cover-url.local", track.ArtExtraLargeUrl); Assert.Equal("http://large-cover-url.local", track.ArtLargeUrl); Assert.Equal("http://medium-cover-url.local", track.ArtMediumUrl); Assert.Equal("http://small-cover-url.local", track.ArtSmallUrl); }