///////////////////////////////////////////////////////////////////////////////// // GET /viewingservice/{apiversion}/thumbnails/{urn}? // guid=$GUID$ & width=$WIDTH$ & height=$HEIGHT$ (& type=$TYPE$) // ///////////////////////////////////////////////////////////////////////////////// public async Task <ThumbnailResponse> GetThumbnailAsync( string fileId, int width = 150, int height = 150, string guid = "") { var response = new ThumbnailResponse(); try { RestRequest request = new RestRequest( "viewingservice/v1/thumbnails/" + fileId.ToBase64(), Method.GET); request.AddHeader( "Authorization", "Bearer " + TokenResponse.AccessToken); request.AddParameter("width", width); request.AddParameter("height", height); if (guid != "") { request.AddParameter("guid", guid); } var httpResponse = await _restClient.ExecuteAsync( request); if (httpResponse.StatusCode != System.Net.HttpStatusCode.OK) { if (httpResponse.Content != string.Empty) { response.Error = JsonConvert.DeserializeObject <ViewDataError>( httpResponse.Content); response.Error.StatusCode = httpResponse.StatusCode; } else { response.Error = new ViewDataError( httpResponse.StatusCode); } } else { using (MemoryStream ms = new MemoryStream(httpResponse.RawBytes)) { response.Image = Image.FromStream(ms); } } } catch (Exception ex) { response.Error = new ViewDataError(ex); } return(response); }
public async Task <ThumbnailResponse> GetThumbnailResponse(string rawVideoId) { if (_HohoemaApp.NiconicoContext == null) { return(null); } // using (var releaser = await _ThumbnailAccessLock.LockAsync()) { ThumbnailResponse res = null; res = await Util.ConnectionRetryUtil.TaskWithRetry(() => { return(_HohoemaApp.NiconicoContext.Video.GetThumbnailAsync(rawVideoId)); }, retryCount : 5, retryInterval : 1000 ); if (res != null) { await UserInfoDb.AddOrReplaceAsync(res.UserId.ToString(), res.UserName, res.UserIconUrl.AbsoluteUri); Debug.WriteLine("サムネ取得:" + rawVideoId); } else { Debug.WriteLine("サムネ取得失敗:" + rawVideoId); } return(res); } }
public static async Task UpdateNicoVideoInfo(NicoVideoInfo info, ThumbnailResponse thumbnailRes) { info.VideoId = thumbnailRes.Id; info.HighSize = (uint)thumbnailRes.SizeHigh; info.LowSize = (uint)thumbnailRes.SizeLow; info.Length = thumbnailRes.Length; info.MovieType = thumbnailRes.MovieType; info.PostedAt = thumbnailRes.PostedAt.DateTime; info.UserId = thumbnailRes.UserId; info.UserType = thumbnailRes.UserType; info.Description = thumbnailRes.Description; info.ThumbnailUrl = thumbnailRes.ThumbnailUrl.AbsoluteUri; info.Title = thumbnailRes.Title; info.ViewCount = thumbnailRes.ViewCount; info.MylistCount = thumbnailRes.MylistCount; info.CommentCount = thumbnailRes.CommentCount; info.SetTags(thumbnailRes.Tags.Value.ToList()); await UpdateAsync(info); }
/// <summary> /// Utility function to print response data to the console. /// </summary> /// <param name="response"> /// The ThumbnailResponse to be printed.<see cref="ThumbnailResponse"/> /// </param> public void PrintResponse(ThumbnailResponse response) { PrintResponse(response.Result, response.RequestErrors); if(response.Result.Equals(Result.REQUEST_SUCCESSFUL)) { Console.WriteLine("Account Id: " + response.imageUrl); } }