Compare commits
12 Commits
28218b6dab
...
3c1865de31
Author | SHA1 | Date | |
---|---|---|---|
3c1865de31 | |||
84542640dc | |||
a3520dfd77 | |||
68b40e087e | |||
1674d70995 | |||
ccbe8a95f8 | |||
78d8deb9de | |||
1d0883cbab | |||
7726259d19 | |||
dc97774587 | |||
26ef59ab42 | |||
1b59475254 |
@ -56,7 +56,7 @@ public static class Tranga_Cli
|
|||||||
publication = SelectPublication(connector);
|
publication = SelectPublication(connector);
|
||||||
TimeSpan reoccurrence = SelectReoccurrence();
|
TimeSpan reoccurrence = SelectReoccurrence();
|
||||||
taskManager.AddTask(task, connector.name, publication, reoccurrence, "en");
|
taskManager.AddTask(task, connector.name, publication, reoccurrence, "en");
|
||||||
Console.WriteLine($"{task} - {connector.name} - {publication?.sortName}");
|
Console.WriteLine($"{task} - {reoccurrence} - {publication?.sortName} - {connector.name}");
|
||||||
Console.WriteLine("Press any key.");
|
Console.WriteLine("Press any key.");
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
menu = 0;
|
menu = 0;
|
||||||
@ -68,7 +68,25 @@ public static class Tranga_Cli
|
|||||||
menu = 0;
|
menu = 0;
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
ExecuteTask(taskManager);
|
ExecuteTaskNow(taskManager);
|
||||||
|
Console.WriteLine("Press any key.");
|
||||||
|
Console.ReadKey();
|
||||||
|
menu = 0;
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
Console.WriteLine("Search-Query (Name):");
|
||||||
|
string? query = Console.ReadLine();
|
||||||
|
while (query is null || query.Length < 1)
|
||||||
|
query = Console.ReadLine();
|
||||||
|
PrintTasks(taskManager.GetAllTasks().Where(task =>
|
||||||
|
((Publication)task.publication!).sortName.ToLower()
|
||||||
|
.Contains(query, StringComparison.OrdinalIgnoreCase)).ToArray());
|
||||||
|
Console.WriteLine("Press any key.");
|
||||||
|
Console.ReadKey();
|
||||||
|
menu = 0;
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
PrintTasks(taskManager.GetAllTasks().Where(task => task.isBeingExecuted).ToArray());
|
||||||
Console.WriteLine("Press any key.");
|
Console.WriteLine("Press any key.");
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
menu = 0;
|
menu = 0;
|
||||||
@ -89,6 +107,15 @@ public static class Tranga_Cli
|
|||||||
case ConsoleKey.E:
|
case ConsoleKey.E:
|
||||||
menu = 4;
|
menu = 4;
|
||||||
break;
|
break;
|
||||||
|
case ConsoleKey.U:
|
||||||
|
menu = 0;
|
||||||
|
break;
|
||||||
|
case ConsoleKey.S:
|
||||||
|
menu = 5;
|
||||||
|
break;
|
||||||
|
case ConsoleKey.R:
|
||||||
|
menu = 6;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
menu = 0;
|
menu = 0;
|
||||||
break;
|
break;
|
||||||
@ -112,10 +139,13 @@ public static class Tranga_Cli
|
|||||||
int taskRunningCount = taskManager.GetAllTasks().Count(task => task.isBeingExecuted);
|
int taskRunningCount = taskManager.GetAllTasks().Count(task => task.isBeingExecuted);
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
Console.WriteLine($"Download Folder: {folderPath} Tasks (Running/Total): {taskRunningCount}/{taskCount}");
|
Console.WriteLine($"Download Folder: {folderPath} Tasks (Running/Total): {taskRunningCount}/{taskCount}");
|
||||||
|
Console.WriteLine("U: Update this Screen");
|
||||||
Console.WriteLine("L: List tasks");
|
Console.WriteLine("L: List tasks");
|
||||||
Console.WriteLine("C: Create Task");
|
Console.WriteLine("C: Create Task");
|
||||||
Console.WriteLine("D: Delete Task");
|
Console.WriteLine("D: Delete Task");
|
||||||
Console.WriteLine("E: Execute Task now");
|
Console.WriteLine("E: Execute Task now");
|
||||||
|
Console.WriteLine("S: Search Task");
|
||||||
|
Console.WriteLine("R: Running Tasks");
|
||||||
Console.WriteLine("Q: Exit");
|
Console.WriteLine("Q: Exit");
|
||||||
ConsoleKey selection = Console.ReadKey().Key;
|
ConsoleKey selection = Console.ReadKey().Key;
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
@ -133,7 +163,7 @@ public static class Tranga_Cli
|
|||||||
Console.WriteLine($"{tIndex++}: {trangaTask.task} - {trangaTask.reoccurrence} - {trangaTask.publication?.sortName} - {trangaTask.connectorName} - {trangaTask.lastExecuted} - {(trangaTask.isBeingExecuted ? "Running" : "Waiting")}");
|
Console.WriteLine($"{tIndex++}: {trangaTask.task} - {trangaTask.reoccurrence} - {trangaTask.publication?.sortName} - {trangaTask.connectorName} - {trangaTask.lastExecuted} - {(trangaTask.isBeingExecuted ? "Running" : "Waiting")}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ExecuteTask(TaskManager taskManager)
|
private static void ExecuteTaskNow(TaskManager taskManager)
|
||||||
{
|
{
|
||||||
TrangaTask[] tasks = taskManager.GetAllTasks();
|
TrangaTask[] tasks = taskManager.GetAllTasks();
|
||||||
if (tasks.Length < 1)
|
if (tasks.Length < 1)
|
||||||
@ -144,7 +174,7 @@ public static class Tranga_Cli
|
|||||||
}
|
}
|
||||||
PrintTasks(tasks);
|
PrintTasks(tasks);
|
||||||
|
|
||||||
Console.WriteLine($"Select Task (0-{tasks.Length}):");
|
Console.WriteLine($"Select Task (0-{tasks.Length - 1}):");
|
||||||
|
|
||||||
string? selectedTask = Console.ReadLine();
|
string? selectedTask = Console.ReadLine();
|
||||||
while(selectedTask is null || selectedTask.Length < 1)
|
while(selectedTask is null || selectedTask.Length < 1)
|
||||||
@ -165,7 +195,7 @@ public static class Tranga_Cli
|
|||||||
}
|
}
|
||||||
PrintTasks(tasks);
|
PrintTasks(tasks);
|
||||||
|
|
||||||
Console.WriteLine($"Select Task (0-{tasks.Length}):");
|
Console.WriteLine($"Select Task (0-{tasks.Length - 1}):");
|
||||||
|
|
||||||
string? selectedTask = Console.ReadLine();
|
string? selectedTask = Console.ReadLine();
|
||||||
while(selectedTask is null || selectedTask.Length < 1)
|
while(selectedTask is null || selectedTask.Length < 1)
|
||||||
@ -184,7 +214,7 @@ public static class Tranga_Cli
|
|||||||
Console.WriteLine("Available Tasks:");
|
Console.WriteLine("Available Tasks:");
|
||||||
foreach (string taskName in taskNames)
|
foreach (string taskName in taskNames)
|
||||||
Console.WriteLine($"{tIndex++}: {taskName}");
|
Console.WriteLine($"{tIndex++}: {taskName}");
|
||||||
Console.WriteLine($"Select Task (0-{taskNames.Length}):");
|
Console.WriteLine($"Select Task (0-{taskNames.Length - 1}):");
|
||||||
|
|
||||||
string? selectedTask = Console.ReadLine();
|
string? selectedTask = Console.ReadLine();
|
||||||
while(selectedTask is null || selectedTask.Length < 1)
|
while(selectedTask is null || selectedTask.Length < 1)
|
||||||
|
@ -23,6 +23,6 @@ public struct Chapter
|
|||||||
string chapterName = string.Concat((name ?? "").Split(Path.GetInvalidFileNameChars()));
|
string chapterName = string.Concat((name ?? "").Split(Path.GetInvalidFileNameChars()));
|
||||||
double multiplied = Convert.ToDouble(chapterNumber, new NumberFormatInfo() { NumberDecimalSeparator = "." }) *
|
double multiplied = Convert.ToDouble(chapterNumber, new NumberFormatInfo() { NumberDecimalSeparator = "." }) *
|
||||||
Convert.ToInt32(volumeNumber);
|
Convert.ToInt32(volumeNumber);
|
||||||
this.fileName = $"{chapterName} - V{volumeNumber}C{chapterNumber} - {multiplied}";
|
this.fileName = $"{chapterName} - V{volumeNumber}C{chapterNumber} - {multiplied.ToString(new NumberFormatInfo() { NumberDecimalSeparator = "." })}";
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,6 @@
|
|||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
namespace Tranga;
|
namespace Tranga;
|
||||||
|
|
||||||
@ -59,10 +60,22 @@ public abstract class Connector
|
|||||||
{
|
{
|
||||||
//Check if Publication already has a Folder and a series.json
|
//Check if Publication already has a Folder and a series.json
|
||||||
string publicationFolder = Path.Join(downloadLocation, publication.folderName);
|
string publicationFolder = Path.Join(downloadLocation, publication.folderName);
|
||||||
|
if(!Directory.Exists(publicationFolder))
|
||||||
Directory.CreateDirectory(publicationFolder);
|
Directory.CreateDirectory(publicationFolder);
|
||||||
|
|
||||||
string seriesInfoPath = Path.Join(publicationFolder, "series.json");
|
string seriesInfoPath = Path.Join(publicationFolder, "series.json");
|
||||||
if(!File.Exists(seriesInfoPath))
|
if(!File.Exists(seriesInfoPath))
|
||||||
File.WriteAllText(seriesInfoPath,publication.GetSeriesInfo());
|
File.WriteAllText(seriesInfoPath,publication.GetSeriesInfoJson());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string CreateComicInfo(Publication publication, Chapter chapter)
|
||||||
|
{
|
||||||
|
XElement comicInfo = new XElement("ComicInfo",
|
||||||
|
new XElement("Tags", string.Join(',',publication.tags)),
|
||||||
|
new XElement("LanguageISO", publication.originalLanguage),
|
||||||
|
new XElement("Title", chapter.name)
|
||||||
|
);
|
||||||
|
return comicInfo.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -85,7 +98,7 @@ public abstract class Connector
|
|||||||
/// <param name="imageUrls">List of URLs to download Images from</param>
|
/// <param name="imageUrls">List of URLs to download Images from</param>
|
||||||
/// <param name="saveArchiveFilePath">Full path to save archive to (without file ending .cbz)</param>
|
/// <param name="saveArchiveFilePath">Full path to save archive to (without file ending .cbz)</param>
|
||||||
/// <param name="downloadClient">DownloadClient of the connector</param>
|
/// <param name="downloadClient">DownloadClient of the connector</param>
|
||||||
protected static void DownloadChapterImages(string[] imageUrls, string saveArchiveFilePath, DownloadClient downloadClient)
|
protected static void DownloadChapterImages(string[] imageUrls, string saveArchiveFilePath, DownloadClient downloadClient, string? comicInfoPath = null)
|
||||||
{
|
{
|
||||||
//Check if Publication Directory already exists
|
//Check if Publication Directory already exists
|
||||||
string[] splitPath = saveArchiveFilePath.Split(Path.DirectorySeparatorChar);
|
string[] splitPath = saveArchiveFilePath.Split(Path.DirectorySeparatorChar);
|
||||||
@ -98,9 +111,7 @@ public abstract class Connector
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
//Create a temporary folder to store images
|
//Create a temporary folder to store images
|
||||||
string tempFolder = Path.GetTempFileName();
|
string tempFolder = Directory.CreateTempSubdirectory().FullName;
|
||||||
File.Delete(tempFolder);
|
|
||||||
Directory.CreateDirectory(tempFolder);
|
|
||||||
|
|
||||||
int chapter = 0;
|
int chapter = 0;
|
||||||
//Download all Images to temporary Folder
|
//Download all Images to temporary Folder
|
||||||
@ -111,6 +122,9 @@ public abstract class Connector
|
|||||||
DownloadImage(imageUrl, Path.Join(tempFolder, $"{chapter++}.{extension}"), downloadClient);
|
DownloadImage(imageUrl, Path.Join(tempFolder, $"{chapter++}.{extension}"), downloadClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(comicInfoPath is not null)
|
||||||
|
File.Copy(comicInfoPath, Path.Join(tempFolder, "ComicInfo.xml"));
|
||||||
|
|
||||||
//ZIP-it and ship-it
|
//ZIP-it and ship-it
|
||||||
ZipFile.CreateFromDirectory(tempFolder, fullPath);
|
ZipFile.CreateFromDirectory(tempFolder, fullPath);
|
||||||
Directory.Delete(tempFolder, true); //Cleanup
|
Directory.Delete(tempFolder, true); //Cleanup
|
||||||
|
@ -197,14 +197,18 @@ public class MangaDex : Connector
|
|||||||
foreach (JsonNode? image in imageFileNames)
|
foreach (JsonNode? image in imageFileNames)
|
||||||
imageUrls.Add($"{baseUrl}/data/{hash}/{image!.GetValue<string>()}");
|
imageUrls.Add($"{baseUrl}/data/{hash}/{image!.GetValue<string>()}");
|
||||||
|
|
||||||
|
string comicInfoPath = Path.GetTempFileName();
|
||||||
|
File.WriteAllText(comicInfoPath, CreateComicInfo(publication, chapter));
|
||||||
|
|
||||||
//Download Chapter-Images
|
//Download Chapter-Images
|
||||||
DownloadChapterImages(imageUrls.ToArray(), Path.Join(downloadLocation, publication.folderName, chapter.fileName), this.downloadClient);
|
DownloadChapterImages(imageUrls.ToArray(), Path.Join(downloadLocation, publication.folderName, chapter.fileName), this.downloadClient, comicInfoPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void DownloadCover(Publication publication)
|
public override void DownloadCover(Publication publication)
|
||||||
{
|
{
|
||||||
//Check if Publication already has a Folder and cover
|
//Check if Publication already has a Folder and cover
|
||||||
string publicationFolder = Path.Join(downloadLocation, publication.folderName);
|
string publicationFolder = Path.Join(downloadLocation, publication.folderName);
|
||||||
|
if(!Directory.Exists(publicationFolder))
|
||||||
Directory.CreateDirectory(publicationFolder);
|
Directory.CreateDirectory(publicationFolder);
|
||||||
DirectoryInfo dirInfo = new (publicationFolder);
|
DirectoryInfo dirInfo = new (publicationFolder);
|
||||||
foreach(FileInfo fileInfo in dirInfo.EnumerateFiles())
|
foreach(FileInfo fileInfo in dirInfo.EnumerateFiles())
|
||||||
|
@ -38,7 +38,7 @@ public struct Publication
|
|||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Serialized JSON String for series.json</returns>
|
/// <returns>Serialized JSON String for series.json</returns>
|
||||||
public string GetSeriesInfo()
|
public string GetSeriesInfoJson()
|
||||||
{
|
{
|
||||||
SeriesInfo si = new (new Metadata(this.sortName, this.year.ToString() ?? string.Empty, this.status, this.description ?? ""));
|
SeriesInfo si = new (new Metadata(this.sortName, this.year.ToString() ?? string.Empty, this.status, this.description ?? ""));
|
||||||
return System.Text.Json.JsonSerializer.Serialize(si);
|
return System.Text.Json.JsonSerializer.Serialize(si);
|
||||||
@ -51,21 +51,43 @@ public struct Publication
|
|||||||
public SeriesInfo(Metadata metadata) => this.metadata = metadata;
|
public SeriesInfo(Metadata metadata) => this.metadata = metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Only for series.json
|
//Only for series.json what an abomination, why are all the fields not-null????
|
||||||
private struct Metadata
|
private struct Metadata
|
||||||
{
|
{
|
||||||
|
[JsonRequired] public string type { get; }
|
||||||
|
[JsonRequired] public string publisher { get; }
|
||||||
|
// ReSharper disable twice IdentifierTypo
|
||||||
|
[JsonRequired] public int comicid { get; }
|
||||||
|
[JsonRequired] public string booktype { get; }
|
||||||
|
// ReSharper disable InconsistentNaming
|
||||||
|
[JsonRequired] public string ComicImage { get; }
|
||||||
|
[JsonRequired] public int total_issues { get; }
|
||||||
|
[JsonRequired] public string publication_run { get; }
|
||||||
[JsonRequired]public string name { get; }
|
[JsonRequired]public string name { get; }
|
||||||
[JsonRequired]public string year { get; }
|
[JsonRequired]public string year { get; }
|
||||||
[JsonRequired]public string status { get; }
|
[JsonRequired]public string status { get; }
|
||||||
// ReSharper disable twice InconsistentNaming
|
|
||||||
[JsonRequired]public string description_text { get; }
|
[JsonRequired]public string description_text { get; }
|
||||||
|
|
||||||
public Metadata(string name, string year, string status, string description_text)
|
public Metadata(string name, string year, string status, string description_text)
|
||||||
{
|
{
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.year = year;
|
this.year = year;
|
||||||
|
if(status == "ongoing" || status == "hiatus")
|
||||||
|
this.status = "Continuing";
|
||||||
|
else if (status == "completed" || status == "cancelled")
|
||||||
|
this.status = "Ended";
|
||||||
|
else
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.description_text = description_text;
|
this.description_text = description_text;
|
||||||
|
|
||||||
|
//kill it with fire
|
||||||
|
type = "Manga";
|
||||||
|
publisher = "";
|
||||||
|
comicid = 0;
|
||||||
|
booktype = "";
|
||||||
|
ComicImage = "";
|
||||||
|
total_issues = 0;
|
||||||
|
publication_run = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -68,7 +68,16 @@ public static class TaskExecutor
|
|||||||
{
|
{
|
||||||
List<Chapter> newChapters = UpdateChapters(connector, publication, language, chapterCollection);
|
List<Chapter> newChapters = UpdateChapters(connector, publication, language, chapterCollection);
|
||||||
connector.DownloadCover(publication);
|
connector.DownloadCover(publication);
|
||||||
connector.SaveSeriesInfo(publication);
|
|
||||||
|
//Check if Publication already has a Folder and a series.json
|
||||||
|
string publicationFolder = Path.Join(connector.downloadLocation, publication.folderName);
|
||||||
|
if(!Directory.Exists(publicationFolder))
|
||||||
|
Directory.CreateDirectory(publicationFolder);
|
||||||
|
|
||||||
|
string seriesInfoPath = Path.Join(publicationFolder, "series.json");
|
||||||
|
if(!File.Exists(seriesInfoPath))
|
||||||
|
File.WriteAllText(seriesInfoPath,publication.GetSeriesInfoJson());
|
||||||
|
|
||||||
foreach(Chapter newChapter in newChapters)
|
foreach(Chapter newChapter in newChapters)
|
||||||
connector.DownloadChapter(publication, newChapter);
|
connector.DownloadChapter(publication, newChapter);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user