Пример #1
0
        internal static VkAudio FromJson(JToken json)
        {
            if (json == null)
            {
                throw new ArgumentException("Json can not be null.");
            }
            VkAudio vkAudio = new VkAudio();

            vkAudio.Id       = json["aid"].Value <long>();
            vkAudio.OwnerId  = json["owner_id"].Value <long>();
            vkAudio.Duration = TimeSpan.FromSeconds(json["duration"].Value <double>());
            vkAudio.Url      = json["url"].Value <string>();
            try
            {
                vkAudio.Title  = WebUtility.HtmlDecode(json["title"].Value <string>()).Trim();
                vkAudio.Artist = WebUtility.HtmlDecode(json["artist"].Value <string>()).Trim();
            }
            catch (Exception)
            {
                vkAudio.Title  = json["title"].Value <string>().Trim();
                vkAudio.Artist = json["artist"].Value <string>().Trim();
            }
            if (json["album_id"] != null)
            {
                vkAudio.AlbumId = json["album_id"].Value <long>();
            }
            if (json["lyrics_id"] != null)
            {
                vkAudio.LyricsId = json["lyrics_id"].Value <string>();
            }
            return(vkAudio);
        }
Пример #2
0
        public async Task <IEnumerable <VkAudio> > GetPopular(int count, int offset)
        {
            Dictionary <string, string> dictionary = new Dictionary <string, string>();

            if (count > 0)
            {
                dictionary.Add("count", count.ToString(CultureInfo.InvariantCulture));
            }
            if (offset > 0)
            {
                dictionary.Add("offset", offset.ToString(CultureInfo.InvariantCulture));
            }
            dictionary.Add("access_token", Vkontakte.Instance.AccessToken.Token);
            JObject jObject = await new VkRequest(new Uri("https://api.vk.com/method/audio.getPopular"), dictionary, "GET").Execute();
            IEnumerable <VkAudio> result;

            if (VkErrorProcessor.ProcessError(jObject))
            {
                result = null;
            }
            else
            {
                if (jObject["response"].HasValues)
                {
                    result = Enumerable.Select <JToken, VkAudio>(jObject["response"], (JToken a) => VkAudio.FromJson(a));
                }
                else
                {
                    result = null;
                }
            }
            return(result);
        }
Пример #3
0
        public async Task <IEnumerable <VkAudio> > GetById(IList <string> ids)
        {
            Dictionary <string, string> dictionary = new Dictionary <string, string>();

            dictionary.Add("audios", string.Join(",", ids));
            dictionary.Add("access_token", Vkontakte.Instance.AccessToken.Token);
            JObject jObject = await new VkRequest(new Uri("https://api.vk.com/method/audio.getById"), dictionary, "GET").Execute();
            IEnumerable <VkAudio> result;

            if (VkErrorProcessor.ProcessError(jObject))
            {
                result = null;
            }
            else
            {
                if (jObject["response"].HasValues)
                {
                    result = Enumerable.Select <JToken, VkAudio>(jObject["response"], (JToken a) => VkAudio.FromJson(a));
                }
                else
                {
                    result = null;
                }
            }
            return(result);
        }
Пример #4
0
        public async Task <IEnumerable <VkAudio> > Get(string userId, string groupId, string albumId, bool needUser, int count = 0, int offset = 0)
        {
            Dictionary <string, string> dictionary = new Dictionary <string, string>();

            if (!string.IsNullOrEmpty(groupId))
            {
                dictionary.Add("gid", groupId);
            }
            else
            {
                dictionary.Add("uid", userId);
            }
            if (!string.IsNullOrEmpty(albumId))
            {
                dictionary.Add("album_id", albumId);
            }
            if (needUser)
            {
                dictionary.Add("need_user", "1");
            }
            if (count > 0)
            {
                dictionary.Add("count", count.ToString(CultureInfo.InvariantCulture));
            }
            if (offset > 0)
            {
                dictionary.Add("offset", offset.ToString(CultureInfo.InvariantCulture));
            }
            dictionary.Add("access_token", Vkontakte.Instance.AccessToken.Token);
            JObject jObject = await new VkRequest(new Uri("https://api.vk.com/method/audio.get"), dictionary, "GET").Execute();
            IEnumerable <VkAudio> result;

            if (VkErrorProcessor.ProcessError(jObject))
            {
                result = null;
            }
            else
            {
                if (jObject["response"].HasValues)
                {
                    result = Enumerable.Select <JToken, VkAudio>(jObject["response"], (JToken a) => VkAudio.FromJson(a));
                }
                else
                {
                    result = null;
                }
            }
            return(result);
        }
Пример #5
0
        public async Task <IEnumerable <VkAudio> > Search(string query, int count = 0, int offset = 0, VkAudioSortType sort = VkAudioSortType.DateAdded, bool withLyricsOnly = false, bool autoFix = true)
        {
            if (count > 200)
            {
                throw new ArgumentException("Maximum count is 200.");
            }
            if (query == null)
            {
                throw new ArgumentException("Query must not be null.");
            }
            Dictionary <string, string> dictionary = new Dictionary <string, string>();

            dictionary.Add("q", query);
            if (autoFix)
            {
                dictionary.Add("auto_complete", "1");
            }
            Dictionary <string, string> arg_98_0 = dictionary;
            string arg_98_1 = "sort";
            int    num      = (int)sort;

            arg_98_0.Add(arg_98_1, num.ToString(CultureInfo.InvariantCulture));
            if (withLyricsOnly)
            {
                dictionary.Add("lyrics", "1");
            }
            if (count > 0)
            {
                dictionary.Add("count", count.ToString(CultureInfo.InvariantCulture));
            }
            else
            {
                dictionary.Add("count", 200.ToString(CultureInfo.InvariantCulture));
            }
            if (offset > 0)
            {
                dictionary.Add("offset", offset.ToString(CultureInfo.InvariantCulture));
            }
            dictionary.Add("access_token", Vkontakte.Instance.AccessToken.Token);
            JObject jObject = await new VkRequest(new Uri("https://api.vk.com/method/audio.search"), dictionary, "GET").Execute();
            IEnumerable <VkAudio> result;

            if (VkErrorProcessor.ProcessError(jObject))
            {
                result = null;
            }
            else
            {
                if (jObject["response"].HasValues)
                {
                    result = Enumerable.Select <JToken, VkAudio>(Enumerable.Where <JToken>(jObject["response"], (JToken a) => a.HasValues && !string.IsNullOrEmpty(a["url"].Value <string>())), (JToken a) => VkAudio.FromJson(a));
                }
                else
                {
                    result = null;
                }
            }
            return(result);
        }