Exemplo n.º 1
0
        private async Task RefreshTimeshiftProgram()
        {
            if (NiconicoSession.IsLoggedIn)
            {
                var timeshiftDetailsRes = await LoginUserLiveReservationProvider.GetReservtionsAsync();

                foreach (var timeshift in timeshiftDetailsRes.ReservedProgram)
                {
                    if (LiveId.EndsWith(timeshift.Id))
                    {
                        _TimeshiftProgram = timeshift;
                    }
                }
            }
            else
            {
                _TimeshiftProgram = null;
            }
        }
        private async Task RefreshLiveInfoAsync()
        {
            IsLoadFailed.Value      = false;
            LoadFailedMessage.Value = string.Empty;

            IsLiveInfoLoaded.Value = false;
            try
            {
                if (LiveId == null)
                {
                    throw new Exception("Require LiveId in LiveInfomationPage navigation with (e.Parameter as string)");
                }

                var liveInfoResponse = await NiconicoSession.Context.Live.GetLiveVideoInfoAsync(LiveId);

                if (!liveInfoResponse.IsOK)
                {
                    throw new Exception("Live not found. LiveId is " + LiveId);
                }

                var liveInfo = liveInfoResponse.VideoInfo;
                {
                    _LiveTags.Clear();

                    Func <string, LiveTagType, LiveTagViewModel> ConvertToLiveTagVM =
                        (x, type) => new LiveTagViewModel()
                    {
                        Tag = x, Type = type
                    };

                    var tags = new[] {
                        liveInfo.Livetags.Category?.Tags.Select(x => ConvertToLiveTagVM(x, LiveTagType.Category)),
                        liveInfo.Livetags.Locked?.Tags.Select(x => ConvertToLiveTagVM(x, LiveTagType.Locked)),
                        liveInfo.Livetags.Free?.Tags.Select(x => ConvertToLiveTagVM(x, LiveTagType.Free)),
                    }
                    .SelectMany(x => x ?? Enumerable.Empty <LiveTagViewModel>());

                    foreach (var tag in tags)
                    {
                        _LiveTags.Add(tag);
                    }

                    RaisePropertyChanged(nameof(LiveTags));
                }

                var reseevations = await NiconicoSession.Context.Live.GetReservationsInDetailAsync();

                var thisLiveReservation = reseevations.ReservedProgram.FirstOrDefault(x => LiveId.EndsWith(x.Id));
                if (thisLiveReservation != null)
                {
                    var timeshiftList = await NiconicoSession.Context.Live.GetMyTimeshiftListAsync();

                    ExpiredTime = (timeshiftList.Items.FirstOrDefault(x => x.Id == LiveId)?.WatchTimeLimit ?? thisLiveReservation.ExpiredAt).LocalDateTime;
                }

                _IsTsPreserved.Value = thisLiveReservation != null;

                // タイムシフト視聴開始の判定処理のため_IsTsPreservedより後にLiveInfoを代入する
                LiveInfo = liveInfo;

                Community = LiveInfo.Community != null ? new LiveCommunityInfo()
                {
                    Id = LiveInfo.Community.GlobalId, Label = LiveInfo.Community.Name
                } : null;
            }
            catch (Exception ex)
            {
                IsLoadFailed.Value      = true;
                LoadFailedMessage.Value = ex.Message;
            }
            finally
            {
                IsLiveInfoLoaded.Value = true;
            }
        }