예제 #1
0
파일: YandexTrack.cs 프로젝트: cutpix/Lofi
        public static YandexTrack FromJson(JToken jTrack)
        {
            try
            {
                var track = new YandexTrack
                {
                    Id        = jTrack.GetString("id"),
                    RealId    = jTrack.GetString("realId"),
                    Title     = jTrack.GetString("title"),
                    Major     = YandexMajor.FromJson(jTrack.Contains("major")),
                    Available = jTrack.GetBool("available"),
                    AvailableForPremiumUsers = jTrack.GetBool("availableForPremiumUsers"),
                    Albums     = jTrack.ContainField("albums") ? YandexAlbum.FromJsonArray(jTrack["albums"].ToObject <JArray>()) : null,
                    DurationMS = jTrack["durationMs"].ToObject <int>(),
                    StorageDir = jTrack.GetString("storageDir"),
                    FileSize   = jTrack.GetInt("fileSize"),
                    Artists    = YandexArtist.FromJsonArray(jTrack["artists"].ToObject <JArray>()),
                    OgImage    = jTrack.GetString("ogImage")
                };
                return(track);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            return(null);
        }
예제 #2
0
파일: YandexAlbum.cs 프로젝트: cutpix/Lofi
        public static YandexAlbum FromJson(JToken jAlbum)
        {
            var album = new YandexAlbum
            {
                Artists   = YandexArtist.FromJsonArray(jAlbum["artists"].ToObject <JArray>()),
                Available = jAlbum.GetBool("available"),
                AvailableForPremiumUsers = jAlbum.GetBool("availableForPremiumUsers"),
                CoverUri            = jAlbum.GetString("coverUri"),
                Genre               = jAlbum.GetString("genre"),
                Id                  = jAlbum.GetString("id"),
                OriginalReleaseYear = jAlbum.GetString("originalReleaseYear"),
                Regions             = jAlbum.Contains("regions")
          ? jAlbum["regions"].ToObject <JArray>().Select(x => (string)x).ToList()
          : null,
                StorageDir = jAlbum.GetString("storageDir"),
                Title      = jAlbum.GetString("title"),
                TrackCount = jAlbum.GetInt("trackCount"),
                Year       = jAlbum.GetString("year"),
                Bests      = jAlbum.ContainField("bests")
          ? jAlbum["bests"].ToObject <JArray>().Select(x => x.ToString()).ToList()
          : null,
                Type = jAlbum.GetString("type"),
            };

            if (jAlbum.ContainField("volumes"))
            {
                if (jAlbum["volumes"].ToString() != String.Empty)
                {
                    var fieldVolumes = jAlbum["volumes"].ToObject <JArray>().FirstOrDefault();
                    if (fieldVolumes != null)
                    {
                        var jVolumes = fieldVolumes.ToObject <JArray>();
                        var tracks   = YandexTrack.FromJsonArray(jVolumes);
                        album.Volumes = new List <List <YandexTrack> > {
                            tracks
                        };
                    }
                    else
                    {
                        album.Volumes = null;
                    }
                }
            }
//      album.Volumes = jAlbum.ContainField("volumes")
//        ? new List<List<Track>>
//        {
//          Track.FromJsonArray(jAlbum["volumes"].ToObject<JArray>().First().ToObject<JArray>())
//        }
//        : null;

            return(album);
        }
예제 #3
0
파일: YandexArtist.cs 프로젝트: cutpix/Lofi
        public static YandexArtist FromJson(JToken jArtist)
        {
            var artist = new YandexArtist
            {
                Id       = jArtist.GetString("id"),
                Name     = jArtist.GetString("name"),
                Various  = jArtist.GetBool("various"),
                Composer = jArtist.GetBool("composer"),
                Cover    = jArtist.ContainField("cover") ? YandexCover.FromJson(jArtist["cover"]) : null,
                Genres   = new string[] { }
            };

            return(artist);
        }
예제 #4
0
        public List <IYandexSearchable> Search(string searchText, YandexSearchType searchType, int page = 0)
        {
            var listResult = new List <IYandexSearchable>();

            var request = GetRequest(_settings.GetSearchURL(searchText, searchType, page), WebRequestMethods.Http.Get);

            using (var response = (HttpWebResponse)request.GetResponse())
            {
                var json      = GetDataFromResponse(response);
                var fieldName = searchType.ToString().ToLower();
                var jArray    = (JArray)json[fieldName]["items"];

                if (searchType == YandexSearchType.Tracks)
                {
                    listResult = YandexTrack.FromJsonArray(jArray).Select(x => (IYandexSearchable)x).ToList();
                }
                else if (searchType == YandexSearchType.Artists)
                {
                    listResult = YandexArtist.FromJsonArray(jArray).Select(x => (IYandexSearchable)x).ToList();
                }
                else if (searchType == YandexSearchType.Albums)
                {
                    listResult = YandexAlbum.FromJsonArray(jArray).Select(x => (IYandexSearchable)x).ToList();
                }
                else if (searchType == YandexSearchType.Playlists)
                {
                    listResult = YandexPlaylist.FromJsonArray(jArray).Select(x => (IYandexSearchable)x).ToList();
                }
                else if (searchType == YandexSearchType.Users)
                {
                    listResult = YandexUser.FromJsonArray(jArray).Select(x => (IYandexSearchable)x).ToList();
                }
            }

            return(listResult);
        }