public override async Task <Uri> GenerateVideoContentUrl()
        {
            if (DmcWatchResponse == null)
            {
                return(null);
            }

            if (DmcWatchResponse.Video.DmcInfo == null)
            {
                return(null);
            }

            VideoContent videoQuality = Video;

            if (Video == null)
            {
                return(null);
            }

            try
            {
                // 直前に同一動画を見ていた場合には、動画ページに再アクセスする
                DmcSessionResponse clearPreviousSession = null;
                if (_DmcSessionResponse != null && DmcWatchEnvironment != null)
                {
                    if (_DmcSessionResponse.Data.Session.RecipeId.EndsWith(RawVideoId))
                    {
                        clearPreviousSession = _DmcSessionResponse;
                        _DmcSessionResponse  = null;
                        _DmcWatchResponse    = await HohoemaApp.NiconicoContext.Video.GetDmcWatchJsonAsync(RawVideoId, DmcWatchEnvironment.PlaylistToken);

                        videoQuality = Video;
                    }
                }

                _DmcSessionResponse = await HohoemaApp.NiconicoContext.Video.GetDmcSessionResponse(DmcWatchResponse, videoQuality);

                if (_DmcSessionResponse == null)
                {
                    return(null);
                }

                if (clearPreviousSession != null)
                {
                    await HohoemaApp.NiconicoContext.Video.DmcSessionExitHeartbeatAsync(DmcWatchResponse, clearPreviousSession);
                }

                return(new Uri(_DmcSessionResponse.Data.Session.ContentUri));
            }
            catch
            {
                return(null);
            }
        }
Example #2
0
        public static async Task UpdateNicoVideoInfo(NicoVideoInfo info, DmcWatchResponse watchApiRes)
        {
            info.DescriptionWithHtml = watchApiRes.Video.Description;

            info.ThreadId     = watchApiRes.Thread.Ids.Default;
            info.ViewCount    = (uint)watchApiRes.Video.ViewCount;
            info.MylistCount  = (uint)watchApiRes.Video.MylistCount;
            info.CommentCount = (uint)watchApiRes.Thread.CommentCount;

            //info.PrivateReasonType = watchApiRes.;

            await UpdateAsync(info);
        }
 internal DmcVideoDetails(DmcWatchData dmcWatchData)
 {
     _dmcWatchRes = dmcWatchData.DmcWatchResponse;
     Tags         = _dmcWatchRes.Tags.Select(x => new NicoVideoTag(x.Name)).ToArray();
 }
Example #4
0
        private async Task <DmcWatchResponse> GetDmcWatchResponse()
        {
            if (!HohoemaApp.IsLoggedIn)
            {
                return(null);
            }

            DmcWatchResponse dmcWatchResponse = null;

            try
            {
                dmcWatchResponse = await HohoemaApp.ContentFinder.GetDmcWatchResponse(RawVideoId, HarmfulContentReactionType);
            }
            catch (AggregateException ea) when(ea.Flatten().InnerExceptions.Any(e => e is ContentZoningException))
            {
                IsBlockedHarmfulVideo = true;
            }
            catch (ContentZoningException)
            {
                IsBlockedHarmfulVideo = true;
            }

            if (dmcWatchResponse != null)
            {
                NowLowQualityOnly = dmcWatchResponse.Video.SmileInfo.IsSlowLine;
            }

            //			_VisitedPageType = watchApiRes.Vide.AbsoluteUri.EndsWith("low") ? NicoVideoQuality.Low : NicoVideoQuality.Original;


            if (dmcWatchResponse != null)
            {
                if (dmcWatchResponse.Video.DmcInfo.Quality == null)
                {
                    throw new Exception("Dmcサーバーからの再生が出来ません。");
                }

                ProtocolType = MediaProtocolType.RTSPoverHTTP;

                if (dmcWatchResponse.Video.SmileInfo.Url != null)
                {
                    LegacyVideoUrl = new Uri(dmcWatchResponse.Video.SmileInfo.Url);
                    ProtocolType   = MediaProtocolTypeHelper.ParseMediaProtocolType(LegacyVideoUrl);
                }


                DescriptionWithHtml = dmcWatchResponse.Video.Description;
                ThreadId            = dmcWatchResponse.Thread.Ids.Default;
                //PrivateReasonType = watchApiRes.PrivateReason;
                VideoLength       = TimeSpan.FromSeconds(dmcWatchResponse.Video.Duration);
                NowLowQualityOnly = dmcWatchResponse.Video.SmileInfo?.IsSlowLine ?? false;
                //IsOriginalQualityOnly = dmcWatchResponse.Video.SmileInfo?.QualityIds?.Count == 1;

                if (!_thumbnailInitialized)
                {
                    RawVideoId = dmcWatchResponse.Video.Id;
                    await UpdateWithThumbnail();
                }
                IsCommunity = dmcWatchResponse.Video.IsCommunityMemberOnly == "1";

                if (CommentClient.CommentServerInfo == null)
                {
                    if (dmcWatchResponse.Video.DmcInfo != null)
                    {
                        var commentServerInfo = new CommentServerInfo()
                        {
                            ServerUrl         = dmcWatchResponse.Video.DmcInfo.Thread.ServerUrl,
                            DefaultThreadId   = dmcWatchResponse.Video.DmcInfo.Thread.ThreadId,
                            ThreadKeyRequired = dmcWatchResponse.Video.DmcInfo?.Thread.ThreadKeyRequired ?? false
                        };

                        CommentClient.CommentServerInfo = commentServerInfo;
                    }
                    else
                    {
                        var commentServerInfo = new CommentServerInfo()
                        {
                            ServerUrl         = dmcWatchResponse.Thread.ServerUrl,
                            DefaultThreadId   = int.Parse(dmcWatchResponse.Thread.Ids.Default),
                            ThreadKeyRequired = dmcWatchResponse.Video.IsOfficial
                        };

                        if (int.TryParse((string)dmcWatchResponse.Thread.Ids.Community, out var comThreadId))
                        {
                            commentServerInfo.CommunityThreadId = comThreadId;
                        }

                        CommentClient.CommentServerInfo = commentServerInfo;
                    }
                }

                foreach (var divided in GetAllQuality())
                {
                    if (divided is DmcQualityNicoVideo)
                    {
                        (divided as DmcQualityNicoVideo).DmcWatchResponse = dmcWatchResponse;
                    }
                }

                // TODO:
                //				Tags = watchApiRes.videoDetail.tagList.Select(x => new Tag()
                //				{

                //				}).ToList();

                if (dmcWatchResponse.Owner != null)
                {
                    OwnerId        = uint.Parse(dmcWatchResponse.Owner.Id);
                    OwnerIconUrl   = dmcWatchResponse.Owner.IconURL;
                    this.OwnerName = dmcWatchResponse.Owner.Nickname;
                }


                this.IsDeleted = dmcWatchResponse.Video.IsDeleted;
                if (IsDeleted)
                {
                    await DeletedTeardown();
                }
            }

            return(dmcWatchResponse);
        }