示例#1
0
        public static YandexPlaylist FromJson(JToken jList)
        {
            var playlist = new YandexPlaylist
            {
                Collective = jList.GetBool("collective"),
                Cover      = jList.ContainField("cover") ?
                             YandexCover.FromJson(jList["cover"]) : null,
                Description           = jList.GetString("description"),
                DescriptionFormatted  = jList.GetString("descriptionFormatted"),
                Duration              = jList.GetInt("Duration"),
                GeneratedPlaylistType = jList.GetString("generatedPlaylistType"),
                IdForFrom             = jList.GetString("IdForFrom"),
                Kind       = jList.GetInt("kind"),
                LikesCount = jList.GetInt("likesCount"),
                Modified   = jList.GetString("modified"),
                OgImage    = jList.GetString("ogImage"),
                Owner      = jList.ContainField("owner") ?
                             YandexOwner.FromJson(jList["owner"]) : null,
                Revision   = jList.GetInt("revision"),
                Title      = jList.GetString("title"),
                TrackCount = jList.GetInt("trackCount"),
                Visibility = jList.GetString("visibility"),
                TrackIds   = jList.ContainField("trackIds")
          ? jList["trackIds"].Select(x => int.Parse(x.ToString())).ToList() : null,
                Tracks = jList.ContainField("tracks")
          ? YandexTrack.FromJsonArray(jList["tracks"].ToObject <JArray>())
          : null
            };

            return(playlist);
        }
示例#2
0
        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);
        }
示例#3
0
        public YandexStreamTrack ExtractStreamTrack(YandexTrack track)
        {
            var trackDonloadInfo = GetDownloadTrackInfo(track.StorageDir);
            var trackDownloadUrl = _settings.GetURLDownloadTrack(track, trackDonloadInfo);

            var isNetworing = System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable();

            return(YandexStreamTrack.Open(trackDownloadUrl, track.FileSize));
        }
示例#4
0
        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);
        }
示例#5
0
        public byte[] ExtractDataTrack(YandexTrack track)
        {
            var trackDonloadInfo = GetDownloadTrackInfo(track.StorageDir);
            var trackDownloadUrl = _settings.GetURLDownloadTrack(track, trackDonloadInfo);

            byte[] bytes;

            using (var client = new WebClient())
            {
                bytes = client.DownloadData(trackDownloadUrl);
            }

            return(bytes);
        }
示例#6
0
        public YandexTrack GetTrack(string trackId)
        {
            var request = GetRequest(_settings.GetTrackURL(trackId), WebRequestMethods.Http.Get);
            var track   = default(YandexTrack);

            using (var response = (HttpWebResponse)request.GetResponse())
            {
                var data = GetDataFromResponse(response)["track"];
                track = YandexTrack.FromJson(data);

                _cookies.Add(response.Cookies);
            }

            return(track);
        }
示例#7
0
        public Uri GetURLDownloadTrack(YandexTrack track, YandexTrackDownloadInfo downloadInfo)
        {
            var key = ""; //downloadInfo.Path.Substring(1, downloadInfo.Path.Length - 1) + downloadInfo.S;

            using (var md5 = MD5.Create())
            {
                key = GetMdHesh(md5,
                                $"XGRlBW9FXlekgbPrRHuSiA{downloadInfo.Path.Substring(1, downloadInfo.Path.Length - 1)}{downloadInfo.S}");
            }

            var trackDownloadUrl =
                String.Format("http://{0}/get-mp3/{1}/{2}{3}?track-id={4}&region=225&from=service-search",
                              downloadInfo.Host,
                              key,
                              downloadInfo.Ts,
                              downloadInfo.Path,
                              track.Id);

            return(new Uri(trackDownloadUrl));
        }
示例#8
0
        public bool ExtractTrackToFile(YandexTrack track, string folder)
        {
            try
            {
                var trackDonloadInfo = GetDownloadTrackInfo(track.StorageDir);
                var trackDownloadUrl = _settings.GetURLDownloadTrack(track, trackDonloadInfo);
                var isNetworing      = System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable();

                using (var client = new WebClient())
                {
                    client.DownloadFile(trackDownloadUrl, $"{folder}/{track.Title}.mp3");
                }

                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            return(false);
        }
示例#9
0
        public List <YandexTrack> GetListFavorites(string login = null)
        {
            if (login == null)
            {
                login = _login;
            }

            var request = GetRequest(_settings.GetListFavoritesURL(login));
            var tracks  = new List <YandexTrack>();

            using (var response = (HttpWebResponse)request.GetResponse())
            {
                var data    = GetDataFromResponse(response);
                var jTracks = (JArray)data["tracks"];

                tracks = YandexTrack.FromJsonArray(jTracks);

                _cookies.Add(response.Cookies);
            }

            return(tracks);
        }
示例#10
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);
        }