public static async Task <Ugoira> GetUgoiraAsync(string IllustID) { List <string> framefiles = new List <string>(); Dictionary <string, int> framedelays = new Dictionary <string, int>(); Dictionary <string, SoftwareBitmap> frameimgs = new Dictionary <string, SoftwareBitmap>(); try { var res = await new PixivAppAPI(OverAll.GlobalBaseAPI).UgoiraMetadata(IllustID); if (res.Stringify().Contains("error")) { return(null); } var framesarray = res["ugoira_metadata"].GetObject()["frames"].GetArray(); foreach (var i in framesarray) { var file = i.GetObject()["file"].GetString(); framefiles.Add(file); framedelays.Add(file, (int)i.GetObject()["delay"].GetNumber()); } var zipurl = res["ugoira_metadata"].GetObject()["zip_urls"].GetObject()["medium"].GetString(); using (var zipfile = await OverAll.DownloadImage(zipurl)) { using (ZipArchive ziparc = new ZipArchive(zipfile, ZipArchiveMode.Read)) { foreach (var entry in ziparc.Entries) { var file = entry.FullName; using (var memStream = new MemoryStream()) { await entry.Open().CopyToAsync(memStream); memStream.Position = 0; BitmapDecoder decoder = await BitmapDecoder.CreateAsync(memStream.AsRandomAccessStream()); frameimgs.Add(file, await decoder.GetSoftwareBitmapAsync()); } } } } Ugoira toret = new Ugoira(); foreach (var i in framefiles) { toret.Frames.Add(new Ugoira.Frame() { Image = frameimgs[i], Delay = framedelays[i] }); } return(toret); } finally { framefiles.Clear(); framedelays.Clear(); frameimgs.Clear(); } }
private async Task loadContent() { try { _busy = true; txtTitle.Text = GetResourceString("LoadingPlain"); iconView.Visibility = Visibility.Collapsed; iconStar.Visibility = Visibility.Collapsed; stkAuthor.Visibility = Visibility.Collapsed; var res = await new PixivAppAPI(Data.OverAll.GlobalBaseAPI) .IllustDetail(illustID.ToString()); ImageList.ItemsSource = new ObservableCollection <ViewModels.ImageItemViewModel>(); illust = Data.IllustDetail.FromJsonValue(res); imgAuthor.ImageSource = await Data.OverAll.LoadImageAsync(illust.AuthorAvatarUrl); txtTitle.Text = illust.Title; btnBookmark.IsChecked = illust.IsBookmarked; btnFollow.IsChecked = illust.IsUserFollowed; txtBtnBookmark.Text = illust.IsBookmarked ? GetResourceString("BookmarkedPlain") : GetResourceString("NotBookmarkedPlain"); txtBtnFollow.Text = illust.IsUserFollowed ? GetResourceString("FollowingPlain") : GetResourceString("NotFollowingPlain"); iconView.Visibility = Visibility.Visible; iconStar.Visibility = Visibility.Visible; stkAuthor.Visibility = Visibility.Visible; txtViewStatus.Text = illust.TotalView.ToString(); txtBookmarkStatus.Text = illust.TotalBookmarks.ToString(); txtAuthor.Text = illust.Author; txtAuthorAccount.Text = string.Format("@{0}", illust.AuthorAccount); txtCaption.Text = (illust.Caption == "") ? GetResourceString("NoCaptionPlain") : Regex.Replace(illust.Caption.Replace("<br />", "\n"), "<[^>]+>", ""); txtCommentTitle.Text = GetResourceString("CommentsPlain"); btnNewComment.Visibility = Visibility.Visible; listComments.ItemsSource = new CommentsCollection(illustID.ToString()); txtLoadingStatus.Text = GetResourceString("CreatingTimelinePlain"); AdaptiveCard card = new AdaptiveCard("1.1"); card.Body.Add(new AdaptiveTextBlock() { Text = illust.Title, Weight = AdaptiveTextWeight.Bolder, Size = AdaptiveTextSize.Large, Wrap = true, MaxLines = 3 }); card.Body.Add(new AdaptiveTextBlock() { Text = string.Format("by {0}", illust.Author), Size = AdaptiveTextSize.Default, Wrap = true, MaxLines = 3 }); var build = SystemInformation.OperatingSystemVersion.Build; if (build >= 18362) { var data = await Data.OverAll.GetDataUri(illust.MediumUrl); card.BackgroundImage = new AdaptiveBackgroundImage(new Uri(data)); } await Data.OverAll.GenerateActivityAsync(illust.Title, card, new Uri(string.Format("pixiv://illust?id={0}", illustID)), illustID.ToString()); if (illust.Type == "ugoira") { ugoiraPlayer.Visibility = Visibility.Visible; ImageList.Visibility = Visibility.Collapsed; btnPlay.IsEnabled = false; btnPlay.Visibility = Visibility.Visible; btnSaveGif.IsEnabled = false; btnSaveGif.Visibility = Visibility.Visible; txtLoadingStatus.Text = GetResourceString("LoadingPreviewPlain"); ugoiraPlayer.Source = await Data.OverAll.LoadImageAsync(illust.OriginalUrls[0]); txtLoadingStatus.Text = GetResourceString("DownloadingUgoiraPlain"); if (_emergencyStop) { return; } ugoira = await Data.UgoiraHelper.GetUgoiraAsync(illust.IllustID.ToString()); txtLoadingStatus.Text = GetResourceString("GeneratingGifPlain"); await playUgoira(); txtLoadingStatus.Text = GetResourceString("PlayingUgoiraPlain"); btnPlay.IsEnabled = true; btnSaveGif.IsEnabled = true; } else { int counter = 0; foreach (var i in illust.OriginalUrls) { if (_emergencyStop) { return; } txtLoadingStatus.Text = string.Format(GetResourceString("LoadingStatusPlain"), ++counter, illust.OriginalUrls.Count); (ImageList.ItemsSource as ObservableCollection <ViewModels.ImageItemViewModel>) .Add(new ViewModels.ImageItemViewModel() { ImageSource = await Data.OverAll.LoadImageAsync(i, 1, 1) }); } txtLoadingStatus.Text = string.Format(GetResourceString("PageInfoPlain"), illust.OriginalUrls.Count); } } finally { _busy = false; if (_emergencyStop) { (ImageList.ItemsSource as ObservableCollection <ViewModels.ImageItemViewModel>)?.Clear(); GC.Collect(); } } }