示例#1
0
文件: PixivEx.cs 项目: zsc319/Pixeval
        public static async Task DownloadManga(Illustration illustration, string rootPath)
        {
            if (!illustration.IsManga)
            {
                throw new InvalidOperationException();
            }

            var mangaDir = Directory.CreateDirectory(Path.Combine(rootPath, $"[{Texts.FormatPath(illustration.UserName)}]{illustration.Id}")).FullName;

            for (var i = 0; i < illustration.MangaMetadata.Length; i++)
            {
                var url = illustration.MangaMetadata[i].Origin.IsNullOrEmpty() ? illustration.MangaMetadata[i].Large : illustration.MangaMetadata[i].Origin;
                await File.WriteAllBytesAsync(Path.Combine(mangaDir, $"{i}{Texts.GetExtension(url)}"), await FromUrlInternal(url));
            }
        }
示例#2
0
        public static async Task DownloadUgoira(Illustration illustration, string rootPath)
        {
            if (!illustration.IsUgoira)
            {
                throw new InvalidOperationException();
            }

            var metadata = await HttpClientFactory.AppApiService.GetUgoiraMetadata(illustration.Id);

            var url = FormatGifZipUrl(metadata.UgoiraMetadataInfo.ZipUrls.Medium);

            await using var img = (MemoryStream) await GetGifStream(url, metadata.UgoiraMetadataInfo.Frames.Select (f => f.Delay / 10).ToList());

            await File.WriteAllBytesAsync(Path.Combine(rootPath, $"[{Texts.FormatPath(illustration.UserName)}]{illustration.Id}.gif"), await Task.Run(() => img.ToArray()));
        }
示例#3
0
文件: PixivEx.cs 项目: zsc319/Pixeval
        public static async Task DownloadIllust(Illustration illustration, string rootPath)
        {
            var path = Directory.CreateDirectory(rootPath).FullName;

            if (illustration.IsManga)
            {
                await DownloadManga(illustration, path);
            }
            else if (illustration.IsUgoira)
            {
                await DownloadUgoira(illustration, path);
            }
            else
            {
                var url = illustration.Origin.IsNullOrEmpty() ? illustration.Large : illustration.Origin;
                await File.WriteAllBytesAsync(Path.Combine(path, $"[{Texts.FormatPath(illustration.UserName)}]{illustration.Id}{Texts.GetExtension(url)}"), await FromUrlInternal(url));
            }
        }