internal SpotifySearchResponse(JObject data, SpotifyClient client) : base(client)
        {
            var artists = data["artists"];

            if (artists != null)
            {
                Artists = new SpotifyPagingResponse <SpotifyArtist>((JObject)artists, (o, c) => new SpotifyArtist(c, o), j => (JObject)j["artists"], client);
            }
            else
            {
                Artists = new SpotifyPagingResponse <SpotifyArtist>();
            }

            var albums = data["albums"];

            if (albums != null)
            {
                Albums = new SpotifyPagingResponse <SpotifyAlbumReference>((JObject)albums, (o, c) => new SpotifyAlbumReference(o, c), j => (JObject)j["albums"], client);
            }
            else
            {
                Albums = new SpotifyPagingResponse <SpotifyAlbumReference>();
            }

            var tracks = data["tracks"];

            if (tracks != null)
            {
                Tracks = new SpotifyPagingResponse <SpotifyTrack>((JObject)tracks, (o, c) => new SpotifyTrack(o, c), j => (JObject)j["tracks"], client);
            }
            else
            {
                Tracks = new SpotifyPagingResponse <SpotifyTrack>();
            }
        }
示例#2
0
        internal SpotifyAlbum(SpotifyClient client, JObject data) : base(client)
        {
            Type             = data["album_type"].ToObject <AlbumType>();
            Artists          = data["artists"].ToObject <IEnumerable <JObject> >().Select(a => new SpotifyArtistReference(client, a)).ToImmutableArray();
            AvailableMarkets = data["available_markets"].ToObject <ImmutableArray <string> >();
            Copyrights       = data["copyrights"]
                               .ToObject <IEnumerable <JObject> >()
                               .Select(a =>
                                       new SpotifyAlbumCopyright(a["text"].ToObject <string>(), a["type"].ToObject <string>() == "C" ? AlbumCopyrightType.Copyright : AlbumCopyrightType.PerformanceCopyright))
                               .ToImmutableArray();
            ExternalIds  = new SpotifyExternalIdsCollection(data["external_ids"].ToObject <IDictionary <string, string> >());
            ExternalUrls = new SpotifyExternalUrlsCollection(data["external_urls"].ToObject <IDictionary <string, string> >());
            Id           = new SpotifyUri(data["uri"].ToObject <string>());
            Images       = data["images"].ToObject <ImmutableArray <SpotifyImage> >();
            Label        = data["label"].ToObject <string>();
            Name         = data["name"].ToObject <string>();
            Popularity   = data["popularity"].ToObject <int>();

            var rdp = data["release_date_precision"].ToObject <string>();
            var rd  = data["release_date"].ToObject <string>().Split('-');

            switch (rdp)
            {
            case "year":
                ReleaseDate = new DateTimeOffset(int.Parse(rd[0]), 1, 1, 0, 0, 0, TimeSpan.Zero);
                break;

            case "month":
                ReleaseDate = new DateTimeOffset(int.Parse(rd[0]), int.Parse(rd[1]), 1, 0, 0, 0, TimeSpan.Zero);
                break;

            case "day":
                ReleaseDate = new DateTimeOffset(int.Parse(rd[0]), int.Parse(rd[1]), int.Parse(rd[2]), 0, 0, 0, TimeSpan.Zero);
                break;

            default:
                throw new InvalidOperationException("The specified release date precision was not year, month, or day.");
            }

            // TODO: Track Relinking

            Tracks = new SpotifyPagingResponse <SpotifyTrackReference>((JObject)data["tracks"], (o, c) => new SpotifyTrackReference(c, o), a => (JObject)a["tracks"], client);
        }