Beispiel #1
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
        }
        private async void IllustBrowserDialogHost_OnDialogOpened(object sender, DialogOpenedEventArgs e)
        {
            var context = sender.GetDataContext <Illustration>();

            var list = new ObservableCollection <TransitionerSlide>();

            var template = new IllustTransitioner(list);

            IllustBrowserContainer.Children.Insert(1, template);

            if (context.IsManga)
            {
                if (context.MangaMetadata.IsNullOrEmpty())
                {
                    context = await PixivHelper.IllustrationInfo(context.Id);
                }

                var tasks = await Tasks <Illustration, (BitmapImage image, Illustration illust)> .Of(context.MangaMetadata)
                            .Mapping(illustration => Task.Run(async() => (await PixivIO.FromUrl(illustration.Large), illustration)))
                            .Construct()
                            .WhenAll();

                list.AddRange(tasks.Select(i => InitTransitionerSlide(i.image, i.illust)));
            }
            else
            {
                list.Add(InitTransitionerSlide(await PixivIO.FromUrl(context.Large), context));
            }
        }
Beispiel #3
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);
        }
Beispiel #4
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);
            }
        }
Beispiel #5
0
 private async void TrendingTagThumbnail_OnLoaded(object sender, RoutedEventArgs e)
 {
     if (await PixivIO.FromUrl(sender.GetDataContext <TrendingTag>().Thumbnail) is { } image)
     {
         SetImageSource(sender, image);
     }
 }
Beispiel #6
0
        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);
            SetUserBanner(usrEntity.Id);
            SetImageSource(UserBrowserUserAvatar, await PixivIO.FromUrl(usrEntity.Avatar));

            SetupUserUploads(usrEntity.Id);
        }
 private async Task AddUserNameAndAvatar()
 {
     if (!Identity.Global.AvatarUrl.IsNullOrEmpty() && !Identity.Global.Name.IsNullOrEmpty())
     {
         UserName.Text     = Identity.Global.Name;
         UserAvatar.Source = await PixivIO.FromUrl(Identity.Global.AvatarUrl);
     }
 }
Beispiel #8
0
 private async Task AddUserNameAndAvatar()
 {
     if (!Session.Current.AvatarUrl.IsNullOrEmpty() && !Session.Current.Name.IsNullOrEmpty())
     {
         UserName.Text     = Session.Current.Name;
         UserAvatar.Source = await PixivIO.FromUrl(Session.Current.AvatarUrl);
     }
 }
Beispiel #9
0
        private async void ReferUserAvatar_OnLoaded(object sender, RoutedEventArgs e)
        {
            var trend = sender.GetDataContext <Trends>();

            if (trend.IsReferToUser)
            {
                SetImageSource(sender, await PixivIO.FromUrl(trend.TrendObjectThumbnail));
            }
        }
Beispiel #10
0
        private async void LoadThumbnail()
        {
            var imgSource = await PixivIO.FromUrl(Illust.Thumbnail);

            if (ImgSource == null)
            {
                Dispatcher.Invoke(() => ImgSource = imgSource);
            }
        }
        private async void BrowsingHistoryAvatarImage_OnLoaded(object sender, RoutedEventArgs e)
        {
            var browsing = sender.GetDataContext <BrowsingHistory>();

            if (browsing.IsReferToUser)
            {
                UiHelper.SetImageSource(sender, await PixivIO.FromUrl(browsing.BrowseObjectThumbnail));
            }
        }
        // 3/10/2020 I wish that we could both be there
        public async void Download()
        {
            if (DownloadContent.IsUgoira)
            {
                DownloadGif();
                return;
            }

            string path = null;

            try
            {
                await using var memory = await PixivIO.Download(DownloadContent.GetDownloadUrl(), new Progress <double>(d => Progress = d), cancellationTokenSource.Token);

                if (DownloadContent.FromSpotlight)
                {
                    path = IsFromManga
                        ? Path.Combine(Directory.CreateDirectory(AppContext.DownloadPathProvider.GetSpotlightPath(DownloadContent.SpotlightTitle)).FullName, DownloadContent.Id, AppContext.FileNameFormatter.FormatManga(DownloadContent, MangaIndex))
                        : Path.Combine(Directory.CreateDirectory(AppContext.DownloadPathProvider.GetSpotlightPath(DownloadContent.SpotlightTitle)).FullName, AppContext.FileNameFormatter.Format(DownloadContent));
                }
                else if (IsFromManga)
                {
                    path = Path.Combine(Directory.CreateDirectory(AppContext.DownloadPathProvider.GetMangaPath(DownloadContent.Id)).FullName, AppContext.FileNameFormatter.FormatManga(DownloadContent, MangaIndex));
                }
                else
                {
                    path = Path.Combine(Directory.CreateDirectory(AppContext.DownloadPathProvider.GetIllustrationPath()).FullName, AppContext.FileNameFormatter.Format(DownloadContent));
                }
                if (cancellationTokenSource.IsCancellationRequested)
                {
                    return;
                }
                await using var fileStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
                memory.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);
                }
            }
        }
Beispiel #13
0
        private async void LoadOrigin()
        {
            LoadingOrigin = true;
            var progress = new Progress <double>(p => Dispatcher.Invoke(() => LoadingIndicator = p));

            await using var mem = await PixivIO.Download(Illust.GetDownloadUrl(), progress, cancellationTokenSource.Token);

            ImgSource     = InternalIO.CreateBitmapImageFromStream(mem);
            LoadingOrigin = false;
            ((BlurEffect)ContentImage.Effect).Radius = 0;
        }
Beispiel #14
0
        private async void Thumbnail_OnLoaded(object sender, RoutedEventArgs e)
        {
            var dataContext = sender.GetDataContext <Illustration>();

            if (dataContext != null && Uri.IsWellFormedUriString(dataContext.Thumbnail, UriKind.Absolute))
            {
                SetImageSource(sender, await PixivIO.FromUrl(dataContext.Thumbnail));
            }

            StartDoubleAnimationUseCubicEase(sender, "(Image.Opacity)", 0, 1, 500);
        }
        private async void BrowsingHistoryMainImage_OnLoaded(object sender, RoutedEventArgs e)
        {
            var browsing = sender.GetDataContext <BrowsingHistory>();
            var img      = (Image)sender;

            if (browsing.IsReferToUser)
            {
                img.Effect = new BlurEffect {
                    KernelType = KernelType.Gaussian, Radius = 50, RenderingBias = RenderingBias.Quality
                };
            }
            UiHelper.SetImageSource(img, await PixivIO.FromUrl(browsing.BrowseObjectThumbnail));
        }
        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);
                }
            }
        }
        public async void Download()
        {
            if (!modifiable)
            {
                return;
            }

            DownloadState.Value = DownloadStateEnum.Downloading;
            var downloadPath = GetPath();

            if (DownloadContent.IsUgoira)
            {
                DownloadGif();
                return;
            }

            try
            {
                await using var memory = await PixivIO.Download(DownloadContent.GetDownloadUrl(),
                                                                new Progress <double>(d => Progress = d),
                                                                cancellationTokenSource.Token);

                if (cancellationTokenSource.IsCancellationRequested)
                {
                    return;
                }
                await using var fileStream = new FileStream(downloadPath, FileMode.OpenOrCreate, FileAccess.ReadWrite,
                                                            FileShare.None);
                memory.WriteTo(fileStream);
                DownloadState.Value = DownloadStateEnum.Finished;
            }
            catch (OperationCanceledException)
            {
                if (downloadPath != null && File.Exists(downloadPath))
                {
                    File.Delete(downloadPath);
                }
            }
            catch (Exception e)
            {
                if (!retried)
                {
                    Restart();
                    retried = true;
                }
                else
                {
                    HandleError(e, downloadPath);
                }
            }
        }
Beispiel #18
0
        private async void OpenIllustBrowser(Illustration illustration)
        {
            IllustBrowserDialogHost.DataContext = illustration;

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

            var avatar = await PixivIO.FromUrl(userInfo.UserEntity.ProfileImageUrls.Medium);

            if (avatar != null)
            {
                SetImageSource(IllustBrowserUserAvatar, avatar);
            }
        }
Beispiel #19
0
 private void SetUserBanner(string id)
 {
     Task.Run(async() =>
     {
         try
         {
             SetImageSource(UserBanner, await PixivIO.FromUrl((await HttpClientFactory.WebApiService().GetWebApiUserDetail(id)).ResponseBody.UserDetails.CoverImage.ProfileCoverImage.The720X360));
         }
         catch
         {
             /* ignore */
         }
     });
 }
Beispiel #20
0
 public async void SetImages(BitmapImage left, BitmapImage center, BitmapImage right)
 {
     UiHelper.SetImageSource(ImgLeft, left);
     UiHelper.SetImageSource(ImgCenter, center);
     UiHelper.SetImageSource(ImgRight, right);
     UiHelper.SetImageSource(UserAvatar, await PixivIO.FromUrl(this.GetDataContext <User>().Avatar));
     try
     {
         UiHelper.SetImageSource(Banner, await PixivIO.FromUrl((await HttpClientFactory.WebApiService.GetWebApiUserDetail(this.GetDataContext <User>().Id)).ResponseBody.UserDetails.CoverImage.ProfileCoverImage.The720X360));
     }
     catch
     {
         /* ignore */
     }
 }
Beispiel #21
0
        private async void ReferImage_OnLoaded(object sender, RoutedEventArgs e)
        {
            var trend = sender.GetDataContext <Trends>();
            var img   = (Image)sender;

            if (trend.IsReferToUser)
            {
                img.Effect = new BlurEffect {
                    KernelType = KernelType.Gaussian, Radius = 50, RenderingBias = RenderingBias.Quality
                }
            }
            ;

            SetImageSource(sender, await PixivIO.FromUrl(trend.TrendObjectThumbnail));
        }
Beispiel #22
0
        private void SetUserBanner(string id)
        {
            Task.Run(async() =>
            {
                var link       = $"https://public-api.secure.pixiv.net/v1/users/{id}/works.json?page=1&publicity=public&per_page=1&image_sizes=large";
                var httpClient = HttpClientFactory.PixivApi(ProtocolBase.PublicApiBaseUrl, Settings.Global.DirectConnect);
                httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", "Bearer");

                var res = (await httpClient.GetStringAsync(link)).FromJson <dynamic>();
                if (((IEnumerable <JToken>)res.response).Any())
                {
                    var img = res.response[0].image_urls.large.ToString();
                    SetImageSource(UserBanner, await PixivIO.FromUrl(img));
                }
            });
        }
        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 PixivIO.Download(ugoiraUrl, new Progress <double>(d => Progress = d), cancellationTokenSource.Token);

                await using var gifStream = (MemoryStream)PixivIO.MergeGifStream(PixivIO.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);
                }
            }
        }
Beispiel #24
0
        private async void UserPrevItem_OnLoaded(object sender, RoutedEventArgs e)
        {
            var(avatar, thumbnails) = GetUserPrevImageControls(sender);
            var dataContext = sender.GetDataContext <User>();

            SetImageSource(avatar, await PixivIO.FromUrl(dataContext.Avatar));

            var counter = 0;

            foreach (var thumbnail in thumbnails)
            {
                if (counter < dataContext.Thumbnails.Length)
                {
                    SetImageSource(thumbnail, await PixivIO.FromUrl(dataContext.Thumbnails[counter++]));
                }
            }
        }
 private void ChangeSource()
 {
     Task.Run(async() =>
     {
         var userInfo = await HttpClientFactory.AppApiService.GetUserInformation(new UserInformationRequest {
             Id = Illust.UserId
         });
         if (Dispatcher.Invoke(() => Illust.UserId != MainWindow.Instance.IllustBrowserDialogHost.GetDataContext <Illustration>().UserId))
         {
             var img = await PixivIO.FromUrl(userInfo.UserEntity.ProfileImageUrls.Medium);
             Dispatcher.Invoke(() =>
             {
                 SetImageSource(MainWindow.Instance.IllustBrowserUserAvatar, img);
                 MainWindow.Instance.IllustBrowserDialogHost.DataContext = Illust;
             });
         }
     });
 }
Beispiel #26
0
 private void ChangeSource()
 {
     Task.Run(() =>
     {
         (Dispatcher ?? throw new InvalidOperationException()).Invoke(async() =>
         {
             var userInfo = await HttpClientFactory.AppApiService()
                            .GetUserInformation(new UserInformationRequest {
                 Id = Illust.UserId
             });
             if (Illust.UserId ==
                 MainWindow.Instance.IllustBrowserDialogHost.GetDataContext <Illustration>()
                 .UserId)
             {
                 SetImageSource(MainWindow.Instance.IllustBrowserUserAvatar,
                                await PixivIO.FromUrl(userInfo.UserEntity.ProfileImageUrls.Medium));
             }
             MainWindow.Instance.IllustBrowserDialogHost.DataContext = Illust;
         });
     });
 }
        private async void DownloadItemThumbnail_OnLoaded(object sender, RoutedEventArgs e)
        {
            var url = sender.GetDataContext <DownloadableIllustration>().DownloadContent.Thumbnail;

            UiHelper.SetImageSource(sender, await PixivIO.FromUrl(url));
        }
Beispiel #28
0
 private async void SpotlightThumbnail_OnLoaded(object sender, RoutedEventArgs e)
 {
     SetImageSource((Image)sender, await PixivIO.FromUrl(sender.GetDataContext <SpotlightArticle>().Thumbnail));
 }
Beispiel #29
0
        private async void RecommendIllustratorAvatar_OnLoaded(object sender, RoutedEventArgs e)
        {
            var context = sender.GetDataContext <User>();

            SetImageSource(sender, await PixivIO.FromUrl(context.Avatar));
        }
Beispiel #30
0
 private async void PostUserAvatar_OnLoaded(object sender, RoutedEventArgs e)
 {
     SetImageSource(sender, await PixivIO.FromUrl(sender.GetDataContext <Trends>().PostUserThumbnail));
 }