public async Task <DmcWatchResponse> GetDmcWatchResponse(string rawVideoId, HarmfulContentReactionType harmfulContentReaction = HarmfulContentReactionType.None) { if (_HohoemaApp.NiconicoContext == null) { return(null); } if (!_HohoemaApp.IsLoggedIn) { return(null); } await WaitNicoPageAccess(); using (var releaser = await _NicoPageAccessLock.LockAsync()) { var res = await Util.ConnectionRetryUtil.TaskWithRetry(() => { return(_HohoemaApp.NiconicoContext.Video.GetDmcWatchResponseAsync( rawVideoId , harmfulReactType: harmfulContentReaction )); }); if (res != null && res.Owner != null) { var uploaderInfo = res.Owner; await UserInfoDb.AddOrReplaceAsync(uploaderInfo.Id, uploaderInfo.Nickname, uploaderInfo.IconURL); } if (res != null) { var data = await VideoInfoDb.GetEnsureNicoVideoInfoAsync(rawVideoId); if (data != null) { await VideoInfoDb.UpdateNicoVideoInfo(data, res); } } return(res); } }
public async Task <WatchApiResponse> GetWatchApiResponse(string rawVideoId, bool forceLowQuality = false) { if (NiconicoSession.ServiceStatus.IsOutOfService()) { return(null); } if (!NiconicoSession.IsLoggedIn) { return(null); } // TODO: 有害動画に指定されたページにアクセスした場合の対応 HarmfulContentReactionType harmfulContentReactionType = HarmfulContentReactionType.None; { try { var res = await Helpers.ConnectionRetryUtil.TaskWithRetry(async() => { return(await ContextActionWithPageAccessWaitAsync(async context => { return await context.Video.GetWatchApiAsync( rawVideoId , forceLowQuality: forceLowQuality , harmfulReactType: harmfulContentReactionType ); })); }); var info = NicoVideoDb.Get(rawVideoId); if (info == null) { info = new Database.NicoVideo() { RawVideoId = rawVideoId }; } info.VideoId = res.videoDetail.id; info.Title = res.videoDetail.title; info.Length = res.videoDetail.length.HasValue ? TimeSpan.FromSeconds(res.videoDetail.length.Value) : TimeSpan.Zero; info.PostedAt = DateTime.Parse(res.videoDetail.postedAt); info.ThumbnailUrl = res.videoDetail.thumbnail; info.DescriptionWithHtml = res.videoDetail.description; info.ViewCount = res.videoDetail.viewCount ?? 0; info.MylistCount = res.videoDetail.mylistCount ?? 0; info.CommentCount = res.videoDetail.commentCount ?? 0; switch (res.flashvars.movie_type) { case @"mp4": info.MovieType = MovieType.Mp4; break; case @"flv": info.MovieType = MovieType.Flv; break; case @"swf": info.MovieType = MovieType.Swf; break; } info.Tags = res.videoDetail.tagList.Select(x => new NicoVideoTag() { Name = x.tag, IsCategory = x.cat ?? false, IsLocked = x.lck == "1", /* TODO: lck 値が不明です */ Id = x.id, IsDictionaryExists = x.dic ?? false }).ToList(); info.Owner = new NicoVideoOwner() { ScreenName = res.UploaderInfo?.nickname ?? res.channelInfo?.name, IconUrl = res.UploaderInfo?.icon_url ?? res.channelInfo?.icon_url, OwnerId = res.UploaderInfo?.id ?? res.channelInfo?.id, UserType = res.channelInfo != null ? UserType.Channel : UserType.User }; info.IsDeleted = res.IsDeleted; info.PrivateReasonType = res.PrivateReason; NicoVideoDb.AddOrUpdate(info); // NicoVideoOwnerDb.AddOrUpdate(info.Owner); if (info.IsDeleted) { PublishVideoDeletedEvent(info); } return(res); } catch (AggregateException ea) when(ea.Flatten().InnerExceptions.Any(e => e is ContentZoningException)) { throw new NotImplementedException("not implement hurmful video content."); } catch (ContentZoningException) { throw new NotImplementedException("not implement hurmful video content."); } } }
public async Task <DmcWatchData> GetDmcWatchResponse(string rawVideoId) { if (NiconicoSession.ServiceStatus.IsOutOfService()) { return(null); } // TODO: 有害動画に指定されたページにアクセスした場合の対応 // 有害動画ページにアクセスしたら一度だけ確認ページをダイアログ表示する // (ユーザーのアクションによらず)再度ページを読み込んで、もう一度HurmfulContentが返ってきた場合はnullを返す HarmfulContentReactionType harmfulContentReactionType = HarmfulContentReactionType.None; { try { var data = await Helpers.ConnectionRetryUtil.TaskWithRetry(async() => { return(await ContextActionWithPageAccessWaitAsync(async context => { return await context.Video.GetDmcWatchResponseAsync( rawVideoId , harmfulReactType: harmfulContentReactionType ); })); }); var res = data?.DmcWatchResponse; var info = NicoVideoDb.Get(rawVideoId); if (res != null) { if (info == null) { info = new Database.NicoVideo() { RawVideoId = rawVideoId }; } info.VideoId = res.Video.Id; info.Title = res.Video.Title; info.Length = TimeSpan.FromSeconds(res.Video.Duration); info.PostedAt = DateTime.Parse(res.Video.PostedDateTime); info.ThumbnailUrl = res.Video.ThumbnailURL; info.DescriptionWithHtml = res.Video.Description; info.ViewCount = res.Video.ViewCount; info.MylistCount = res.Video.MylistCount; info.CommentCount = res.Thread.CommentCount; switch (res.Video.MovieType) { case @"mp4": info.MovieType = MovieType.Mp4; break; case @"flv": info.MovieType = MovieType.Flv; break; case @"swf": info.MovieType = MovieType.Swf; break; } info.Tags = res.Tags.Select(x => new NicoVideoTag() { Name = x.Name, IsCategory = x.IsCategory, IsLocked = x.IsLocked, Id = x.Id, IsDictionaryExists = x.IsDictionaryExists }).ToList(); if (res.Owner != null) { info.Owner = new NicoVideoOwner() { ScreenName = res.Owner.Nickname, IconUrl = res.Owner.IconURL, OwnerId = res.Owner.Id, UserType = UserType.User }; NicoVideoOwnerDb.AddOrUpdate(info.Owner); } else if (res.Channel != null) { info.Owner = new NicoVideoOwner() { ScreenName = res.Channel.Name, IconUrl = res.Channel.IconURL, OwnerId = res.Channel.GlobalId, UserType = UserType.Channel }; } if (data.DmcWatchResponse?.Video != null) { info.IsDeleted = data.DmcWatchResponse.Video.IsDeleted; } NicoVideoDb.AddOrUpdate(info); } if (info.IsDeleted) { PublishVideoDeletedEvent(info); } return(data); } catch (AggregateException ea) when(ea.Flatten().InnerExceptions.Any(e => e is ContentZoningException)) { throw new NotImplementedException("not implement hurmful video content."); } catch (Mntone.Nico2.ContentZoningException) { throw new NotImplementedException("not implement hurmful video content."); } } }