Example #1
0
 private void PublishVideoDeletedEvent(Database.NicoVideo deletedVideo)
 {
     if (deletedVideo.IsDeleted)
     {
         EventAggregator.GetEvent <VideoDeletedEvent>().Publish(deletedVideo);
     }
 }
Example #2
0
        protected override async Task NavigatedToAsync(CancellationToken cancelToken, NavigatedToEventArgs e, Dictionary <string, object> viewModelState)
        {
            NowLoading.Value = true;

            if (e.Parameter is string)
            {
                VideoId = e.Parameter as string;
            }

            if (VideoId == null)
            {
                IsLoadFailed.Value = true;
                throw new Exception();
            }

            VideoPageUri = new Uri("http://nicovideo.jp/watch/" + VideoId);
            RaisePropertyChanged(nameof(VideoPageUri));

            Playlists = HohoemaApp.Playlist.Playlists.ToList();

            try
            {
                _VideoInfo = await HohoemaApp.ContentProvider.GetNicoVideoInfo(VideoId);
            }
            catch
            {
                IsLoadFailed.Value = true;

                // サムネ情報取得に失敗

                // 動画情報ページ自体はアクセスできる可能性があるため処理を継続
            }


            try
            {
                await Update();
            }
            catch
            {
                IsLoadFailed.Value = true;
            }

            try
            {
                var ichiba = await HohoemaApp.NiconicoContext.Embed.GetIchiba(VideoId);

                IchibaItems = ichiba.GetMainIchibaItems();
                if (IchibaItems.Count > 0)
                {
                    RaisePropertyChanged(nameof(IchibaItems));
                }
            }
            catch
            {
                Debug.WriteLine(VideoId + " の市場情報の取得に失敗");
            }

            NowLoading.Value = false;
        }
Example #3
0
 public CacheVideoViewModel(
     Database.NicoVideo data,
     Interfaces.IMylist ownerPlaylist = null
     )
     : base(data, ownerPlaylist)
 {
 }
Example #4
0
 public RankedVideoInfoControlViewModel(
     Database.NicoVideo data,
     Interfaces.IMylist ownerPlaylist = null
     )
     : base(data, ownerPlaylist)
 {
 }
        public VideoInfoControlViewModel(Database.NicoVideo data, Interfaces.IMylist ownerPlaylist = null)

        {
            RawVideoId    = data?.RawVideoId ?? RawVideoId;
            Data          = data;
            OnwerPlaylist = ownerPlaylist;

            NgSettings                     = App.Current.Container.Resolve <NGSettings>();
            CreateMylistCommand            = App.Current.Container.Resolve <CreateMylistCommand>();
            CreateLocalMylistCommand       = App.Current.Container.Resolve <CreateLocalMylistCommand>();
            CreateSubscriptionGroupCommand = App.Current.Container.Resolve <CreateSubscriptionGroupCommand>();
            AddToHiddenUserCommand         = App.Current.Container.Resolve <AddToHiddenUserCommand>();
            AddCacheRequestCommand         = App.Current.Container.Resolve <Commands.Cache.AddCacheRequestCommand>();
            DeleteCacheRequestCommand      = App.Current.Container.Resolve <DeleteCacheRequestCommand>();
            Scheduler             = App.Current.Container.Resolve <IScheduler>();
            HohoemaPlaylist       = App.Current.Container.Resolve <HohoemaPlaylist>();
            ExternalAccessService = App.Current.Container.Resolve <ExternalAccessService>();
            PageManager           = App.Current.Container.Resolve <PageManager>();
            UserMylistManager     = App.Current.Container.Resolve <UserMylistManager>();
            LocalMylistManager    = App.Current.Container.Resolve <LocalMylistManager>();
            SubscriptionManager   = App.Current.Container.Resolve <SubscriptionManager>();
            VideoCacheManager     = App.Current.Container.Resolve <VideoCacheManager>();
            NicoVideoProvider     = App.Current.Container.Resolve <NicoVideoProvider>();

            _CompositeDisposable = new CompositeDisposable();

            VideoCacheManager.VideoCacheStateChanged += VideoCacheManager_VideoCacheStateChanged;

            if (Data != null)
            {
                SetupFromThumbnail(Data);
            }
        }
Example #6
0
 public static string MakeShareText(Database.NicoVideo video)
 {
     if (!string.IsNullOrEmpty(video.VideoId))
     {
         return(MakeShareText(video.VideoId, video.Title));
     }
     else
     {
         return(MakeShareText(video.RawVideoId, video.Title));
     }
 }
        public VideoInfoControlViewModel(Database.NicoVideo nicoVideo, bool isNgEnabled = true, PlaylistItem playlistItem = null, bool requireLatest = true, IScheduler eventScheduler = null)
        {
            RawVideoId           = nicoVideo.RawVideoId;
            PlaylistItem         = playlistItem;
            _CompositeDisposable = new CompositeDisposable();

            _IsNGEnabled    = isNgEnabled;
            _EventShceduler = eventScheduler;

            _IsRequireLatest = requireLatest;

            OnDeferredUpdate().ConfigureAwait(false);
        }
        public VideoInfoControlViewModel(Database.NicoVideo data)
        {
            VideoCacheManager = App.Current.Container.Resolve <VideoCacheManager>();
            NicoVideoProvider = App.Current.Container.Resolve <NicoVideoProvider>();
            NgSettings        = App.Current.Container.Resolve <NGSettings>();

            RawVideoId = data?.RawVideoId ?? RawVideoId;
            Data       = data;

            if (Data != null)
            {
                SetupFromThumbnail(Data);
            }
        }
        protected override async Task OnDeferredUpdate()
        {
            // Note: 動画リストの一覧表示が終わってからサムネイル情報読み込みが掛かるようにする
            using (var releaser = await _DefferedUpdateLock.LockAsync())
            {
                if (IsDisposed)
                {
                    Debug.WriteLine("skip thumbnail loading: " + RawVideoId);
                    return;
                }

                Database.NicoVideo info = null;
                if (_IsRequireLatest)
                {
                    var contentProvider = App.Current.Container.Resolve <NiconicoContentProvider>();
                    info = await contentProvider.GetNicoVideoInfo(RawVideoId);
                }

                // オフライン時はDBの情報を利用する
                if (info == null)
                {
                    info = Database.NicoVideoDb.Get(RawVideoId);
                }

                if (_EventShceduler != null)
                {
                    _EventShceduler.Schedule(async() =>
                    {
                        SetupFromThumbnail(info);

                        await RefrechCacheState();
                    });
                }
                else
                {
                    await HohoemaApp.UIDispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
                    {
                        SetupFromThumbnail(info);

                        await RefrechCacheState();
                    });
                }
            }
        }
Example #10
0
        public NGResult IsNgVideo(Database.NicoVideo info)
        {
            NGResult result = null;

            if (info.Owner != null)
            {
                result = IsNgVideoOwnerId(info.Owner.OwnerId);
                if (result != null)
                {
                    return(result);
                }
            }

            result = IsNGVideoTitle(info.Title);
            if (result != null)
            {
                return(result);
            }

            return(result);
        }
Example #11
0
        protected override async Task NavigatedToAsync(CancellationToken cancelToken, NavigatedToEventArgs e, Dictionary <string, object> viewModelState)
        {
            try
            {
                _VideoInfo = await NicoVideoProvider.GetNicoVideoInfo(VideoId);

                await UpdateVideoDescription();

                UpdateSelfZoning();

                OpenOwnerUserPageCommand.RaiseCanExecuteChanged();
                OpenOwnerUserVideoPageCommand.RaiseCanExecuteChanged();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }
            finally
            {
                NowLoading.Value = false;
            }
        }
Example #12
0
        public async Task UpdateAsync(Interfaces.IVideoContentWritable video)
        {
            if (NiconicoSession.ServiceStatus.IsOutOfService())
            {
                return;
            }

            if (string.IsNullOrEmpty(video?.Id))
            {
                return;
            }

            Database.NicoVideo info = await _nicoVideoProvider.GetNicoVideoInfo(video.Id);

            if (info == null)
            {
                return;
            }

            _scheduler.Schedule(() =>
            {
                video.Label        = info.Title;
                video.ViewCount    = (int)info.ViewCount;
                video.MylistCount  = (int)info.MylistCount;
                video.CommentCount = (int)info.CommentCount;
                video.Length       = info.Length;
                video.Description  = info.Description;
                video.IsDeleted    = info.IsDeleted;
                video.ThumbnailUrl = info.ThumbnailUrl;
                video.PostedAt     = info.PostedAt;
                if (info.Owner != null)
                {
                    video.ProviderId   = info.Owner.OwnerId;
                    video.ProviderType = info.Owner.UserType;
                }
            });
        }
Example #13
0
        public async Task OnNavigatedToAsync(INavigationParameters parameters)
        {
            NowLoading.Value   = true;
            IsLoadFailed.Value = false;

            try
            {
                if (parameters.TryGetValue("id", out string videoId))
                {
                    VideoId = videoId;

                    if (VideoId == null)
                    {
                        IsLoadFailed.Value = true;
                        throw new Exception();
                    }

                    _VideoInfo = await NicoVideoProvider.GetNicoVideoInfo(VideoId);

                    await UpdateVideoDescription();

                    UpdateSelfZoning();

                    OpenOwnerUserPageCommand.RaiseCanExecuteChanged();
                    OpenOwnerUserVideoPageCommand.RaiseCanExecuteChanged();
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }
            finally
            {
                NowLoading.Value = false;
            }
        }
Example #14
0
 public RecommendVideoListItem(Database.NicoVideo nicoVideo, Mntone.Nico2.Videos.Recommend.Item recommendItem)
     : base(nicoVideo, isNgEnabled: true, playlistItem: null, requireLatest: true)
 {
     _Item = recommendItem;
     RecommendSourceTag = _Item.AdditionalInfo?.Sherlock.Tag;
 }
 public FeedVideoInfoControlViewModel(Database.NicoVideo nicoVideo, Database.Bookmark sourceBookmark)
     : base(nicoVideo)
 {
     SourceBookmark = sourceBookmark;
 }
Example #16
0
 static public void CopyToClipboard(Database.NicoVideo video)
 {
     CopyToClipboard(Helpers.ShareHelper.MakeShareText(video));
 }
Example #17
0
        private ToastNotification MakeSuccessToastNotification(Database.NicoVideo info)
        {
            // トーストのレイアウトを作成
            ToastContent content = new ToastContent()
            {
                Launch = "niconico://" + info.RawVideoId,

                Visual = new ToastVisual()
                {
                    BindingGeneric = new ToastBindingGeneric()
                    {
                        Children =
                        {
                            new AdaptiveText()
                            {
                                Text = info.Title,
                            },

                            new AdaptiveText()
                            {
                                Text      = "キャッシュ完了",
                                HintStyle = AdaptiveTextStyle.CaptionSubtle
                            },

                            new AdaptiveText()
                            {
                                Text      = "ここをタップして再生を開始",
                                HintStyle = AdaptiveTextStyle.CaptionSubtle
                            }
                        },

                        /*
                         * AppLogoOverride = new ToastGenericAppLogo()
                         * {
                         *  Source = "oneAlarm.png"
                         * }
                         */
                    }
                },

                /*
                 * Actions = new ToastActionsCustom()
                 * {
                 *  Buttons =
                 *  {
                 *      new ToastButton("check", "check")
                 *      {
                 *          ImageUri = "check.png"
                 *      },
                 *
                 *      new ToastButton("cancel", "cancel")
                 *      {
                 *          ImageUri = "cancel.png"
                 *      }
                 *  }
                 * },
                 */
                /*
                 * Audio = new ToastAudio()
                 * {
                 *  Src = new Uri("ms-winsoundevent:Notification.Reminder")
                 * }
                 */
            };

            // トースト表示を実行
            return(new ToastNotification(content.GetXml()));
        }
Example #18
0
 public static void CopyToClipboard(Database.NicoVideo video)
 {
     CopyToClipboard(MakeShareText(video));
 }
Example #19
0
        private ToastNotification MakeFailureToastNotification(Database.NicoVideo info)
        {
            // トーストのレイアウトを作成
            ToastContent content = new ToastContent()
            {
                Visual = new ToastVisual()
                {
                    BindingGeneric = new ToastBindingGeneric()
                    {
                        Children =
                        {
                            new AdaptiveText()
                            {
                                Text = info.Title,
                            },

                            new AdaptiveText()
                            {
                                Text      = "キャッシュに失敗(またはキャンセル)",
                                HintStyle = AdaptiveTextStyle.CaptionSubtle
                            },

                            /*
                             * new AdaptiveText()
                             * {
                             *  Text = "再ダウンロード",
                             *  HintStyle = AdaptiveTextStyle.CaptionSubtle
                             * }
                             */
                        },

                        /*
                         * AppLogoOverride = new ToastGenericAppLogo()
                         * {
                         *  Source = "oneAlarm.png"
                         * }
                         */
                    }
                },

                /*
                 * Actions = new ToastActionsCustom()
                 * {
                 *  Buttons =
                 *  {
                 *      new ToastButton("check", "check")
                 *      {
                 *          ImageUri = "check.png"
                 *      },
                 *
                 *      new ToastButton("cancel", "cancel")
                 *      {
                 *          ImageUri = "cancel.png"
                 *      }
                 *  }
                 * },
                 */
                /*
                 * Audio = new ToastAudio()
                 * {
                 *  Src = new Uri("ms-winsoundevent:Notification.Reminder")
                 * }
                 */
            };

            // トースト表示を実行

            return(new ToastNotification(content.GetXml()));
        }
Example #20
0
        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.");
                }
            }
        }
        public void SetupFromThumbnail(Database.NicoVideo info)
        {
            Debug.WriteLine("thumbnail reflect : " + info.RawVideoId);

            Label = info.Title;

            // NG判定
            if (_IsNGEnabled)
            {
                var hohoemaApp = App.Current.Container.Resolve <HohoemaApp>();

                NGResult ngResult = null;

                // タイトルをチェック
                if (!_isTitleNgCheckProcessed && !string.IsNullOrEmpty(info.Title))
                {
                    ngResult = hohoemaApp.UserSettings.NGSettings.IsNGVideoTitle(info.Title);
                    _isTitleNgCheckProcessed = true;
                }

                // 投稿者IDをチェック
                if (ngResult == null &&
                    !_isOwnerIdNgCheckProcessed &&
                    !string.IsNullOrEmpty(info.Owner?.OwnerId)
                    )
                {
                    ngResult = hohoemaApp.UserSettings.NGSettings.IsNgVideoOwnerId(info.Owner.OwnerId);
                    _isOwnerIdNgCheckProcessed = true;
                }

                if (ngResult != null)
                {
                    IsVisible = false;
                    var ngDesc = !string.IsNullOrWhiteSpace(ngResult.NGDescription) ? ngResult.NGDescription : ngResult.Content;
                    InvisibleDescription = $"NG動画";
                }
            }

            SetTitle(info.Title);
            SetThumbnailImage(info.ThumbnailUrl);
            SetSubmitDate(info.PostedAt);
            SetVideoDuration(info.Length);
            if (!info.IsDeleted)
            {
                SetDescription(info.ViewCount, info.CommentCount, info.MylistCount);
            }
            else
            {
                if (info.PrivateReasonType != PrivateReasonType.None)
                {
                    Description = info.PrivateReasonType.ToCulturelizeString();
                }
                else
                {
                    Description = "視聴不可(配信終了など)";
                }
            }

            if (info.Owner != null)
            {
                OwnerUserId   = info.Owner.OwnerId;
                OwnerUserName = info.Owner.ScreenName;
                OwnerUserType = info.Owner.UserType;
            }
        }
Example #22
0
 public CacheVideoViewModel(
     Database.NicoVideo data
     )
     : base(data)
 {
 }
Example #23
0
        private async Task <Database.NicoVideo> GetLatestInfo(string videoId)
        {
            var res = await ContextActionAsync(async context =>
            {
                return(await context.Search.GetVideoInfoAsync(videoId));
            });

            if (res.Status == "ok")
            {
                var video = res.Video;

                var info = new Database.NicoVideo()
                {
                    RawVideoId   = videoId,
                    Title        = video.Title,
                    VideoId      = video.Id,
                    Length       = video.Length,
                    PostedAt     = video.UploadTime,
                    IsDeleted    = video.IsDeleted,
                    Description  = video.Description,
                    ViewCount    = (int)video.ViewCount,
                    CommentCount = (int)res.Thread.GetCommentCount(),
                    MylistCount  = (int)video.MylistCount,
                    ThreadId     = video.DefaultThread,
                    ThumbnailUrl = video.ThumbnailUrl.OriginalString,
                    Tags         = res.Tags.TagInfo.Select(x => new NicoVideoTag()
                    {
                        Id = x.Tag,
                    }
                                                           ).ToList()
                };

                if (res.Video.ProviderType == "channel")
                {
                    info.Owner = new NicoVideoOwner()
                    {
                        OwnerId  = res.Video.CommunityId,
                        UserType = Database.NicoVideoUserType.Channel
                    };
                }
                else
                {
                    info.Owner = new NicoVideoOwner()
                    {
                        OwnerId  = res.Video.UserId,
                        UserType = res.Video.ProviderType == "regular" ? NicoVideoUserType.User : NicoVideoUserType.Channel
                    };
                }

                info.IsDeleted = res.Video.IsDeleted;
                if (info.IsDeleted && int.TryParse(res.Video.__deleted, out int deleteType))
                {
                    try
                    {
                        info.PrivateReasonType = (PrivateReasonType)deleteType;
                    }
                    catch { }
                }

                return(info);
            }

            throw new Exception();
        }
Example #24
0
 public ChannelVideoListItemViewModel(
     Database.NicoVideo data
     )
     : base(data)
 {
 }
Example #25
0
 public static async Task ShareToTwitter(Database.NicoVideo video)
 {
     await ShareToTwitter(MakeShareText(video));
 }
Example #26
0
        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.");
                }
            }
        }
Example #27
0
 public static void Share(Database.NicoVideo video)
 {
     Share(MakeShareText(video));
 }
Example #28
0
        /// <summary>
        /// ニコニコ動画コンテンツの情報を取得します。
        /// 内部DB、サムネイル、Watchページのアクセス情報から更新されたデータを提供します。
        ///
        /// </summary>
        /// <param name="rawVideoId"></param>
        /// <returns></returns>
        public async Task <Database.NicoVideo> GetNicoVideoInfo(string rawVideoId, bool requireLatest = false)
        {
            if (NiconicoSession.ServiceStatus.IsOutOfService())
            {
                return(null);
            }

            using (await _ThumbnailAccessLock.LockAsync())
            {
                var info = NicoVideoDb.Get(rawVideoId);

                // 最新情報が不要な場合は内部DBのキャッシュをそのまま返す
                if (info != null && !requireLatest)
                {
                    if (info.ViewCount != 0 &&
                        info.LastUpdated > DateTime.Now - ThumbnailExpirationSpan)
                    {
                        return(info);
                    }
                }

                if (info == null)
                {
                    info = new Database.NicoVideo()
                    {
                        RawVideoId = rawVideoId
                    };
                }

                try
                {
                    var res = await ContextActionAsync(async context =>
                    {
                        return(await context.Search.GetVideoInfoAsync(rawVideoId));
                    });

                    if (res.Status == "ok")
                    {
                        var video = res.Video;

                        info.Title        = video.Title;
                        info.VideoId      = video.Id;
                        info.Length       = video.Length;
                        info.PostedAt     = video.FirstRetrieve;
                        info.ThumbnailUrl = video.ThumbnailUrl.OriginalString;

                        info.ViewCount    = (int)video.ViewCount;
                        info.MylistCount  = (int)video.MylistCount;
                        info.CommentCount = (int)res.Thread.GetCommentCount();
                        info.Tags         = res.Tags.TagInfo.Select(x => new NicoVideoTag()
                        {
                            Id = x.Tag,
                        }
                                                                    ).ToList();

                        if (res.Video.ProviderType == "channel")
                        {
                            info.Owner = new NicoVideoOwner()
                            {
                                OwnerId  = res.Video.CommunityId,
                                UserType = UserType.Channel
                            };
                        }
                        else
                        {
                            info.Owner = new NicoVideoOwner()
                            {
                                OwnerId  = res.Video.UserId,
                                UserType = res.Video.ProviderType == "regular" ? UserType.User : UserType.Channel
                            };
                        }

                        info.IsDeleted = res.Video.IsDeleted;
                        if (info.IsDeleted && int.TryParse(res.Video.__deleted, out int deleteType))
                        {
                            try
                            {
                                info.PrivateReasonType = (PrivateReasonType)deleteType;
                            }
                            catch { }
                        }
                    }
                    else
                    {
                        info.IsDeleted = true;
                    }
                }

                catch (Exception ex) when(ex.Message.Contains("DELETE") || ex.Message.Contains("NOT_FOUND"))
                {
                    info.IsDeleted = true;
                }
                finally
                {
                    NicoVideoDb.AddOrUpdate(info);
                    if (info.Owner != null)
                    {
                        NicoVideoOwnerDb.AddOrUpdate(info.Owner);
                    }
                }

                if (info.IsDeleted)
                {
                    PublishVideoDeletedEvent(info);
                }


                await Task.Delay(25);

                return(info);
            }
        }
Example #29
0
        /// <summary>
        /// ニコニコ動画コンテンツの情報を取得します。
        /// 内部DB、サムネイル、Watchページのアクセス情報から更新されたデータを提供します。
        ///
        /// </summary>
        /// <param name="rawVideoId"></param>
        /// <returns></returns>
        public async Task <Database.NicoVideo> GetNicoVideoInfo(string rawVideoId, bool requireLatest = false)
        {
            if (Context == null)
            {
                return(null);
            }

            using (var releaser = await _ThumbnailAccessLock.LockAsync())
            {
                var info = NicoVideoDb.Get(rawVideoId);

                // 最新情報が不要な場合は内部DBのキャッシュをそのまま返す
                if (info != null && !requireLatest)
                {
                    if (info.LastUpdated > DateTime.Now - ThumbnailExpirationSpan)
                    {
                        return(info);
                    }
                }

                if (info == null)
                {
                    info = new Database.NicoVideo()
                    {
                        RawVideoId = rawVideoId
                    };
                }

                try
                {
                    var res = await Helpers.ConnectionRetryUtil.TaskWithRetry(() =>
                    {
                        return(Context.Search.GetVideoInfoAsync(rawVideoId));
                    },
                                                                              retryCount : 5,
                                                                              retryInterval : 1000
                                                                              );

                    if (res.Status == "ok")
                    {
                        var video = res.Video;

                        info.Title        = video.Title;
                        info.VideoId      = video.Id;
                        info.Length       = video.Length;
                        info.PostedAt     = video.FirstRetrieve;
                        info.ThumbnailUrl = video.ThumbnailUrl.OriginalString;

                        info.ViewCount    = (int)video.ViewCount;
                        info.MylistCount  = (int)video.MylistCount;
                        info.CommentCount = (int)res.Thread.GetCommentCount();
                        info.Tags         = res.Tags.TagInfo.Select(x => new NicoVideoTag()
                        {
                            Id = x.Tag,
                        }
                                                                    ).ToList();

                        if (res.Video.ProviderType == "channel")
                        {
                            info.Owner = new NicoVideoOwner()
                            {
                                OwnerId  = res.Video.CommunityId,
                                UserType = UserType.Channel
                            };
                        }
                        else
                        {
                            info.Owner = new NicoVideoOwner()
                            {
                                OwnerId  = res.Video.UserId,
                                UserType = res.Video.ProviderType == "regular" ? UserType.User : UserType.Channel
                            };
                        }

                        info.IsDeleted = res.Video.IsDeleted;
                        if (info.IsDeleted && int.TryParse(res.Video.__deleted, out int deleteType))
                        {
                            try
                            {
                                info.PrivateReasonType = (PrivateReasonType)deleteType;
                            }
                            catch { }
                        }
                    }
                    else
                    {
                        info.IsDeleted = true;
                    }
                }

                catch (Exception ex) when(ex.Message.Contains("DELETE") || ex.Message.Contains("NOT_FOUND"))
                {
                    info.IsDeleted = true;
                }
                finally
                {
                    NicoVideoDb.AddOrUpdate(info);
                    if (info.Owner != null)
                    {
                        NicoVideoOwnerDb.AddOrUpdate(info.Owner);
                    }
                }

                if (info.IsDeleted)
                {
                    var cacheManager = App.Current.Container.Resolve <VideoCacheManager>();
                    await cacheManager.VideoDeletedFromNiconicoServer(info.RawVideoId).ConfigureAwait(false);
                }

                return(info);
            }
        }