public override void OnNavigatedFrom(INavigationParameters parameters)
        {
            VideoDescriptionHyperlinkItems?.Clear();
            RaisePropertyChanged(nameof(VideoDescriptionHyperlinkItems));
            IchibaItems?.Clear();
            RaisePropertyChanged(nameof(IchibaItems));

            base.OnNavigatedFrom(parameters);
        }
Ejemplo n.º 2
0
        private async Task UpdateVideoDescription()
        {
            var videoDescriptionHtml = string.Empty;

            using (var releaser = await _UpdateLock.LockAsync())
            {
                if (VideoId == null)
                {
                    return;
                }

                IsLoadFailed.Value = false;

                try
                {
                    var res = await NicoVideo.VisitWatchPage(VideoId);

                    if (res is WatchApiResponse)
                    {
                        var watchApi = res as WatchApiResponse;

                        VideoTitle = watchApi.videoDetail.title;
                        Tags       = watchApi.videoDetail.tagList.Select(x => new TagViewModel(x.tag))
                                     .ToList();
                        ThumbnailUrl        = watchApi.videoDetail.thumbnail;
                        VideoLength         = TimeSpan.FromSeconds(watchApi.videoDetail.length.Value);
                        SubmitDate          = DateTime.Parse(watchApi.videoDetail.postedAt);
                        ViewCount           = (uint)watchApi.videoDetail.viewCount.Value;
                        CommentCount        = (uint)watchApi.videoDetail.commentCount.Value;
                        MylistCount         = (uint)watchApi.videoDetail.mylistCount.Value;
                        ProviderName        = watchApi.UserName;
                        OwnerIconUrl        = watchApi.UploaderInfo?.icon_url ?? watchApi.channelInfo?.icon_url;
                        IsChannelOwnedVideo = watchApi.channelInfo != null;

                        videoDescriptionHtml = watchApi.videoDetail.description;
                    }
                    else if (res is DmcWatchData)
                    {
                        var dmcWatchApi = (res as DmcWatchData).DmcWatchResponse;

                        VideoTitle = dmcWatchApi.Video.Title;
                        Tags       = dmcWatchApi.Tags.Select(x => new TagViewModel(x.Name))
                                     .ToList();
                        ThumbnailUrl        = dmcWatchApi.Video.ThumbnailURL;
                        VideoLength         = TimeSpan.FromSeconds(dmcWatchApi.Video.Duration);
                        SubmitDate          = DateTime.Parse(dmcWatchApi.Video.PostedDateTime);
                        ViewCount           = (uint)dmcWatchApi.Video.ViewCount;
                        CommentCount        = (uint)dmcWatchApi.Thread.CommentCount;
                        MylistCount         = (uint)dmcWatchApi.Video.MylistCount;
                        ProviderId          = dmcWatchApi.Owner?.Nickname ?? dmcWatchApi.Channel?.Name;
                        ProviderName        = dmcWatchApi.Owner?.Nickname ?? dmcWatchApi.Channel?.Name;
                        OwnerIconUrl        = dmcWatchApi.Owner?.IconURL ?? dmcWatchApi.Channel?.IconURL;
                        IsChannelOwnedVideo = dmcWatchApi.Channel != null;

                        videoDescriptionHtml = dmcWatchApi.Video.Description;
                    }
                }
                catch
                {
                    IsLoadFailed.Value = true;
                    return;
                }



                RaisePropertyChanged(nameof(VideoTitle));
                RaisePropertyChanged(nameof(Tags));
                RaisePropertyChanged(nameof(ThumbnailUrl));
                RaisePropertyChanged(nameof(VideoLength));
                RaisePropertyChanged(nameof(SubmitDate));
                RaisePropertyChanged(nameof(ViewCount));
                RaisePropertyChanged(nameof(CommentCount));
                RaisePropertyChanged(nameof(MylistCount));
                RaisePropertyChanged(nameof(ProviderName));
                RaisePropertyChanged(nameof(OwnerIconUrl));
            }

            try
            {
                DescriptionHtmlFileUri = await Models.Helpers.HtmlFileHelper.PartHtmlOutputToCompletlyHtml(VideoId, videoDescriptionHtml);

                RaisePropertyChanged(nameof(DescriptionHtmlFileUri));
            }
            catch
            {
                IsLoadFailed.Value = true;
                return;
            }


            try
            {
                var htmlDocument = new HtmlAgilityPack.HtmlDocument();
                htmlDocument.LoadHtml(videoDescriptionHtml);
                var root        = htmlDocument.DocumentNode;
                var anchorNodes = root.Descendants("a");

                foreach (var anchor in anchorNodes)
                {
                    VideoDescriptionHyperlinkItems.Add(new HyperlinkItem()
                    {
                        Label = anchor.InnerText,
                        Url   = new Uri(anchor.Attributes["href"].Value)
                    });

                    Debug.WriteLine($"{anchor.InnerText} : {anchor.Attributes["href"].Value}");
                }

                var matches = GeneralUrlRegex.Matches(videoDescriptionHtml);
                foreach (var match in matches.Cast <Match>())
                {
                    if (!VideoDescriptionHyperlinkItems.Any(x => x.Url.OriginalString == match.Value))
                    {
                        VideoDescriptionHyperlinkItems.Add(new HyperlinkItem()
                        {
                            Label = match.Value,
                            Url   = new Uri(match.Value)
                        });

                        Debug.WriteLine($"{match.Value} : {match.Value}");
                    }
                }

                RaisePropertyChanged(nameof(VideoDescriptionHyperlinkItems));
            }
            catch
            {
                Debug.WriteLine("動画説明からリンクを抜き出す処理に失敗");
            }
        }
        private async Task UpdateVideoDescription()
        {
            using (var releaser = await _UpdateLock.LockAsync())
            {
                if (VideoInfo.RawVideoId == null)
                {
                    return;
                }

                IsLoadFailed.Value = false;

                try
                {
                    var res = await NicoVideo.PreparePlayVideoAsync(VideoInfo.RawVideoId);

                    VideoDetals = res.GetVideoDetails();

                    //VideoTitle = details.VideoTitle;
                    //Tags = details.Tags.ToList();
                    //ThumbnailUrl = details.ThumbnailUrl;
                    //VideoLength = details.VideoLength;
                    //SubmitDate = details.SubmitDate;
                    //ViewCount = details.ViewCount;
                    //CommentCount = details.CommentCount;
                    //MylistCount = details.MylistCount;
                    //ProviderId = details.ProviderId;
                    //ProviderName = details.ProviderName;
                    //OwnerIconUrl = details.OwnerIconUrl;
                    //IsChannelOwnedVideo = details.IsChannelOwnedVideo;
                }
                catch
                {
                    IsLoadFailed.Value = true;
                    return;
                }
            }

            try
            {
                ApplicationTheme appTheme;
                if (_appearanceSettings.Theme == ElementTheme.Dark)
                {
                    appTheme = ApplicationTheme.Dark;
                }
                else if (_appearanceSettings.Theme == ElementTheme.Light)
                {
                    appTheme = ApplicationTheme.Light;
                }
                else
                {
                    appTheme = Views.Helpers.SystemThemeHelper.GetSystemTheme();
                }

                DescriptionHtmlFileUri = await Models.Helpers.HtmlFileHelper.PartHtmlOutputToCompletlyHtml(VideoInfo.VideoId, VideoDetals.DescriptionHtml, appTheme);

                RaisePropertyChanged(nameof(DescriptionHtmlFileUri));
            }
            catch
            {
                IsLoadFailed.Value = true;
                return;
            }


            VideoDescriptionHyperlinkItems.Clear();
            try
            {
                var htmlDocument = new HtmlAgilityPack.HtmlDocument();
                htmlDocument.LoadHtml(VideoDetals.DescriptionHtml);
                var root        = htmlDocument.DocumentNode;
                var anchorNodes = root.Descendants("a");

                foreach (var anchor in anchorNodes)
                {
                    var href = anchor.Attributes["href"].Value;
                    if (!Uri.IsWellFormedUriString(href, UriKind.Absolute))
                    {
                        Debug.WriteLine("リンク抽出スキップ: " + anchor.InnerText);
                        continue;
                    }

                    VideoDescriptionHyperlinkItems.Add(new HyperlinkItem()
                    {
                        Label = anchor.InnerText,
                        Url   = new Uri(href)
                    });

                    Debug.WriteLine($"{anchor.InnerText} : {anchor.Attributes["href"].Value}");
                }

                var matches = GeneralUrlRegex.Matches(VideoDetals.DescriptionHtml);
                foreach (var match in matches.Cast <Match>())
                {
                    if (!VideoDescriptionHyperlinkItems.Any(x => x.Url.OriginalString == match.Value))
                    {
                        VideoDescriptionHyperlinkItems.Add(new HyperlinkItem()
                        {
                            Label = match.Value,
                            Url   = new Uri(match.Value)
                        });

                        Debug.WriteLine($"{match.Value} : {match.Value}");
                    }
                }

                RaisePropertyChanged(nameof(VideoDescriptionHyperlinkItems));
            }
            catch
            {
                Debug.WriteLine("動画説明からリンクを抜き出す処理に失敗");
            }
        }