Exemplo n.º 1
0
        public static DiscogsAlbum ParseAlbum(JObject jData)
        {
            DiscogsAlbum album = new DiscogsAlbum
            {
                Name      = jData.GetStringValue("title").FixDiscogsName(),
                Id        = jData.GetStringValue("id"),
                Year      = jData.GetStringValue("year").ToInt(),
                Artists   = new List <DiscogsAlbumArtist>(),
                TrackList = new List <DiscogsTrack>(),
                Images    = new List <ImageInfo>(),
                Styles    = new List <string>(jData["styles"].Select(x => x.ToString())),
                Genres    = new List <string>(jData["genres"].Select(x => x.ToString()))
            };

            foreach (var art in jData["artists"])
            {
                album.Artists.Add(new DiscogsAlbumArtist
                {
                    Name = art.GetStringValue("name").FixDiscogsName(),
                    Id   = art.GetStringValue("id")
                });
            }

            foreach (var trk in jData["tracklist"])
            {
                album.TrackList.Add(new DiscogsTrack
                {
                    Title    = trk.GetStringValue("title"),
                    Duration = trk.GetStringValue("duration"),
                    Position = trk.GetStringValue("position")
                });
            }
            foreach (var img in jData["images"])
            {
                album.Images.Add(new ImageInfo
                {
                    Link = img.GetStringValue("uri"),
                    Size = new ImageSize(img.GetStringValue("width").ToInt(), img.GetStringValue("height").ToInt())
                });
            }

            //Check if master release
            album.MasterId = jData.HasProperty("master_id") ? jData.GetStringValue("master_id") : album.Id;

            return(album);
        }
Exemplo n.º 2
0
        public async Task <DiscogsAlbum> GetMasterAlbumById(string id)
        {
            string args = $"/masters/{id}?{_credentials}";

            var jsonSource = await GetRequestJson(args);

            try
            {
                JObject      json  = JObject.Parse(jsonSource);
                DiscogsAlbum album = DiscogsAlbum.ParseAlbum(json);
                return(album);
            }
            catch (JsonReaderException jException)
            {
                throw new Exception(jsonSource, jException);
            }
            catch (Exception ex)
            {
                throw new Exception("A error as occur", ex);
            }
        }
Exemplo n.º 3
0
        public async Task <DiscogsAlbum> GetReleaseAlbumById(string id)
        {
            string args = string.Format("/releases/{0}?{1}", id, _credentials);
            Uri    url  = new Uri(Domain + args);


            HttpClient webClient  = CreateDiscogsClient();
            string     jsonSource = await webClient.GetStringAsync(url);

            try
            {
                JObject      json  = JObject.Parse(jsonSource);
                DiscogsAlbum album = DiscogsAlbum.ParseAlbum(json);
                return(album);
            }
            catch (JsonReaderException jException)
            {
                throw new Exception(jsonSource, jException);
            }
            catch (Exception ex)
            {
                throw new Exception("A error as occur", ex);
            }
        }