示例#1
0
        public async Task <List <LoginUserMylistGroup> > GetLoginUserMylistGroups()
        {
            if (Context == null)
            {
                return(null);
            }

            if (await Context.GetIsSignedInAsync() != NiconicoSignInStatus.Success)
            {
                return(null);
            }


            await WaitNicoPageAccess();


            return(await ConnectionRetryUtil.TaskWithRetry(() =>
            {
                return Context.User.GetMylistGroupListAsync();
            })
                   .ContinueWith(prevResult =>
            {
                return prevResult.Result.Cast <LoginUserMylistGroup>().ToList();
            }));
        }
示例#2
0
        public async Task <List <LoginUserMylistGroup> > GetLoginUserMylistGroups()
        {
            if (_HohoemaApp.NiconicoContext == null)
            {
                return(null);
            }

            if (!_HohoemaApp.IsLoggedIn)
            {
                return(null);
            }


            await WaitNicoPageAccess();


            return(await ConnectionRetryUtil.TaskWithRetry(() =>
            {
                return _HohoemaApp.NiconicoContext.User.GetMylistGroupListAsync();
            })
                   .ContinueWith(prevResult =>
            {
                return prevResult.Result.Cast <LoginUserMylistGroup>().ToList();
            }));
        }
示例#3
0
        public async Task <UserDetail> GetUserDetail(string userId)
        {
            var userDetail = await ConnectionRetryUtil.TaskWithRetry(() =>
            {
                return(Context.User.GetUserDetail(userId));
            });

            if (userDetail != null)
            {
                var owner = NicoVideoOwnerDb.Get(userId);
                if (owner == null)
                {
                    owner = new NicoVideoOwner()
                    {
                        OwnerId  = userId,
                        UserType = UserType.User
                    };
                }
                owner.ScreenName = userDetail.Nickname;
                owner.IconUrl    = userDetail.ThumbnailUri;

                NicoVideoOwnerDb.AddOrUpdate(owner);
            }

            return(userDetail);
        }
示例#4
0
        public async Task <CommunityDetailResponse> GetCommunityDetail(
            string communityId
            )
        {
            if (Context == null)
            {
                return(null);
            }

            if (await Context.GetIsSignedInAsync() != NiconicoSignInStatus.Success)
            {
                return(null);
            }


            await WaitNicoPageAccess();


            return(await ConnectionRetryUtil.TaskWithRetry(async() =>
            {
                using (var releaser = await _NicoPageAccessLock.LockAsync())
                {
                    return await Context.Community.GetCommunityDetailAsync(communityId);
                }
            }));
        }
示例#5
0
        public async Task <CommunityDetailResponse> GetCommunityDetail(
            string communityId
            )
        {
            if (_HohoemaApp.NiconicoContext == null)
            {
                return(null);
            }

            if (!_HohoemaApp.IsLoggedIn)
            {
                return(null);
            }


            await WaitNicoPageAccess();


            return(await ConnectionRetryUtil.TaskWithRetry(async() =>
            {
                using (var releaser = await _NicoPageAccessLock.LockAsync())
                {
                    return await _HohoemaApp.NiconicoContext.Community.GetCommunityDetailAsync(communityId);
                }
            }));
        }
示例#6
0
        public async Task <NicoVideoOwner> GetUser(string userId)
        {
            using (var releaser = await _NicoPageAccessLock.LockAsync())
            {
                var userRes = await ConnectionRetryUtil.TaskWithRetry(() =>
                {
                    return(Context.User.GetUserAsync(userId));
                });

                var owner = NicoVideoOwnerDb.Get(userId);
                if (userRes.Status == "ok")
                {
                    var user = userRes.User;
                    if (owner == null)
                    {
                        owner = new NicoVideoOwner()
                        {
                            OwnerId  = userId,
                            UserType = UserType.User
                        };
                    }
                    owner.ScreenName = user.Nickname;
                    owner.IconUrl    = user.ThumbnailUrl;

                    NicoVideoOwnerDb.AddOrUpdate(owner);
                }

                return(owner);
            }
        }
示例#7
0
 public async Task <NiconicoVideoRss> GetCategoryRanking(RankingCategory category, RankingTarget target, RankingTimeSpan timeSpan)
 {
     return(await ConnectionRetryUtil.TaskWithRetry(async() =>
     {
         return await NiconicoRanking.GetRankingData(target, timeSpan, category);
     }));
 }
示例#8
0
        public async Task <NiconicoSignInStatus> CheckSignedInStatus()
        {
            NiconicoSignInStatus result = NiconicoSignInStatus.Failed;

            try
            {
                await _SigninLock.WaitAsync();

                if (Util.InternetConnection.IsInternet() && NiconicoContext != null)
                {
                    result = await ConnectionRetryUtil.TaskWithRetry(
                        () => NiconicoContext.GetIsSignedInAsync()
                        , retryInterval : 1000
                        );
                }
            }
            catch
            {
                // ログイン処理時には例外を捕捉するが、ログイン状態チェックでは例外は無視する
                result = NiconicoSignInStatus.Failed;
            }
            finally
            {
                UpdateServiceStatus(result);

                _SigninLock.Release();
            }

            return(result);
        }
示例#9
0
        public async Task <CommunitySearchResponse> SearchCommunity(
            string keyword
            , uint page
            , CommunitySearchSort sort = CommunitySearchSort.CreatedAt
            , Order order = Order.Descending
            , CommunitySearchMode mode = CommunitySearchMode.Keyword
            )
        {
            if (_HohoemaApp.NiconicoContext == null)
            {
                return(null);
            }

            if (!_HohoemaApp.IsLoggedIn)
            {
                return(null);
            }


            return(await ConnectionRetryUtil.TaskWithRetry(async() =>
            {
                using (var releaser = await _NicoPageAccessLock.LockAsync())
                {
                    return await _HohoemaApp.NiconicoContext.Search.CommunitySearchAsync(keyword, page, sort, order, mode);
                }
            }));
        }
示例#10
0
        public async Task <List <MylistGroupData> > GetUserMylistGroups(string userId)
        {
            if (_HohoemaApp.NiconicoContext == null)
            {
                return(null);
            }

            await WaitNicoPageAccess();


            return(await ConnectionRetryUtil.TaskWithRetry(async() =>
            {
                try
                {
                    return await _HohoemaApp.NiconicoContext.Mylist.GetUserMylistGroupAsync(userId);
                }
                catch (Exception e) when(e.Message.Contains("Forbidden"))
                {
                    return new List <MylistGroupData>();
                }
            })
                   .ContinueWith(prevTask =>
            {
                if (prevTask.IsCompleted && prevTask.Result != null)
                {
                    _CachedUserMylistGroupDatum = prevTask.Result;
                    return prevTask.Result;
                }
                else
                {
                    return _CachedUserMylistGroupDatum;
                }
            }));
        }
示例#11
0
        // コメントのキャッシュまたはオンラインからの取得と更新
        public async Task <List <Chat> > GetComments()
        {
            if (CommentServerInfo == null)
            {
                return(new List <Chat>());
            }

            CommentResponse commentRes = null;

            try
            {
                commentRes = await ConnectionRetryUtil.TaskWithRetry(async() =>
                {
                    return(await this.HohoemaApp.NiconicoContext.Video
                           .GetCommentAsync(
                               (int)HohoemaApp.LoginUserId,
                               CommentServerInfo.ServerUrl,
                               CommentServerInfo.DefaultThreadId,
                               CommentServerInfo.ThreadKeyRequired
                               ));
                });
            }
            catch
            {
            }


            if (commentRes?.Chat.Count == 0)
            {
                try
                {
                    if (CommentServerInfo.CommunityThreadId.HasValue)
                    {
                        commentRes = await ConnectionRetryUtil.TaskWithRetry(async() =>
                        {
                            return(await this.HohoemaApp.NiconicoContext.Video
                                   .GetCommentAsync(
                                       (int)HohoemaApp.LoginUserId,
                                       CommentServerInfo.ServerUrl,
                                       CommentServerInfo.CommunityThreadId.Value,
                                       CommentServerInfo.ThreadKeyRequired
                                       ));
                        });
                    }
                }
                catch { }
            }

            if (commentRes != null)
            {
                CachedCommentResponse = commentRes;
                CommentDb.AddOrUpdate(RawVideoId, commentRes);
            }

            return(commentRes?.Chat);
        }
示例#12
0
        public async Task <MylistGroupVideoResponse> GetMylistGroupVideo(string mylistGroupid, uint from = 0, uint limit = 50)
        {
            if (_HohoemaApp.NiconicoContext == null)
            {
                return(null);
            }

            return(await ConnectionRetryUtil.TaskWithRetry(async() =>
            {
                return await _HohoemaApp.NiconicoContext.Mylist.GetMylistGroupVideoAsync(mylistGroupid, from, limit);
            }));
        }
示例#13
0
        public async Task <MylistGroupDetailResponse> GetMylistGroupDetail(string mylistGroupid)
        {
            if (_HohoemaApp.NiconicoContext == null)
            {
                return(null);
            }

            return(await ConnectionRetryUtil.TaskWithRetry(async() =>
            {
                return await _HohoemaApp.NiconicoContext.Mylist.GetMylistGroupDetailAsync(mylistGroupid);
            }));
        }
示例#14
0
        public async Task <VideoListingResponse> GetKeywordSearch(string keyword, uint from, uint limit, Sort sort = Sort.FirstRetrieve, Order order = Order.Descending)
        {
            if (_HohoemaApp.NiconicoContext == null)
            {
                return(null);
            }

            return(await ConnectionRetryUtil.TaskWithRetry(async() =>
            {
                return await _HohoemaApp.NiconicoContext.Search.VideoSearchWithKeywordAsync(keyword, from, limit, sort, order);
            }
                                                           , retryInterval : 1000));
        }
示例#15
0
        public async Task <UserDetail> GetUserDetail(string userId)
        {
            var userDetail = await ConnectionRetryUtil.TaskWithRetry(() =>
            {
                return(_HohoemaApp.NiconicoContext.User.GetUserDetail(userId));
            });

            if (userDetail != null)
            {
                await UserInfoDb.AddOrReplaceAsync(userId, userDetail.Nickname, userDetail.ThumbnailUri);
            }

            return(userDetail);
        }
示例#16
0
        public async Task <HistoriesResponse> GetHistory()
        {
            if (_HohoemaApp.NiconicoContext == null)
            {
                return(null);
            }

            if (!_HohoemaApp.IsLoggedIn)
            {
                return(null);
            }

            await WaitNicoPageAccess();

            return(await ConnectionRetryUtil.TaskWithRetry(async() =>
            {
                return await _HohoemaApp.NiconicoContext.Video.GetHistoriesAsync();
            }));
        }
示例#17
0
        public async Task <HistoriesResponse> GetHistory()
        {
            if (Context == null)
            {
                return(null);
            }

            if (await Context.GetIsSignedInAsync() != NiconicoSignInStatus.Success)
            {
                return(null);
            }

            await WaitNicoPageAccess();

            return(await ConnectionRetryUtil.TaskWithRetry(async() =>
            {
                return await Context.Video.GetHistoriesAsync();
            }));
        }
示例#18
0
        public async Task <NiconicoVideoRss> GetCommunityVideo(
            string communityId,
            uint page
            )
        {
            if (Context == null)
            {
                return(null);
            }

            if (await Context.GetIsSignedInAsync() != NiconicoSignInStatus.Success)
            {
                return(null);
            }


            return(await ConnectionRetryUtil.TaskWithRetry(async() =>
            {
                return await Context.Community.GetCommunityVideoAsync(communityId, page);
            }));
        }
示例#19
0
        public Task <NiconicoVideoRss> GetCommunityVideo(
            string communityId,
            uint page
            )
        {
            if (_HohoemaApp.NiconicoContext == null)
            {
                return(null);
            }

            if (!_HohoemaApp.IsLoggedIn)
            {
                return(null);
            }


            return(ConnectionRetryUtil.TaskWithRetry(async() =>
            {
                return await _HohoemaApp.NiconicoContext.Community.GetCommunityVideoAsync(communityId, page);
            }));
        }
示例#20
0
        public async Task <UserDetail> GetUserInfo(string userId)
        {
            if (_HohoemaApp.NiconicoContext == null)
            {
                return(null);
            }

            await WaitNicoPageAccess();



            var user = await ConnectionRetryUtil.TaskWithRetry(() =>
            {
                return(_HohoemaApp.NiconicoContext.User.GetUserDetail(userId));
            });

            if (user != null)
            {
                await UserInfoDb.AddOrReplaceAsync(userId, user.Nickname, user.ThumbnailUri);
            }

            return(user);
        }
示例#21
0
        public async Task <VideoListingResponse> GetTagSearch(string tag, uint from, uint limit, Sort sort = Sort.FirstRetrieve, Order order = Order.Descending)
        {
            if (_HohoemaApp.NiconicoContext == null)
            {
                return(null);
            }

            return(await ConnectionRetryUtil.TaskWithRetry(async() =>
            {
                return await _HohoemaApp.NiconicoContext.Search.VideoSearchWithTagAsync(tag, from, limit, sort, order)
                .ContinueWith(prevTask =>
                {
                    if (!prevTask.Result.IsOK)
                    {
                        throw new WebException();
                    }
                    else
                    {
                        return prevTask.Result;
                    }
                });
            }, retryInterval : 1000));
        }
示例#22
0
        private async Task <List <Chat> > GetComments()
        {
            if (CommentServerInfo == null)
            {
                return(new List <Chat>());
            }

            CommentResponse commentRes = null;

            try
            {
                commentRes = await ConnectionRetryUtil.TaskWithRetry(async() =>
                {
                    return(await ContextActionAsync(async context =>
                    {
                        return await context.Video
                        .GetCommentAsync(
                            (int)CommentServerInfo.ViewerUserId,
                            CommentServerInfo.ServerUrl,
                            CommentServerInfo.DefaultThreadId,
                            CommentServerInfo.ThreadKeyRequired
                            );
                    }));
                });
            }
            catch
            {
            }


            if (commentRes?.Chat.Count == 0)
            {
                try
                {
                    if (CommentServerInfo.CommunityThreadId.HasValue)
                    {
                        commentRes = await ConnectionRetryUtil.TaskWithRetry(async() =>
                        {
                            return(await ContextActionAsync(async context =>
                            {
                                return await context.Video
                                .GetCommentAsync(
                                    (int)CommentServerInfo.ViewerUserId,
                                    CommentServerInfo.ServerUrl,
                                    CommentServerInfo.CommunityThreadId.Value,
                                    CommentServerInfo.ThreadKeyRequired
                                    );
                            }));
                        });
                    }
                }
                catch { }
            }

            if (commentRes != null)
            {
                CachedCommentResponse = commentRes;
                Database.VideoCommentDb.AddOrUpdate(RawVideoId, commentRes.Chat);
            }

            if (commentRes != null && DefaultThreadSubmitInfo == null)
            {
                DefaultThreadSubmitInfo        = new CommentSubmitInfo();
                DefaultThreadSubmitInfo.Ticket = commentRes.Thread.Ticket;
                if (int.TryParse(commentRes.Thread.CommentCount, out int count))
                {
                    DefaultThreadSubmitInfo.CommentCount = count + 1;
                }
            }

            return(commentRes?.Chat);
        }