private async Task <InAppNotificationPayload> SubmitVideoContentSuggestion(string videoId)
        {
            var nicoVideo = await NicoVideoProvider.GetNicoVideoInfo(videoId);

            if (nicoVideo.IsDeleted || string.IsNullOrEmpty(nicoVideo.Title))
            {
                return(null);
            }

            return(new InAppNotificationPayload()
            {
                Content = $"{nicoVideo.Title} をお探しですか?",
                ShowDuration = DefaultNotificationShowDuration,
                SymbolIcon = Symbol.Video,
                IsShowDismissButton = true,
                Commands =
                {
                    new InAppNotificationCommand()
                    {
                        Label = "再生",
                        Command = new DelegateCommand(() =>
                        {
                            Playlist.PlayVideo(nicoVideo.RawVideoId, nicoVideo.Title);

                            NotificationService.DismissInAppNotification();
                        })
                    },
                    new InAppNotificationCommand()
                    {
                        Label = "あとで見る",
                        Command = new DelegateCommand(() =>
                        {
                            Playlist.DefaultPlaylist.AddMylistItem(nicoVideo.RawVideoId);

                            NotificationService.DismissInAppNotification();
                        })
                    },
                    new InAppNotificationCommand()
                    {
                        Label = "動画情報を開く",
                        Command = new DelegateCommand(() =>
                        {
                            PageManager.OpenPageWithId(HohoemaPageType.VideoInfomation, videoId);

                            NotificationService.DismissInAppNotification();
                        })
                    },
                }
            });
        }
Exemple #2
0
        private async Task <InAppNotificationPayload> SubmitVideoContentSuggestion(string videoId)
        {
            var nicoVideo = await NicoVideoProvider.GetNicoVideoInfo(videoId);

            if (nicoVideo.IsDeleted || string.IsNullOrEmpty(nicoVideo.Title))
            {
                return(null);
            }

            return(new InAppNotificationPayload()
            {
                Content = "InAppNotification_ContentDetectedFromClipboard".Translate(nicoVideo.Title),
                ShowDuration = DefaultNotificationShowDuration,
                SymbolIcon = Symbol.Video,
                IsShowDismissButton = true,
                Commands =
                {
                    new InAppNotificationCommand()
                    {
                        Label = "Play".Translate(),
                        Command = new DelegateCommand(() =>
                        {
                            Playlist.Play(nicoVideo);

                            NotificationService.DismissInAppNotification();
                        })
                    },
                    new InAppNotificationCommand()
                    {
                        Label = "@view".Translate(),
                        Command = new DelegateCommand(() =>
                        {
                            Playlist.AddWatchAfterPlaylist(nicoVideo);

                            NotificationService.DismissInAppNotification();
                        })
                    },
                    new InAppNotificationCommand()
                    {
                        Label = HohoemaPageType.VideoInfomation.Translate(),
                        Command = new DelegateCommand(() =>
                        {
                            PageManager.OpenPageWithId(HohoemaPageType.VideoInfomation, videoId);

                            NotificationService.DismissInAppNotification();
                        })
                    },
                }
            });
        }
        async Task Views.Extensions.ListViewBase.IDeferInitialize.DeferInitializeAsync()
        {
            if (Data?.Title != null)
            {
                SetTitle(Data.Title);
            }

            _ = RefrechCacheState();

            var data = await Task.Run(async() =>
            {
                if (IsDisposed)
                {
                    Debug.WriteLine("skip thumbnail loading: " + RawVideoId);
                    return(null);
                }

                if (NicoVideoProvider != null)
                {
                    return(await NicoVideoProvider.GetNicoVideoInfo(RawVideoId));
                }

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

                return(null);
            });

            if (data == null)
            {
                return;
            }

            Data = data;

            if (IsDisposed)
            {
                Debug.WriteLine("skip thumbnail loading: " + RawVideoId);
                return;
            }

            SetupFromThumbnail(Data);
        }
Exemple #4
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;
            }
        }
Exemple #5
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;
                }
            });
        }
Exemple #6
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;
            }
        }
Exemple #7
0
        public async Task <VideoRelatedContents> GetRelatedContentsAsync(string videoId)
        {
            if (_cachedVideoRelatedContents?.ContentId == videoId)
            {
                return(_cachedVideoRelatedContents);
            }

            var videoInfo           = Database.NicoVideoDb.Get(videoId);
            var videoViewerHelpInfo = NicoVideoSessionProvider.GetVideoRelatedInfomationWithVideoDescription(videoId);

            VideoRelatedContents result = new VideoRelatedContents(videoId);
            // ニコスクリプトで指定されたジャンプ先動画

            /*
             * if (JumpVideoId != null)
             * {
             *  var video = await NicoVideoProvider.GetNicoVideoInfo(JumpVideoId, requireLatest: true);
             *  if (video != null)
             *  {
             *      JumpVideo = new VideoInfoControlViewModel(video);
             *      RaisePropertyChanged(nameof(JumpVideo));
             *  }
             * }
             */

            // 再生中アイテムのタイトルと投稿者説明文に含まれる動画IDの動画タイトルを比較して
            // タイトル文字列が近似する動画をシリーズ動画として取り込む
            // 違うっぽい動画も投稿者が提示したい動画として確保
            var videoIds = videoViewerHelpInfo.GetVideoIds();
            List <Database.NicoVideo> seriesVideos = new List <Database.NicoVideo>();

            seriesVideos.Add(videoInfo);
            foreach (var id in videoIds)
            {
                var video = await NicoVideoProvider.GetNicoVideoInfo(id, requireLatest : true);

                var titleSimilarity = videoInfo.Title.CalculateSimilarity(video.Title);
                if (titleSimilarity > _SeriesVideosTitleSimilarityValue)
                {
                    seriesVideos.Add(video);
                }
                else
                {
                    var otherVideo = new VideoInfoControlViewModel(video);
                    result.OtherVideos.Add(otherVideo);
                }
            }


            // シリーズ動画として集めたアイテムを投稿日が新しいものが最後尾になるよう並び替え
            // シリーズ動画に番兵として仕込んだ現在再生中のアイテムの位置と動画数を比べて
            // 動画数が上回っていた場合は次動画が最後尾にあると決め打ちで取得する
            var orderedSeriesVideos = seriesVideos.OrderBy(x => x.PostedAt).ToList();
            var currentVideoIndex   = orderedSeriesVideos.IndexOf(videoInfo);

            if (orderedSeriesVideos.Count - 1 > currentVideoIndex)
            {
                var nextVideo = orderedSeriesVideos.Last();
                if (nextVideo.RawVideoId != videoId)
                {
                    result.NextVideo = new VideoInfoControlViewModel(nextVideo);

                    orderedSeriesVideos.Remove(nextVideo);
                }
            }

            // 次動画を除いてシリーズ動画っぽいアイテムを投稿者が提示したい動画として優先表示されるようにする
            orderedSeriesVideos.Remove(videoInfo);
            orderedSeriesVideos.Reverse();
            foreach (var video in orderedSeriesVideos)
            {
                var videoVM = new VideoInfoControlViewModel(video);
                result.OtherVideos.Insert(0, videoVM);
            }


            // チャンネル動画で次動画が見つからなかった場合は
            // チャンネル動画一覧から次動画をサジェストする
            if (videoInfo.Owner.UserType == NicoVideoUserType.Channel &&
                result.NextVideo == null
                )
            {
                // DBからチャンネル情報を取得
                var db_channelInfo = Database.NicoChannelInfoDb.GetFromRawId(videoInfo.Owner.OwnerId);
                if (db_channelInfo == null)
                {
                    db_channelInfo = new Database.NicoChannelInfo()
                    {
                        RawId        = videoInfo.Owner.OwnerId,
                        ThumbnailUrl = videoInfo.Owner.IconUrl,
                        Name         = videoInfo.Owner.ScreenName
                    };
                }

                // チャンネル動画の一覧を取得する
                // ページアクセスが必要なので先頭ページを取って
                // 全体の分量を把握してから全ページ取得を行う
                List <ChannelVideoInfo> channelVideos = new List <ChannelVideoInfo>();
                var channelVideosFirstPage            = await ChannelProvider.GetChannelVideo(videoInfo.Owner.OwnerId, 0);

                var uncheckedCount = channelVideosFirstPage.TotalCount - channelVideosFirstPage.Videos.Count;
                if (channelVideosFirstPage.TotalCount != 0)
                {
                    channelVideos.AddRange(channelVideosFirstPage.Videos);

                    var uncheckedPageCount = (int)Math.Ceiling((double)uncheckedCount / 20); /* チャンネル動画1ページ = 20 動画 */
                    foreach (var page in Enumerable.Range(1, uncheckedPageCount))
                    {
                        var channelVideoInfo = await ChannelProvider.GetChannelVideo(videoInfo.Owner.OwnerId, page);

                        channelVideos.AddRange(channelVideoInfo.Videos);
                    }

                    db_channelInfo.Videos = channelVideos;
                }

                Database.NicoChannelInfoDb.AddOrUpdate(db_channelInfo);


                var collectionView = new AdvancedCollectionView(db_channelInfo.Videos);
                collectionView.SortDescriptions.Add(new SortDescription(nameof(ChannelVideoInfo.PostedAt), SortDirection.Ascending));
                collectionView.SortDescriptions.Add(new SortDescription(nameof(ChannelVideoInfo.ItemId), SortDirection.Ascending));
                collectionView.RefreshSorting();

                var item = collectionView.FirstOrDefault(x => (x as ChannelVideoInfo).Title == videoInfo.Title);
                var pos  = collectionView.IndexOf(item);
                if (pos >= 0)
                {
                    var nextVideo = collectionView.ElementAtOrDefault(pos + 1) as ChannelVideoInfo;
                    if (nextVideo != null)
                    {
                        var videoVM = new ChannelVideoListItemViewModel(nextVideo.ItemId);
                        videoVM.IsRequirePayment = nextVideo.IsRequirePayment;
                        videoVM.SetTitle(nextVideo.Title);
                        videoVM.SetSubmitDate(nextVideo.PostedAt);
                        videoVM.SetThumbnailImage(nextVideo.ThumbnailUrl);
                        videoVM.SetVideoDuration(nextVideo.Length);
                        videoVM.SetDescription(nextVideo.ViewCount, nextVideo.CommentCount, nextVideo.MylistCount);

                        result.NextVideo = videoVM;
                    }
                }
            }

            // マイリスト
            var relatedMylistIds = videoViewerHelpInfo.GetMylistIds();

            foreach (var mylistId in relatedMylistIds)
            {
                var mylist = await _mylistRepository.GetMylist(mylistId);

                if (mylist != null)
                {
                    result.Mylists.Add(mylist);
                }
            }


            /*
             * var videos = await Video.GetRelatedVideos(videoId);
             * Videos = videos.Select(x =>
             * {
             *  var vm = new VideoInfoControlViewModel(x);
             *  return vm;
             * })
             * .ToList();
             */

            result.CurrentVideo = result.Videos.FirstOrDefault(x => x.RawVideoId == videoId);

            _cachedVideoRelatedContents = result;

            return(result);
        }