Added Image download and compression to archive to Connector.
This commit is contained in:
parent
c3cb4d6e08
commit
b54ac730b7
@ -1,4 +1,5 @@
|
|||||||
using System.Net;
|
using System.IO.Compression;
|
||||||
|
using System.Net;
|
||||||
|
|
||||||
namespace Tranga;
|
namespace Tranga;
|
||||||
|
|
||||||
@ -9,10 +10,16 @@ public abstract class Connector
|
|||||||
public abstract Publication[] GetPublications(string publicationTitle = "");
|
public abstract Publication[] GetPublications(string publicationTitle = "");
|
||||||
public abstract Chapter[] GetChapters(Publication publication);
|
public abstract Chapter[] GetChapters(Publication publication);
|
||||||
public abstract void DownloadChapter(Publication publication, Chapter chapter); //where to?
|
public abstract void DownloadChapter(Publication publication, Chapter chapter); //where to?
|
||||||
|
internal abstract void DownloadImage(string url, string path);
|
||||||
|
|
||||||
internal void DownloadChapter(string url)
|
internal void DownloadChapterImage(string url, string outputFolder)
|
||||||
{
|
{
|
||||||
|
string tempFolder = Path.GetTempFileName();
|
||||||
|
File.Delete(tempFolder);
|
||||||
|
Directory.CreateDirectory(tempFolder);
|
||||||
|
|
||||||
|
DownloadImage(url, tempFolder);
|
||||||
|
ZipFile.CreateFromDirectory(tempFolder, $"{outputFolder}.cbz");
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class DownloadClient
|
internal class DownloadClient
|
||||||
|
@ -161,6 +161,18 @@ public class MangaDex : Connector
|
|||||||
imageFileNames.Add(imageFileNameObject!.GetValue<string>());
|
imageFileNames.Add(imageFileNameObject!.GetValue<string>());
|
||||||
|
|
||||||
foreach(string imageFileName in imageFileNames)
|
foreach(string imageFileName in imageFileNames)
|
||||||
DownloadChapter($"{baseUrl}/{hash}/imageFileName");
|
DownloadChapterImage($"{baseUrl}/{hash}/{imageFileName}", Path.Join(downloadLocation, publication.sortName));
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override void DownloadImage(string url, string path)
|
||||||
|
{
|
||||||
|
DownloadClient.RequestResult requestResult = _downloadClient.GetPage(url);
|
||||||
|
FileStream fs = new FileStream(path, FileMode.CreateNew);
|
||||||
|
Span<byte> buffer = new();
|
||||||
|
while (requestResult.result.CanRead)
|
||||||
|
{
|
||||||
|
_ = requestResult.result.Read(buffer);
|
||||||
|
fs.Write(buffer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user