Пример #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('-');

            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.");
            }
        }
Пример #2
0
 internal SpotifyArtist(SpotifyClient client, JObject data) : base(client)
 {
     ExternalUrls     = new SpotifyExternalUrlsCollection(data["external_urls"].ToObject <IDictionary <string, string> >());
     FollowerCount    = data["followers"]["total"].ToObject <int>();
     AssociatedGenres = data["genres"].ToObject <ImmutableArray <string> >();
     Images           = data["images"].ToObject <ImmutableArray <SpotifyImage> >();
     Name             = data["name"].ToObject <string>();
     Popularity       = data["popularity"].ToObject <int>();
     Id = new SpotifyUri(data["uri"].ToObject <string>());
 }
Пример #3
0
 internal SpotifyTrackReference(SpotifyClient client, JObject data) : base(client)
 {
     Artists           = data["artists"].ToObject <IEnumerable <JObject> >().Select(a => new SpotifyArtistReference(client, a)).ToImmutableArray();
     AvailableMarkets  = data["available_markets"].ToObject <ImmutableArray <string> >();
     DiscNumber        = data["disc_number"].ToObject <int>();
     Duration          = TimeSpan.FromMilliseconds(data["duration_ms"].ToObject <int>());
     HasExplicitLyrics = data["explicit"].ToObject <bool>();
     ExternalUrls      = new SpotifyExternalUrlsCollection(data["external_urls"].ToObject <IDictionary <string, string> >());
     Id = new SpotifyUri(data["uri"].ToObject <string>());
     // TODO: IS_PLAYABLE, LINKED_FROM, RESTRICTIONS
     Name         = data["name"].ToObject <string>();
     PreviewUrl   = data["preview_url"].ToObject <string>();
     TrackNumber  = data["track_number"].ToObject <int>();
     IsLocalTrack = data["is_local"].ToObject <bool>();
 }
Пример #4
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);
        }
Пример #5
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>();
 }