Exemple #1
0
 public static async Task FollowArtist(this PixivClient _, User user)
 {
     user.IsFollowed = true;
     await HttpClientFactory.AppApiService().FollowArtist(new FollowArtistRequest {
         Id = user.Id
     });
 }
 public static async Task UnFollowArtist(this PixivClient _, User user)
 {
     user.IsFollowed = false;
     await HttpClientFactory.AppApiService().UnFollowArtist(new UnFollowArtistRequest {
         UserId = user.Id
     });
 }
Exemple #3
0
 public static async void RemoveFavoriteAsync(this PixivClient _, Illustration illustration)
 {
     illustration.IsLiked = false;
     await HttpClientFactory.AppApiService().DeleteBookmark(new DeleteBookmarkRequest {
         IllustId = illustration.Id
     });
 }
Exemple #4
0
        private async void UserPreviewPopupContent_OnLoaded(object sender, RoutedEventArgs e)
        {
            var userInfo = sender.GetDataContext <User>();
            var ctrl     = (UserPreviewPopupContent)sender;
            var usr      = await HttpClientFactory.AppApiService()
                           .GetUserInformation(new UserInformationRequest {
                Id = $"{sender.GetDataContext<User>().Id}"
            });

            var usrEntity = new User
            {
                Avatar       = usr.UserEntity.ProfileImageUrls.Medium,
                Background   = usr.UserEntity.ProfileImageUrls.Medium,
                Follows      = (int)usr.UserProfile.TotalFollowUsers,
                Id           = usr.UserEntity.Id.ToString(),
                Introduction = usr.UserEntity.Comment,
                IsFollowed   = usr.UserEntity.IsFollowed,
                IsPremium    = usr.UserProfile.IsPremium,
                Name         = usr.UserEntity.Name,
                Thumbnails   = sender.GetDataContext <User>().Thumbnails
            };

            ctrl.DataContext = usrEntity;
            var result = await Tasks <string, BitmapImage> .Of(userInfo.Thumbnails.Take(3))
                         .Mapping(PixivIO.FromUrl)
                         .Construct()
                         .WhenAll();

            ctrl.SetImages(result[0], result[1], result[2]);
        }
Exemple #5
0
 public static async void PostFavoriteAsync(this PixivClient _, Illustration illustration, RestrictPolicy restrictPolicy)
 {
     illustration.IsLiked = true;
     await HttpClientFactory.AppApiService().AddBookmark(new AddBookmarkRequest {
         Id = illustration.Id, Restrict = restrictPolicy == RestrictPolicy.Public ? "public" : "private"
     });
 }
Exemple #6
0
 public static async void PostFavoriteAsync(this PixivClient _, Illustration illustration)
 {
     illustration.IsLiked = true;
     await HttpClientFactory.AppApiService().AddBookmark(new AddBookmarkRequest {
         Id = illustration.Id
     });
 }
Exemple #7
0
        private async void KeywordTextBox_OnTextChanged(object sender, TextChangedEventArgs e)
        {
            if (!KeywordTextBox.Text.IsNullOrEmpty())
            {
                TrendingTagPopup.CloseControl();
            }

            if (QueryArtistToggleButton.IsChecked == true || QuerySingleArtistToggleButton.IsChecked == true || QuerySingleWorkToggleButton.IsChecked == true)
            {
                return;
            }

            var word = KeywordTextBox.Text;

            try
            {
                var result = await HttpClientFactory.AppApiService().GetAutoCompletion(new AutoCompletionRequest {
                    Word = word
                });

                if (result.Tags.Any())
                {
                    AutoCompletionPopup.OpenControl();
                    AutoCompletionListBox.ItemsSource = result.Tags.Select(p => new AutoCompletion {
                        Tag = p.Name, TranslatedName = p.TranslatedName
                    });
                }
            }
            catch (ApiException)
            {
                AutoCompletionPopup.CloseControl();
            }
        }
Exemple #8
0
        private async void PlayGif_OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            ProcessingGif = true;
            var metadata = await HttpClientFactory.AppApiService().GetUgoiraMetadata(Illust.Id);

            var ugoiraZip = metadata.UgoiraMetadataInfo.ZipUrls.Medium;
            var delay     = metadata.UgoiraMetadataInfo.Frames.Select(f => f.Delay / 10).ToArray();
            var streams   = InternalIO.ReadGifZipEntries(await PixivIO.GetBytes(ugoiraZip)).ToArray();

            ProcessingGif = false;
            PlayingGif    = true;

#pragma warning disable 4014
            Task.Run(async() =>
            {
                while (!cancellationToken.IsCancellationRequested)
                {
                    for (var i = 0; i < streams.Length && !cancellationToken.IsCancellationRequested; i++)
                    {
                        streams[i].Position = 0;
                        ImgSource           = InternalIO.CreateBitmapImageFromStream(streams[i]);
                        await Task.Delay((int)delay[i], cancellationToken.Token);
                    }
                }
            });
#pragma warning restore 4014
        }
Exemple #9
0
        public async void SetUserBrowserContext(User user)
        {
            var usr = await HttpClientFactory.AppApiService()
                      .GetUserInformation(new UserInformationRequest {
                Id = $"{user.Id}"
            });

            var usrEntity = new User
            {
                Avatar       = usr.UserEntity.ProfileImageUrls.Medium,
                Background   = usr.UserEntity.ProfileImageUrls.Medium,
                Follows      = (int)usr.UserProfile.TotalFollowUsers,
                Id           = usr.UserEntity.Id.ToString(),
                Introduction = usr.UserEntity.Comment,
                IsFollowed   = usr.UserEntity.IsFollowed,
                IsPremium    = usr.UserProfile.IsPremium,
                Name         = usr.UserEntity.Name,
                Thumbnails   = user.Thumbnails
            };

            PixivHelper.RecordTimelineInternal(new BrowsingHistory
            {
                BrowseObjectId        = usrEntity.Id,
                BrowseObjectState     = usrEntity.Name,
                BrowseObjectThumbnail = usrEntity.Avatar,
                IsReferToUser         = true,
                Type = "user"
            });
            UserBrowserPageScrollViewer.DataContext = usrEntity;
            SetUserBanner(usrEntity.Id);
            SetImageSource(UserBrowserUserAvatar, await PixivIO.FromUrl(usrEntity.Avatar));
            SetupUserUploads(usrEntity.Id);
        }
Exemple #10
0
        public async void OpenIllustBrowser(Illustration illustration, bool record = true)
        {
            if (!illustration.FromSpotlight && record)
            {
                PixivHelper.RecordTimelineInternal(new BrowsingHistory
                {
                    BrowseObjectId        = illustration.Id,
                    BrowseObjectState     = illustration.Title,
                    BrowseObjectThumbnail = illustration.Thumbnail,
                    IllustratorName       = illustration.UserName,
                    IsReferToIllust       = true,
                    Type = "illust"
                });
            }

            IllustBrowserDialogHost.DataContext = illustration;
            await Task.Delay(100);

            IllustBrowserDialogHost.OpenControl();
            var userInfo = await HttpClientFactory.AppApiService()
                           .GetUserInformation(new UserInformationRequest {
                Id = illustration.UserId
            });

            if (await PixivIO.FromUrl(userInfo.UserEntity.ProfileImageUrls.Medium) is { } avatar)
            {
                SetImageSource(IllustBrowserUserAvatar, avatar);
            }
        }
Exemple #11
0
        private async void ShowArtist(string userId)
        {
            if (!userId.IsNumber())
            {
                MessageQueue.Enqueue(AkaI18N.UserIdIllegal);
                return;
            }

            try
            {
                await HttpClientFactory.AppApiService().GetUserInformation(new UserInformationRequest {
                    Id = userId
                });
            }
            catch (ApiException e)
            {
                if (e.StatusCode == HttpStatusCode.NotFound)
                {
                    MessageQueue.Enqueue(AkaI18N.CannotFindUser);
                    return;
                }
            }

            OpenUserBrowser();
            SetUserBrowserContext(new User {
                Id = userId
            });
        }
Exemple #12
0
 public static async Task FollowArtist(this PixivClient _, User user, RestrictPolicy policy)
 {
     user.IsFollowed = true;
     await HttpClientFactory.AppApiService().FollowArtist(new FollowArtistRequest {
         Id = user.Id, Restrict = policy == RestrictPolicy.Private ? "private" : "public"
     });
 }
 public static async Task PutUserView(this SFClient _, int NovelID, int ChapID)
 {
     await HttpClientFactory.AppApiService().PutUserNovelView(NovelID.ToString(), new Data.Web.Request.UserNovelViews()
     {
         chapterId            = ChapID,
         triggerCardPieceDrop = true
     });
 }
        private async Task Request()
        {
            var newIllustrators = await HttpClientFactory.AppApiService().GetRecommendIllustrators(new RecommendIllustratorRequest {
                Offset = _requestTimes++ *30
            });

            _currentIllustrators.AddRange(newIllustrators.UserPreviews.Select(i => i.Parse()));
        }
Exemple #15
0
        public static async Task <Illustration> IllustrationInfo(string id)
        {
            SingleWorkResponse.Illust response;
            try
            {
                response = (await HttpClientFactory.AppApiService().GetSingle(id)).IllustInfo;
            }
            catch (ApiException e)
            {
                ExceptionDumper.WriteException(e);
                return(null);
            }
            catch (Exception)
            {
                return(null);
            }

            var illust = new Illustration
            {
                Bookmark = (int)response.TotalBookmarks,
                Id       = response.Id.ToString(),
                IsLiked  = response.IsBookmarked,
                IsManga  = response.PageCount != 1,
                IsUgoira = response.Type == "ugoira",
                Origin   = response.ImageUrls.Original ?? response.MetaSinglePage.OriginalImageUrl,
                Large    = response.ImageUrls.Large,
                Tags     = response.Tags.Select(t => new Tag {
                    Name = t.Name, TranslatedName = t.TranslatedName
                }),
                Thumbnail   = response.ImageUrls.Medium,
                Title       = response.Title,
                UserName    = response.User.Name,
                UserId      = response.User.Id.ToString(),
                ViewCount   = (int)response.TotalView,
                Comments    = (int)response.TotalComments,
                Resolution  = $"{response.Width}x{response.Height}",
                PublishDate = response.CreateDate
            };

            if (illust.IsManga && response.MetaPages != null)
            {
                illust.MangaMetadata = response.MetaPages.Select(p =>
                {
                    var page       = (Illustration)illust.Clone();
                    page.Thumbnail = p.ImageUrls.Medium;
                    page.Origin    = p.ImageUrls.Original;
                    page.Large     = p.ImageUrls.Large;
                    return(page);
                }).ToArray();
            }

            return(illust);
        }
        public static async Task <ChapItem> GetChapContent(this SFClient _, int ChapID)
        {
            var result = await HttpClientFactory.AppApiService().GetChapDetailResponse(ChapID.ToString());

            return(new ChapItem()
            {
                ChapID = result.data.chapId,
                NovelID = result.data.novelId,
                VolumeID = result.data.volumeId,
                Content = result.data.expand.content,
                Title = result.data.title
            });
        }
        public static async Task <int> NovelViewData(this SFClient _, int NovelID)
        {
            var result = await HttpClientFactory.AppApiService().GetUserViewDataResponse();

            foreach (var item in result.data)
            {
                if (item.novelId == NovelID)
                {
                    return(item.chapterId);
                }
            }
            return(-1);
        }
        private async void DownloadGif()
        {
            var downloadPath = GetPath();

            try
            {
                var metadata = await HttpClientFactory.AppApiService().GetUgoiraMetadata(DownloadContent.Id);

                var ugoiraUrl = metadata.UgoiraMetadataInfo.ZipUrls.Medium;
                ugoiraUrl = !ugoiraUrl.EndsWith("ugoira1920x1080.zip")
                    ? Regex.Replace(ugoiraUrl, "ugoira(\\d+)x(\\d+).zip", "ugoira1920x1080.zip")
                    : ugoiraUrl;
                var delay = metadata.UgoiraMetadataInfo.Frames.Select(f => f.Delay / 10).ToArray();
                if (cancellationTokenSource.IsCancellationRequested)
                {
                    return;
                }
                await using var memory = await PixivIO.Download(ugoiraUrl, new Progress <double>(d => Progress = d),
                                                                cancellationTokenSource.Token);

                await using var gifStream =
                                (MemoryStream)InternalIO.MergeGifStream(InternalIO.ReadGifZipEntries(memory), delay);
                if (cancellationTokenSource.IsCancellationRequested)
                {
                    return;
                }
                await using var fileStream = new FileStream(downloadPath, FileMode.OpenOrCreate, FileAccess.ReadWrite,
                                                            FileShare.None);
                gifStream.WriteTo(fileStream);
                DownloadState.Value = DownloadStateEnum.Finished;
            }
            catch (TaskCanceledException)
            {
                if (downloadPath != null && File.Exists(downloadPath))
                {
                    File.Delete(downloadPath);
                }
            }
            catch (Exception e)
            {
                if (!retried)
                {
                    Restart();
                    retried = true;
                }
                else
                {
                    HandleError(e, downloadPath);
                }
            }
        }
Exemple #19
0
        public static async void GetTrendingTags(this PixivClient _)
        {
            var result = await HttpClientFactory.AppApiService().GetTrendingTags();

            foreach (var tag in result.TrendTags)
            {
                AppContext.TrendingTags.Add(new TrendingTag
                {
                    Tag            = tag.TagStr,
                    TranslatedName = tag.TranslatedName,
                    Thumbnail      = tag.Illust.ImageUrls.SquareMedium
                });
            }
        }
 private void ChangeSource()
 {
     Task.Run(() =>
     {
         (Dispatcher ?? throw new InvalidOperationException()).Invoke(async() =>
         {
             MainWindow.Instance.IllustBrowserDialogHost.DataContext = Illust;
             var userInfo = await HttpClientFactory.AppApiService().GetUserInformation(new UserInformationRequest {
                 Id = Illust.UserId
             });
             SetImageSource(MainWindow.Instance.IllustBrowserUserAvatar, await PixivIO.FromUrl(userInfo.UserEntity.ProfileImageUrls.Medium));
         });
     });
 }
Exemple #21
0
        public static async Task <List <TrendingTag> > GetTrendingTags(this PixivClient _)
        {
            var result = await HttpClientFactory.AppApiService().GetTrendingTags();

            var list = new List <TrendingTag>();

            if (result is { } res)
            {
                list.AddRange(res.TrendTags.Select(tag => new TrendingTag {
                    Tag = tag.TagStr, TranslatedName = tag.TranslatedName, Thumbnail = tag.Illust.ImageUrls.SquareMedium
                }));
            }
            return(list);
        }
        public async void OpenIllustBrowser(Illustration illustration)
        {
            IllustBrowserDialogHost.DataContext = illustration;
            await Task.Delay(100);

            IllustBrowserDialogHost.OpenControl();
            var userInfo = await HttpClientFactory.AppApiService().GetUserInformation(new UserInformationRequest {
                Id = illustration.UserId
            });

            if (await PixivIO.FromUrl(userInfo.UserEntity.ProfileImageUrls.Medium) is { } avatar)
            {
                SetImageSource(IllustBrowserUserAvatar, avatar);
            }
        }
        public static async Task <List <Volumelist> > GetBookDir(this SFClient _, int NovelID)
        {
            var result = await HttpClientFactory.AppApiService().GetNovelDirResponse(NovelID.ToString());

            var list = new List <Volumelist>();

            if (result is { } res)
            {
                list.AddRange(res.data.volumeList.Select(p => new Volumelist {
                    Chapterlist = p.chapterList.ToChapterItem(),
                    Sno         = p.sno,
                    Title       = p.title,
                    VolumeId    = p.volumeId
                }));
            }
            return(list);
        }
        public static async Task <List <SpecialPushItem> > GetSpecialPush(this SFClient _)
        {
            var result = await HttpClientFactory.AppApiService().GetSpecialPushResponse();

            var list = new List <SpecialPushItem>();

            if (result is { } res)
            {
                list.AddRange(res.data.homePush.Select(book => new SpecialPushItem()
                {
                    ImgUrl = book.imgUrl,
                    Link   = book.link,
                    Type   = book.type
                }));
            }
            return(list);
        }
        private async void DownloadGif()
        {
            var path = Path.Combine(Directory.CreateDirectory(AppContext.DownloadPathProvider.GetIllustrationPath()).FullName, AppContext.FileNameFormatter.FormatGif(DownloadContent));

            try
            {
                var metadata = await HttpClientFactory.AppApiService().GetUgoiraMetadata(DownloadContent.Id);

                var ugoiraUrl = metadata.UgoiraMetadataInfo.ZipUrls.Medium;
                ugoiraUrl = !ugoiraUrl.EndsWith("ugoira1920x1080.zip") ? Regex.Replace(ugoiraUrl, "ugoira(\\d+)x(\\d+).zip", "ugoira1920x1080.zip") : ugoiraUrl;
                var delay = metadata.UgoiraMetadataInfo.Frames.Select(f => f.Delay / 10).ToArray();
                if (cancellationTokenSource.IsCancellationRequested)
                {
                    return;
                }
                await using var memory = await PixivIOHelper.Download(ugoiraUrl, new Progress <double>(d => Progress = d), cancellationTokenSource.Token);

                await using var gifStream = (MemoryStream)PixivIOHelper.MergeGifStream(PixivIOHelper.ReadGifZipEntries(memory), delay);
                if (cancellationTokenSource.IsCancellationRequested)
                {
                    return;
                }
                await using var fileStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
                gifStream.WriteTo(fileStream);
                Application.Current.Invoke(() => DownloadFinished?.Invoke(this));
            }
            catch (TaskCanceledException)
            {
                if (path != null && File.Exists(path))
                {
                    File.Delete(path);
                }
            }
            catch (Exception e)
            {
                if (!retried)
                {
                    Restart();
                    retried = true;
                }
                else
                {
                    HandleError(e, path);
                }
            }
        }
        public static async Task <BookInfo> GetBookInfo(this SFClient _, string NovelID)
        {
            var result = await HttpClientFactory.AppApiService().GetNovelInfoResponse(NovelID);

            return(new BookInfo()
            {
                AuthorName = result.data.authorName,
                ImgUrl = result.data.novelCover,
                AuthorUrl = await GetAuthorAvatar(_, result.data.authorId),
                Intro = result.data.expand.intro,
                IsNeedVIP = result.data.signStatus.ToLower().IndexOf("vip") >= 0,
                LatestString = result.data.expand.latestChapter.addTime.ToString() + "    " + result.data.expand.latestChapter.title,
                MarkCount = result.data.markCount.ToString(),
                Point = (int)(result.data.point / 2),
                TicketCount = result.data.expand.ticket.ToString(),
                Title = result.data.novelName,
                TypeString = result.data.expand.typeName + "/" + ((!result.data.isFinish) ? "连载中" : "已完结"),
                Like = result.data.expand.fav
            });
        }
        public static async Task <List <HotPushItem> > GetComicsHotPush(this SFClient _)
        {
            var result = await HttpClientFactory.AppApiService().GetComicsHotPushResponse();

            var list = new List <HotPushItem>();

            if (result is { } res)
            {
                list.AddRange(res.data.Select(book => new HotPushItem()
                {
                    CoverUrl    = book.comicCover,
                    Title       = book.comicName,
                    NovelID     = book.comicId,
                    AuthorName  = book.comicName,
                    IsSerialize = (!book.isFinished)? "Visiable" : "Collapsed",
                    IsSign      = "Collapsed"
                }));
            }
            return(list);
        }
        public static async Task <List <ChatLineItem> > GetChapChatline(this SFClient _, int ChapID)
        {
            var result = await HttpClientFactory.AppApiService().GetChapDetailResponse(ChapID.ToString());

            var list = new List <ChatLineItem>();

            if (result is { } res)
            {
                list.AddRange(res.data.expand.chatLines.Select(p => new ChatLineItem()
                {
                    Avatar     = p.avatar,
                    CharId     = p.charId,
                    CharName   = p.charName,
                    Content    = p.content.FormatUnalbeShowChar(),
                    Image      = p.image,
                    ChatType   = (p.charType == 0 && !p.avatar.IsNullOrEmpty()) ? "Left" : (!p.avatar.IsNullOrEmpty() ? "Right" : "Center"),
                    IsShowChip = (p.avatar.IsNullOrEmpty()) ? "Collapsed" : "Visiable"
                }));
            }
            return(list);
        }
        public static async Task <List <BookItem> > SearchChatNovels(this SFClient _, string keyword)
        {
            var result = await HttpClientFactory.AppApiService().SearchChatNovel(keyword);

            var list = new List <BookItem>();

            if (result is { } res)
            {
                list.AddRange(res.data.novels.Select(book => new BookItem()
                {
                    CoverUrl    = book.novelCover,
                    Title       = book.novelName,
                    Tags        = book.expand.sysTags.ToTags(),
                    NovelID     = book.novelId,
                    AuthorName  = book.authorName,
                    charCount   = book.charCount.ToString(),
                    IsSerialize = (!book.isFinish) ? "Visiable" : "Collapsed",
                    IsSign      = (book.signStatus == "签约") ? "Visiable" : "Collapsed",
                    IsChatNovel = true
                }));
            }
            return(list);
        }
        private async void SetUserBrowserContext(User user)
        {
            var usr = await HttpClientFactory.AppApiService().GetUserInformation(new UserInformationRequest {
                Id = $"{user.Id}"
            });

            var usrEntity = new User
            {
                Avatar       = usr.UserEntity.ProfileImageUrls.Medium,
                Background   = usr.UserEntity.ProfileImageUrls.Medium,
                Follows      = (int)usr.UserProfile.TotalFollowUsers,
                Id           = usr.UserEntity.Id.ToString(),
                Introduction = usr.UserEntity.Comment,
                IsFollowed   = usr.UserEntity.IsFollowed,
                IsPremium    = usr.UserProfile.IsPremium,
                Name         = usr.UserEntity.Name,
                Thumbnails   = user.Thumbnails
            };

            UserBrowserPageScrollViewer.DataContext = usrEntity;
            SetUserBanner(usrEntity.Id);
            SetImageSource(UserBrowserUserAvatar, await PixivIO.FromUrl(usrEntity.Avatar));
            SetupUserUploads(usrEntity.Id);
        }