Added download cover functionality
This commit is contained in:
parent
f92bcebe04
commit
c283cbd9a9
@ -30,6 +30,9 @@ public static class Tranga_Cli
|
|||||||
Chapter[] allChapteres = connector.GetChapters(selectedPub, "en");
|
Chapter[] allChapteres = connector.GetChapters(selectedPub, "en");
|
||||||
Chapter[] downloadChapters = SelectChapters(allChapteres);
|
Chapter[] downloadChapters = SelectChapters(allChapteres);
|
||||||
|
|
||||||
|
if(downloadChapters.Length > 0)
|
||||||
|
connector.DownloadCover(selectedPub);
|
||||||
|
|
||||||
foreach (Chapter chapter in downloadChapters)
|
foreach (Chapter chapter in downloadChapters)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Downloading {selectedPub.sortName} V{chapter.volumeNumber}C{chapter.chapterNumber}");
|
Console.WriteLine($"Downloading {selectedPub.sortName} V{chapter.volumeNumber}C{chapter.chapterNumber}");
|
||||||
|
@ -16,6 +16,7 @@ public abstract class Connector
|
|||||||
public abstract Chapter[] GetChapters(Publication publication, string language = "");
|
public abstract Chapter[] GetChapters(Publication publication, string language = "");
|
||||||
public abstract void DownloadChapter(Publication publication, Chapter chapter); //where to?
|
public abstract void DownloadChapter(Publication publication, Chapter chapter); //where to?
|
||||||
protected abstract void DownloadImage(string url, string savePath);
|
protected abstract void DownloadImage(string url, string savePath);
|
||||||
|
public abstract void DownloadCover(Publication publication);
|
||||||
|
|
||||||
internal void DownloadChapter(string[] imageUrls, string saveArchiveFilePath)
|
internal void DownloadChapter(string[] imageUrls, string saveArchiveFilePath)
|
||||||
{
|
{
|
||||||
|
@ -3,8 +3,6 @@ using System.Text.Json;
|
|||||||
using System.Text.Json.Nodes;
|
using System.Text.Json.Nodes;
|
||||||
|
|
||||||
namespace Tranga.Connectors;
|
namespace Tranga.Connectors;
|
||||||
//TODO Download covers: https://api.mangadex.org/docs/retrieving-covers/ https://api.mangadex.org/docs/swagger.html#/
|
|
||||||
|
|
||||||
public class MangaDex : Connector
|
public class MangaDex : Connector
|
||||||
{
|
{
|
||||||
public override string name { get; }
|
public override string name { get; }
|
||||||
@ -190,4 +188,22 @@ public class MangaDex : Connector
|
|||||||
requestResult.result.ReadExactly(buffer, 0, buffer.Length);
|
requestResult.result.ReadExactly(buffer, 0, buffer.Length);
|
||||||
File.WriteAllBytes(savePath, buffer);
|
File.WriteAllBytes(savePath, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void DownloadCover(Publication publication)
|
||||||
|
{
|
||||||
|
DownloadClient.RequestResult requestResult = _downloadClient.MakeRequest($"https://uploads.mangadex.org/cover/{publication.posterUrl}");
|
||||||
|
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
||||||
|
if (result is null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
string fileName = result!["data"]!["attributes"]!["fileName"]!.GetValue<string>();
|
||||||
|
|
||||||
|
string coverUrl = $"https://uploads.mangadex.org/covers/{publication.downloadUrl}/{fileName}";
|
||||||
|
string[] split = coverUrl.Split('.');
|
||||||
|
string extension = split[split.Length - 1];
|
||||||
|
|
||||||
|
string outFolderPath = Path.Join(downloadLocation, publication.folderName);
|
||||||
|
Directory.CreateDirectory(outFolderPath);
|
||||||
|
DownloadImage(coverUrl, Path.Join(downloadLocation, publication.folderName, $"cover.{extension}"));
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user