internal static VkVideo FromJson(JToken json) { if (json == null) { throw new ArgumentException("Json can not be null."); } var result = new VkVideo(); if (json["id"] != null) { result.Id = json["id"].Value <long>(); } result.OwnerId = json["owner_id"].Value <long>(); result.Duration = TimeSpan.FromSeconds(json["duration"].Value <double>()); result.Title = WebUtility.HtmlDecode(json["title"].Value <string>()); result.Description = WebUtility.HtmlDecode(json["description"].Value <string>()); if (json["photo_130"] != null) { result.Photo130 = json["photo_130"].Value <string>(); } if (json["photo_320"] != null) { result.Photo130 = json["photo_320"].Value <string>(); } if (json["photo_640"] != null) { result.Photo130 = json["photo_640"].Value <string>(); } if (json["files"] != null) { result.Files = new Dictionary <string, string>(); foreach (JProperty child in json["files"].Children()) { if (!child.HasValues) { continue; } result.Files.Add(child.Name, child.Value.Value <string>()); } } if (json["player"] != null) { result.Player = json["player"].Value <string>(); } return(result); }
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."); } var parameters = new Dictionary <string, string>(); parameters.Add("q", query); if (hdOnly) { parameters.Add("hd", "1"); } parameters.Add("sort", ((int)sort).ToString(CultureInfo.InvariantCulture)); if (adult) { parameters.Add("adult", "1"); } if (count > 0) { parameters.Add("count", count.ToString(CultureInfo.InvariantCulture)); } else { parameters.Add("count", MAX_VIDEO_COUNT.ToString(CultureInfo.InvariantCulture)); } if (offset > 0) { parameters.Add("offset", offset.ToString(CultureInfo.InvariantCulture)); } parameters.Add("access_token", _vkontakte.AccessToken.Token); var response = await VkRequest.GetAsync(VkConst.MethodBase + "video.search", parameters); if (response["response"]?.HasValues == true) { return(from v in response["response"] select VkVideo.FromJson(v)); } return(null); }
internal static VkVideo FromJson(JToken json) { if (json == null) throw new ArgumentException("Json can not be null."); var result = new VkVideo(); if (json["id"] != null) result.Id = json["id"].Value<long>(); if (json["vid"] != null) result.Id = json["vid"].Value<long>(); result.OwnerId = json["owner_id"].Value<long>(); result.Duration = TimeSpan.FromSeconds(json["duration"].Value<double>()); if (json["link"] != null) result.Link = json["link"].Value<string>(); result.Title = WebUtility.HtmlDecode(json["title"].Value<string>()); result.Description = WebUtility.HtmlDecode(json["description"].Value<string>()); if (json["thumb"] != null) result.ImageSmall = json["thumb"].Value<string>(); if (json["image_medium"] != null) result.ImageMedium = json["image_medium"].Value<string>(); if (json["files"] != null) { result.Files = new Dictionary<string, string>(); foreach (JProperty child in json["files"].Children()) { if (!child.HasValues) continue; result.Files.Add(child.Name, child.Value.Value<string>()); } } return result; }
public async Task <IEnumerable <VkVideo> > Get(IList <string> videos, string uid = null, string gid = null, string aid = null, int previewWidth = 0, int count = 0, int offset = 0) { if (_vkontakte.AccessToken == null || string.IsNullOrEmpty(_vkontakte.AccessToken.Token) || _vkontakte.AccessToken.HasExpired) { throw new Exception("Access token is not valid."); } if (count > 200) { throw new ArgumentException("Maximum count is 200."); } var parameters = new Dictionary <string, string>(); if (videos != null) { parameters.Add("videos", string.Join(",", videos)); } if (!string.IsNullOrEmpty(uid)) { parameters.Add("uid", uid); } if (!string.IsNullOrEmpty(gid)) { parameters.Add("gid", gid); } if (!string.IsNullOrEmpty(aid)) { parameters.Add("aid", aid); } if (previewWidth > 0) { parameters.Add("width", previewWidth.ToString(CultureInfo.InvariantCulture)); } if (count > 0) { parameters.Add("count", count.ToString(CultureInfo.InvariantCulture)); } else { parameters.Add("count", MAX_VIDEO_COUNT.ToString(CultureInfo.InvariantCulture)); } if (offset > 0) { parameters.Add("offset", offset.ToString(CultureInfo.InvariantCulture)); } parameters.Add("access_token", _vkontakte.AccessToken.Token); var response = await new VkRequest(new Uri(VkConst.MethodBase + "video.get"), parameters).Execute(); if (VkErrorProcessor.ProcessError(response)) { return(null); } if (response["response"].HasValues) { return(from v in response["response"] where v.HasValues select VkVideo.FromJson(v)); } return(null); }