Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.

Commit

Permalink
完成GetUgoiraAsync(未测试)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiichiamane committed May 21, 2019
1 parent cb6bfd4 commit 3c7cd19
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 19 deletions.
10 changes: 4 additions & 6 deletions PixivFSUWP/Data/OverAll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,16 @@ public static async Task<string> GetDataUri(string Uri)
public static async Task<BitmapImage> LoadImageAsync(string Uri)
{
var toret = new BitmapImage();
var memStream = await DownloadImage(Uri);
await toret.SetSourceAsync(memStream.AsRandomAccessStream());
memStream.Dispose();
using (var memStream = await DownloadImage(Uri))
await toret.SetSourceAsync(memStream.AsRandomAccessStream());
return toret;
}

public static async Task<WriteableBitmap> LoadImageAsync(string Uri, int Width, int Height)
{
var toret = new WriteableBitmap(Width, Height);
var memStream = await DownloadImage(Uri);
await toret.SetSourceAsync(memStream.AsRandomAccessStream());
memStream.Dispose();
using (var memStream = await DownloadImage(Uri))
await toret.SetSourceAsync(memStream.AsRandomAccessStream());
return toret;
}

Expand Down
57 changes: 57 additions & 0 deletions PixivFSUWP/Data/UgoiraHelper.cs
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;
}
}
}
12 changes: 0 additions & 12 deletions PixivFSUWP/Data/UgoriaHelper.cs

This file was deleted.

2 changes: 1 addition & 1 deletion PixivFSUWP/PixivFSUWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
<Compile Include="Data\RecommendIllustsCollection.cs" />
<Compile Include="Data\OverAll.cs" />
<Compile Include="Data\Ugoira.cs" />
<Compile Include="Data\UgoriaHelper.cs" />
<Compile Include="Data\UgoiraHelper.cs" />
<Compile Include="Data\UserDetail.cs" />
<Compile Include="Data\UserIllustsCollection.cs" />
<Compile Include="Data\WaterfallItem.cs" />
Expand Down

0 comments on commit 3c7cd19

Please sign in to comment.