Пример #1
0
        internal SpotifyAlbumReference(JObject data, SpotifyClient client) : 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> >();
            ExternalUrls     = new SpotifyExternalUrlsCollection(data["external_urls"].ToObject <IDictionary <string, string> >());
            Id     = new SpotifyUri(data["uri"].ToObject <string>());
            Images = data["images"].ToObject <ImmutableArray <SpotifyImage> >();
            Name   = data["name"].ToObject <string>();
            var rdp = data["release_date_precision"].ToObject <string>();
            var rd  = data["release_date"].ToObject <string>().Split('-');

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

                "month" => new DateTimeOffset(int.Parse(rd[0]), int.Parse(rd[1]), 1, 0, 0, 0, TimeSpan.Zero),

                "day" => new DateTimeOffset(int.Parse(rd[0]), int.Parse(rd[1]), int.Parse(rd[2]), 0, 0, 0, TimeSpan.Zero),

                _ => throw new InvalidOperationException("The specified release date precision was not year, month, or day."),
            };
        }
Пример #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('-');

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

                "month" => new DateTimeOffset(int.Parse(rd[0]), int.Parse(rd[1]), 1, 0, 0, 0, TimeSpan.Zero),

                "day" => new DateTimeOffset(int.Parse(rd[0]), int.Parse(rd[1]), int.Parse(rd[2]), 0, 0, 0, TimeSpan.Zero),

                _ => 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);
        }
Пример #3
0
 internal SpotifyArtistReference(SpotifyClient client, JObject data) : base(client)
 {
     ExternalUrls = new SpotifyExternalUrlsCollection(data["external_urls"].ToObject <IDictionary <string, string> >());
     Id           = new SpotifyUri(data["uri"].ToObject <string>());
     Name         = data["name"].ToObject <string>();
 }