2
0

Compare commits

..

No commits in common. "3c1865de31c9c114cd195ee230e885c55bd54298" and "28218b6dabd206df06b79f889b186b1e408db2b1" have entirely different histories.

6 changed files with 20 additions and 99 deletions

View File

@ -56,7 +56,7 @@ public static class Tranga_Cli
publication = SelectPublication(connector);
TimeSpan reoccurrence = SelectReoccurrence();
taskManager.AddTask(task, connector.name, publication, reoccurrence, "en");
Console.WriteLine($"{task} - {reoccurrence} - {publication?.sortName} - {connector.name}");
Console.WriteLine($"{task} - {connector.name} - {publication?.sortName}");
Console.WriteLine("Press any key.");
Console.ReadKey();
menu = 0;
@ -68,25 +68,7 @@ public static class Tranga_Cli
menu = 0;
break;
case 4:
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());
ExecuteTask(taskManager);
Console.WriteLine("Press any key.");
Console.ReadKey();
menu = 0;
@ -107,15 +89,6 @@ public static class Tranga_Cli
case ConsoleKey.E:
menu = 4;
break;
case ConsoleKey.U:
menu = 0;
break;
case ConsoleKey.S:
menu = 5;
break;
case ConsoleKey.R:
menu = 6;
break;
default:
menu = 0;
break;
@ -139,13 +112,10 @@ public static class Tranga_Cli
int taskRunningCount = taskManager.GetAllTasks().Count(task => task.isBeingExecuted);
Console.Clear();
Console.WriteLine($"Download Folder: {folderPath} Tasks (Running/Total): {taskRunningCount}/{taskCount}");
Console.WriteLine("U: Update this Screen");
Console.WriteLine("L: List tasks");
Console.WriteLine("C: Create Task");
Console.WriteLine("D: Delete Task");
Console.WriteLine("E: Execute Task now");
Console.WriteLine("S: Search Task");
Console.WriteLine("R: Running Tasks");
Console.WriteLine("Q: Exit");
ConsoleKey selection = Console.ReadKey().Key;
Console.WriteLine();
@ -163,7 +133,7 @@ public static class Tranga_Cli
Console.WriteLine($"{tIndex++}: {trangaTask.task} - {trangaTask.reoccurrence} - {trangaTask.publication?.sortName} - {trangaTask.connectorName} - {trangaTask.lastExecuted} - {(trangaTask.isBeingExecuted ? "Running" : "Waiting")}");
}
private static void ExecuteTaskNow(TaskManager taskManager)
private static void ExecuteTask(TaskManager taskManager)
{
TrangaTask[] tasks = taskManager.GetAllTasks();
if (tasks.Length < 1)
@ -174,7 +144,7 @@ public static class Tranga_Cli
}
PrintTasks(tasks);
Console.WriteLine($"Select Task (0-{tasks.Length - 1}):");
Console.WriteLine($"Select Task (0-{tasks.Length}):");
string? selectedTask = Console.ReadLine();
while(selectedTask is null || selectedTask.Length < 1)
@ -195,7 +165,7 @@ public static class Tranga_Cli
}
PrintTasks(tasks);
Console.WriteLine($"Select Task (0-{tasks.Length - 1}):");
Console.WriteLine($"Select Task (0-{tasks.Length}):");
string? selectedTask = Console.ReadLine();
while(selectedTask is null || selectedTask.Length < 1)
@ -214,7 +184,7 @@ public static class Tranga_Cli
Console.WriteLine("Available Tasks:");
foreach (string taskName in taskNames)
Console.WriteLine($"{tIndex++}: {taskName}");
Console.WriteLine($"Select Task (0-{taskNames.Length - 1}):");
Console.WriteLine($"Select Task (0-{taskNames.Length}):");
string? selectedTask = Console.ReadLine();
while(selectedTask is null || selectedTask.Length < 1)

View File

@ -23,6 +23,6 @@ public struct Chapter
string chapterName = string.Concat((name ?? "").Split(Path.GetInvalidFileNameChars()));
double multiplied = Convert.ToDouble(chapterNumber, new NumberFormatInfo() { NumberDecimalSeparator = "." }) *
Convert.ToInt32(volumeNumber);
this.fileName = $"{chapterName} - V{volumeNumber}C{chapterNumber} - {multiplied.ToString(new NumberFormatInfo() { NumberDecimalSeparator = "." })}";
this.fileName = $"{chapterName} - V{volumeNumber}C{chapterNumber} - {multiplied}";
}
}

View File

@ -1,6 +1,5 @@
using System.IO.Compression;
using System.Net;
using System.Xml.Linq;
namespace Tranga;
@ -60,22 +59,10 @@ public abstract class Connector
{
//Check if Publication already has a Folder and a series.json
string publicationFolder = Path.Join(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());
}
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();
File.WriteAllText(seriesInfoPath,publication.GetSeriesInfo());
}
/// <summary>
@ -98,7 +85,7 @@ public abstract class Connector
/// <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="downloadClient">DownloadClient of the connector</param>
protected static void DownloadChapterImages(string[] imageUrls, string saveArchiveFilePath, DownloadClient downloadClient, string? comicInfoPath = null)
protected static void DownloadChapterImages(string[] imageUrls, string saveArchiveFilePath, DownloadClient downloadClient)
{
//Check if Publication Directory already exists
string[] splitPath = saveArchiveFilePath.Split(Path.DirectorySeparatorChar);
@ -111,7 +98,9 @@ public abstract class Connector
return;
//Create a temporary folder to store images
string tempFolder = Directory.CreateTempSubdirectory().FullName;
string tempFolder = Path.GetTempFileName();
File.Delete(tempFolder);
Directory.CreateDirectory(tempFolder);
int chapter = 0;
//Download all Images to temporary Folder
@ -122,9 +111,6 @@ public abstract class Connector
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
ZipFile.CreateFromDirectory(tempFolder, fullPath);
Directory.Delete(tempFolder, true); //Cleanup

View File

@ -197,18 +197,14 @@ public class MangaDex : Connector
foreach (JsonNode? image in imageFileNames)
imageUrls.Add($"{baseUrl}/data/{hash}/{image!.GetValue<string>()}");
string comicInfoPath = Path.GetTempFileName();
File.WriteAllText(comicInfoPath, CreateComicInfo(publication, chapter));
//Download Chapter-Images
DownloadChapterImages(imageUrls.ToArray(), Path.Join(downloadLocation, publication.folderName, chapter.fileName), this.downloadClient, comicInfoPath);
DownloadChapterImages(imageUrls.ToArray(), Path.Join(downloadLocation, publication.folderName, chapter.fileName), this.downloadClient);
}
public override void DownloadCover(Publication publication)
{
//Check if Publication already has a Folder and cover
string publicationFolder = Path.Join(downloadLocation, publication.folderName);
if(!Directory.Exists(publicationFolder))
Directory.CreateDirectory(publicationFolder);
DirectoryInfo dirInfo = new (publicationFolder);
foreach(FileInfo fileInfo in dirInfo.EnumerateFiles())

View File

@ -38,7 +38,7 @@ public struct Publication
///
/// </summary>
/// <returns>Serialized JSON String for series.json</returns>
public string GetSeriesInfoJson()
public string GetSeriesInfo()
{
SeriesInfo si = new (new Metadata(this.sortName, this.year.ToString() ?? string.Empty, this.status, this.description ?? ""));
return System.Text.Json.JsonSerializer.Serialize(si);
@ -51,43 +51,21 @@ public struct Publication
public SeriesInfo(Metadata metadata) => this.metadata = metadata;
}
//Only for series.json what an abomination, why are all the fields not-null????
//Only for series.json
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 year { get; }
[JsonRequired]public string status { get; }
// ReSharper disable twice InconsistentNaming
[JsonRequired]public string description_text { get; }
public Metadata(string name, string year, string status, string description_text)
{
this.name = name;
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.description_text = description_text;
//kill it with fire
type = "Manga";
publisher = "";
comicid = 0;
booktype = "";
ComicImage = "";
total_issues = 0;
publication_run = "";
}
}
}

View File

@ -68,16 +68,7 @@ public static class TaskExecutor
{
List<Chapter> newChapters = UpdateChapters(connector, publication, language, chapterCollection);
connector.DownloadCover(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());
connector.SaveSeriesInfo(publication);
foreach(Chapter newChapter in newChapters)
connector.DownloadChapter(publication, newChapter);
}