예제 #1
0
        internal static VkVideo FromJson(JToken json)
        {
            if (json == null)
            {
                throw new ArgumentException("Json can not be null.");
            }
            VkVideo vkVideo = new VkVideo();

            if (json["id"] != null)
            {
                vkVideo.Id = json["id"].Value <long>();
            }
            if (json["vid"] != null)
            {
                vkVideo.Id = json["vid"].Value <long>();
            }
            vkVideo.OwnerId  = json["owner_id"].Value <long>();
            vkVideo.Duration = TimeSpan.FromSeconds(json["duration"].Value <double>());
            if (json["link"] != null)
            {
                vkVideo.Link = json["link"].Value <string>();
            }
            vkVideo.Title       = WebUtility.HtmlDecode(json["title"].Value <string>());
            vkVideo.Description = WebUtility.HtmlDecode(json["description"].Value <string>());
            if (json["thumb"] != null)
            {
                vkVideo.ImageSmall = json["thumb"].Value <string>();
            }
            if (json["image_medium"] != null)
            {
                vkVideo.ImageMedium = json["image_medium"].Value <string>();
            }
            if (json["player"] != null)
            {
                vkVideo.Player = json["player"].Value <string>();
            }
            if (json["files"] != null)
            {
                vkVideo.Files = new Dictionary <string, string>();
                using (IEnumerator <JToken> enumerator = json["files"].Children().GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        JProperty jProperty = (JProperty)enumerator.Current;
                        if (jProperty.HasValues)
                        {
                            vkVideo.Files.Add(jProperty.Name, jProperty.Value.Value <string>());
                        }
                    }
                }
            }
            return(vkVideo);
        }
예제 #2
0
        public async Task <IEnumerable <VkVideo> > Search(string query, int count = 0, int offset = 0, bool hdOnly = false, VkAudioSortType sort = VkAudioSortType.DateAdded, bool adult = false)
        {
            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 (hdOnly)
            {
                dictionary.Add("hd", "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 (adult)
            {
                dictionary.Add("adult", "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/video.search"), dictionary, "GET").Execute();
            IEnumerable <VkVideo> result;

            if (VkErrorProcessor.ProcessError(jObject))
            {
                result = null;
            }
            else
            {
                if (jObject["response"].HasValues)
                {
                    result = Enumerable.Select <JToken, VkVideo>(jObject["response"], (JToken v) => VkVideo.FromJson(v));
                }
                else
                {
                    result = null;
                }
            }
            return(result);
        }
예제 #3
0
        public async Task <IEnumerable <VkVideo> > Get(IList <string> videos = null, string uid = null, string gid = null, string aid = null, int previewWidth = 0, int count = 0, int offset = 0)
        {
            if (count > 200)
            {
                throw new ArgumentException("Maximum count is 200.");
            }
            Dictionary <string, string> dictionary = new Dictionary <string, string>();

            if (videos != null)
            {
                dictionary.Add("videos", string.Join(",", videos));
            }
            if (!string.IsNullOrEmpty(uid))
            {
                dictionary.Add("uid", uid);
            }
            if (!string.IsNullOrEmpty(gid))
            {
                dictionary.Add("gid", gid);
            }
            if (!string.IsNullOrEmpty(aid))
            {
                dictionary.Add("aid", aid);
            }
            if (previewWidth > 0)
            {
                dictionary.Add("width", previewWidth.ToString(CultureInfo.InvariantCulture));
            }
            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/video.get"), dictionary, "GET").Execute();
            IEnumerable <VkVideo> result;

            if (VkErrorProcessor.ProcessError(jObject))
            {
                result = null;
            }
            else
            {
                if (jObject["response"].HasValues)
                {
                    result = Enumerable.Select <JToken, VkVideo>(Enumerable.Where <JToken>(jObject["response"], (JToken v) => v.HasValues), (JToken v) => VkVideo.FromJson(v));
                }
                else
                {
                    result = null;
                }
            }
            return(result);
        }