This repository has been archived by the owner on Feb 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
tobiichiamane
committed
May 21, 2019
1 parent
cb6bfd4
commit 3c7cd19
Showing
4 changed files
with
62 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.IO.Compression; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using PixivCS; | ||
using Windows.UI.Xaml.Media.Imaging; | ||
|
||
namespace PixivFSUWP.Data | ||
{ | ||
public static class UgoiraHelper | ||
{ | ||
public static async Task<Ugoira> GetUgoiraAsync(string IllustID) | ||
{ | ||
var res = await new PixivAppAPI(OverAll.GlobalBaseAPI).UgoiraMetadata(IllustID); | ||
if (res.Stringify().Contains("error")) return null; | ||
List<string> framefiles = new List<string>(); | ||
Dictionary<string, int> framedelays = new Dictionary<string, int>(); | ||
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()); | ||
} | ||
Dictionary<string, BitmapImage> frameimgs = new Dictionary<string, BitmapImage>(); | ||
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; | ||
BitmapImage img = new BitmapImage(); | ||
using (var memStream = new MemoryStream()) | ||
{ | ||
memStream.Position = 0; | ||
await entry.Open().CopyToAsync(memStream); | ||
await img.SetSourceAsync(memStream.AsRandomAccessStream()); | ||
} | ||
frameimgs.Add(file, img); | ||
} | ||
} | ||
} | ||
Ugoira toret = new Ugoira(); | ||
foreach (var i in framefiles) | ||
toret.Frames.Add(new Ugoira.Frame() { Image = frameimgs[i], Delay = framedelays[i] }); | ||
framefiles.Clear(); | ||
framedelays.Clear(); | ||
frameimgs.Clear(); | ||
return toret; | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters