Exemplo n.º 1
0
 // Extension to aid deserialization of lists :)
 public static void Deserialize <T>(this IEnumerable <T> aItems, IDeezerClient aClient) where T : IDeserializable <IDeezerClient>
 {
     foreach (T item in aItems)
     {
         item.Deserialize(aClient);
     }
 }
Exemplo n.º 2
0
        public static IArtist FromJson(JToken json, IDeezerClient client)
        {
            if (json == null)
            {
                return(null);
            }

            return(new Artist()
            {
                Id = json.Value <ulong>(ID_PROPERTY_NAME),
                Name = json.Value <string>(NAME_PROPERTY_NAME),
                Link = json.Value <string>(LINK_PROPERTY_NAME),
                ShareLink = json.Value <string>(SHARE_LINK_PROPERTY_NAME),

                NumberOfAlbums = json.Value <uint>(ALBUM_COUNT_PROPERTY_NAME),
                NumberOfFans = json.Value <uint>(FAN_COUNT_PROPERTY_NAME),

                Pictures = Api.Images.FromJson(json),

                HasSmartRadio = json.Value <bool>(HAS_RADIO_PROPERTY_NAME),


                Client = client,
            });
        }
Exemplo n.º 3
0
        public AuthenticationService(IDeezerClient client)
        {
            this.client = client;

            this.lockObj          = new object();
            this.inflightAuthTask = Task.FromResult <bool>(false);
        }
Exemplo n.º 4
0
        // TODO: UnseenTrackCount
        // TODO: CreationDate
        // TODO: Rating

        public static IPlaylist FromJson(JToken json, IDeezerClient client)
        {
            return(new Playlist()
            {
                Id = ulong.Parse(json.Value <string>(ID_PROPERTY_NAME)),

                Title = json.Value <string>(TITLE_PROPERTY_NAME),
                Description = json.Value <string>(DESCRIPTION_PROPERTY_NAME),

                IsPublic = json.Value <bool>(PUBLIC_PROPERTY_NAME),
                IsCollaborative = json.Value <bool>(COLLABORATIVE_PROPERTY_NAME),
                IsLovedTrack = json.Value <bool>(LOVED_TRACKS_PROPERTY_NAME),

                Duration = json.Value <uint>(DURATION_PROPERTY_NAME),

                NumberOfFans = json.Value <uint>(FANS_PROPERTY_NAME),
                NumberOfTracks = json.Value <uint>(TRACK_COUNT_PROPERTY_NAME),

                Link = json.Value <string>(LINK_PROPERTY_NAME),
                ShareLink = json.Value <string>(SHARE_LINK_PROPERTY_NAME),

                Images = Api.Images.FromJson(json),

                Creator = Api.UserProfile.FromJson(json[CREATOR_PROPERTY_NAME], client) ?? Api.UserProfile.FromJson(json[USER_PROPERTY_NAME], client),
                TracklistInternal = FragmentOf <ITrack> .FromJson(json[TRACKS_PROPERTY_NAME], x => Api.Track.FromJson(x, client)),

                Client = client,
            });
        }
Exemplo n.º 5
0
 public static IChart FromJson(JToken json, IDeezerClient client)
 {
     return(new Chart()
     {
         Albums = FragmentOf <IAlbum> .FromJson(json[ALBUMS_PROPERTY_NAME], x => Api.Album.FromJson(x, client)),
         Artists = FragmentOf <IArtist> .FromJson(json[ARTISTS_PROPERTY_NAME], x => Api.Artist.FromJson(x, client)),
         Tracks = FragmentOf <ITrack> .FromJson(json[TRACKS_PROPERTY_NAME], x => Api.Track.FromJson(x, client)),
         Playlists = FragmentOf <IPlaylist> .FromJson(json[PLAYLISTS_PROPERTY_NAME], x => Api.Playlist.FromJson(x, client)),
     });
 }
Exemplo n.º 6
0
        public static IAlbum FromJson(JToken json, IDeezerClient client)
        {
            if (json == null)
            {
                return(null);
            }

            string   apiDateString = json.Value <string>(RELEASE_DATE_PROPERTY_NAME);
            DateTime?releaseDate   = DateTimeExtensions.ParseApiDateTime(apiDateString);

            return(new Album()
            {
                Id = json.Value <ulong>(ID_PROPERTY_NAME),
                Title = json.Value <string>(TITLE_PROPERTY_NAME),

                UPC = json.Value <string>(UPC_PROPERTY_NAME),

                Link = json.Value <string>(LINK_PROPERTY_NAME),
                ShareLink = json.Value <string>(SHARE_LINK_PROPERTY_NAME),

                CoverArtwork = Images.FromJson(json),

                GenreId = json.ValueOrDefault <ulong>(GENRE_ID_PROPERTY_NAME, 0),
                Genre = FragmentOf <IGenre> .FromJson(json[GENRE_LIST_PROPERTY_NAME],
                                                      x => Api.Genre.FromJson(x, client)),

                Fans = json.Value <uint>(FANS_PROPERTY_NAME),

                Rating = json.Value <int>(RATING_PROPERTY_NAME),

                Label = json.Value <string>(LABEL_PROPERTY_NAME),
                TrackCount = json.Value <uint>(TRACK_COUNT_PROEPRTY_NAME),
                Duration = json.Value <uint>(DURATION_PROPERTY_NAME),

                ReleaseDate = releaseDate,

                Available = json.Value <bool>(AVAILABLE_PROPERTY_NAME),

                RecordType = json.Value <string>(RECORD_TYPE_PROPERTY_NAME),

                Contributors = CollectionOf <IArtist> .FromJson(json[CONTRIBUTORS_PROPERTY_NAME],
                                                                x => Api.Artist.FromJson(x, client)),

                Artist = Api.Artist.FromJson(json[ARTIST_PROPERTY_NAME], client),

                TracklistInternal = FragmentOf <ITrack> .FromJson(json[TRACKS_PROPERTY_NAME],
                                                                  x => Api.Track.FromJson(x, client)),


                // ISessionObject
                Client = client,
            });
        }
Exemplo n.º 7
0
 public Endpoints(IDeezerClient client)
 {
     this.Albums    = new AlbumEndpoint(client);
     this.Artists   = new ArtistEndpoint(client);
     this.Charts    = new ChartsEndpoint(client);
     this.Comments  = new CommentsEndpoint(client);
     this.Genre     = new GenreEndpoint(client);
     this.Playlists = new PlaylistsEndpoint(client);
     this.Radio     = new RadioEndpoint(client);
     this.Track     = new TrackEndpoint(client);
     this.User      = new UserEndpoint(client);
     this.Search    = new SearchEndpoint(client);
 }
Exemplo n.º 8
0
        public static IGenre FromJson(JToken json, IDeezerClient client)
        {
            ulong  id   = json.Value <ulong>(ID_PROPERTY_NAME);
            string name = json.Value <string>(NAME_RROPERY_NAME);

            return(new Genre()
            {
                Id = id,
                Name = name,
                Images = Api.Images.FromJson(json),

                Client = client,
            });
        }
Exemplo n.º 9
0
        public static IRadio FromJson(JToken json, IDeezerClient client)
        {
            return(new Radio()
            {
                Id = json.Value <ulong>(ID_PROPERTY_NAME),
                Title = json.Value <string>(TITLE_PROPERTY_NAME),
                Description = json.Value <string>(DESCRIPTION_PROPERTY_NAME),
                ShareLink = json.Value <string>(SHARE_LINK_PROPERTY_NAME),

                Images = Api.Images.FromJson(json),

                Client = client,
            });
        }
Exemplo n.º 10
0
        public static IComment FromJson(JToken json, IDeezerClient client)
        {
            uint     dateAsUnixSeconds = json.Value <uint>(POSTED_PROPERTY_NAME);
            DateTime?postedDate        = DateTimeExtensions.ParseUnixTimeFromSeconds(dateAsUnixSeconds);

            return(new Comment()
            {
                Id = ulong.Parse(json.Value <string>(ID_PROPERTY_NAME)),
                Text = json.Value <string>(TEXT_PROPERTY_NAME),

                Posted = postedDate,

                Author = Api.UserProfile.FromJson(json[AUTHOR_PROPERTY_NAME], client),


                Client = client,
            });
        }
Exemplo n.º 11
0
        public static IUserProfile FromJson(JToken json, IDeezerClient client)
        {
            if (json == null)
            {
                return(null);
            }

            return(new UserProfile()
            {
                Id = ulong.Parse(json.Value <string>(ID_PROPERTY_NAME)),

                Username = json.Value <string>(USERNAME_PROPERTY_NAME),

                Link = json.Value <string>(LINK_PROPERTY_NAME),

                Country = json.Value <string>(COUNTRY_PROPERTY_NAME),

                ProfilePictures = Api.Images.FromJson(json),


                Client = client,
            });
        }
Exemplo n.º 12
0
        // TODO IsKid
        // TODO: Gender. Would likely be parsed into an enum (M, F, Unknown/Not Specified
        // TODO: status. Returns int, but docs don't specify anything about it's values
        // TODO: explicit status ATM. Would need to generate ENUM from returned values to make it easier to user


        public static IUserV2 FromJson(JToken json, IDeezerClient client)
        {
            var birthdayDate = json.Value <string>(BIRTHDAY_PROPERTY_NAME);

            DateTime?birthdayAsDateTime = birthdayDate == DEFAULT_BIRTHDAY ? (DateTime?)null
                                                                            : DateTimeExtensions.ParseApiDateTime(birthdayDate);

            var      inscriptionDateStr = json.Value <string>(INSCRIPTION_PROPERTY_NAME);
            DateTime?inscriptionDate    = null;

            if (inscriptionDateStr != null)
            {
                inscriptionDate = DateTimeExtensions.ParseApiDateTime(inscriptionDateStr);
            }

            return(new UserV2()
            {
                Id = json.Value <ulong>(ID_PROPERTY_NAME),
                Username = json.Value <string>(USERNAME_PROPERTY_NAME),
                Firstname = json.Value <string>(FIRSTNAME_PROPERTY_NAME),
                Lastname = json.Value <string>(LASTNAME_PROPERTY_NAME),
                EmailAddress = json.Value <string>(EMAIL_PROPERTY_NAME),

                Birthday = birthdayAsDateTime,
                Inscription = inscriptionDate,

                ProfilePicture = Images.FromJson(json),

                Country = json.Value <string>(COUNTRY_PROPERTY_NAME),
                Language = json.Value <string>(LANGUAGE_PROPERTY_NAME),

                Link = json.Value <string>(LINK_PROPERTY_NAME),


                Client = client,
            });
        }
Exemplo n.º 13
0
 public AlbumEndpoint(IDeezerClient client)
 {
     this.client = client;
 }
Exemplo n.º 14
0
 public RadioEndpoint(IDeezerClient client)
 {
     this.client = client;
 }
Exemplo n.º 15
0
 public GenreEndpoint(IDeezerClient client)
 {
     this.client = client;
 }
Exemplo n.º 16
0
 public PlaylistsEndpoint(IDeezerClient client)
 {
     this.client = client;
 }
Exemplo n.º 17
0
 public UserEndpoint(IDeezerClient client)
 {
     this.client = client;
 }
Exemplo n.º 18
0
 public SearchEndpoint(IDeezerClient client)
 {
     this.client = client;
 }
Exemplo n.º 19
0
 public TrackEndpoint(IDeezerClient client)
 {
     this.client = client;
 }
Exemplo n.º 20
0
 public ArtistEndpoint(IDeezerClient client)
 {
     this.client = client;
 }
Exemplo n.º 21
0
 public ChartsEndpoint(IDeezerClient client)
 {
     this.client = client;
 }
Exemplo n.º 22
0
        //TODO Readable
        //TODO Title_version
        //TODO Explicit


        public static ITrack FromJson(JToken json, IDeezerClient client)
        {
            var      releaseDateString = json.Value <string>(RELEASE_PROPERTY_NAME);
            DateTime?releaseDate       = DateTimeExtensions.ParseApiDateTime(releaseDateString);

            //TODO -> AvailableFrom property??
            //var availabilityDateString = json.Value<String>(TimeAdd)

            /* Tracks don't always come with their own artwork.
             * Instead, we'll pinch the artwork from the 'Album' property
             * if this is available in the returned JSON. */
            var containedInAlbum = Api.Album.FromJson(json[ALBUM_PROPERTY_NAME], client);

            var internalArtwork = Api.Images.FromJson(json);

            var actualArtwork = new TrackImages(containedInAlbum,
                                                internalArtwork?.Small,
                                                internalArtwork?.Medium,
                                                internalArtwork?.Large,
                                                internalArtwork?.ExtraLarge);

            bool hasAvailabiltyList = (json as JObject)?.ContainsKey(AVAILABLE_COUNTRY_PROPERTY_NAME) ?? false;

            // Json.Values<string>() is lazy, need to wrap and eval into a list at this point
            // as the underlying json is disposed as soon as the parsing has been completed.
            IEnumerable <string> availableInList = hasAvailabiltyList ? new List <string>(json[AVAILABLE_COUNTRY_PROPERTY_NAME].Values <string>())
                                                                     : new List <string>(0);

            return(new Track()
            {
                Id = json.Value <ulong>(ID_PROPERTY_NAME),

                Title = json.Value <string>(TITLE_PROPERTY_NAME),
                ShortTitle = json.Value <string>(SHORT_TITLE_PROPERTY_NAME),

                ISRC = json.Value <string>(ISRC_PROPERTY_NAME),
                Link = json.Value <string>(LINK_PROPERTY_NAME),
                ShareLink = json.Value <string>(SHARE_LINK_PROPERTY_NAME),
                PreviewLink = json.Value <string>(PREVIEW_PROPERTY_NAME),

                Duration = json.Value <uint>(DURATION_PROPERTY_NAME),
                BPM = json.Value <float>(BPM_PROPERTY_NAME),
                Gain = json.Value <float>(GAIN_PROPERTY_NAME),

                TrackNumber = json.Value <uint>(TRACK_NUMBER_PROPERTY_NAME),
                DiscNumber = json.Value <uint>(DISC_NUMBER_PROPERTY_NAME),

                Rank = json.Value <uint>(RANK_PROPERTY_NAME),

                ReleaseDate = releaseDate,

                Artwork = actualArtwork,

                AvailableIn = availableInList,

                Artist = Api.Artist.FromJson(json[ARTIST_PROPERTY_NAME], client),
                Album = containedInAlbum,
                Contributors = CollectionOf <IArtist> .FromJson(json[CONTRIBUTORS_PROPERTY_NAME], x => Api.Artist.FromJson(x, client)),

                // ISssionObject
                Client = client,
            });
        }