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); 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} - {reoccurrence} - {publication?.sortName} - {connector.name}"); Console.WriteLine($"{task} - {connector.name} - {publication?.sortName}");
Console.WriteLine("Press any key."); Console.WriteLine("Press any key.");
Console.ReadKey(); Console.ReadKey();
menu = 0; menu = 0;
@ -68,25 +68,7 @@ public static class Tranga_Cli
menu = 0; menu = 0;
break; break;
case 4: case 4:
ExecuteTaskNow(taskManager); ExecuteTask(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;
@ -107,15 +89,6 @@ 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;
@ -139,13 +112,10 @@ 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();
@ -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")}"); 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(); TrangaTask[] tasks = taskManager.GetAllTasks();
if (tasks.Length < 1) if (tasks.Length < 1)
@ -174,7 +144,7 @@ public static class Tranga_Cli
} }
PrintTasks(tasks); PrintTasks(tasks);
Console.WriteLine($"Select Task (0-{tasks.Length - 1}):"); Console.WriteLine($"Select Task (0-{tasks.Length}):");
string? selectedTask = Console.ReadLine(); string? selectedTask = Console.ReadLine();
while(selectedTask is null || selectedTask.Length < 1) while(selectedTask is null || selectedTask.Length < 1)
@ -195,7 +165,7 @@ public static class Tranga_Cli
} }
PrintTasks(tasks); PrintTasks(tasks);
Console.WriteLine($"Select Task (0-{tasks.Length - 1}):"); Console.WriteLine($"Select Task (0-{tasks.Length}):");
string? selectedTask = Console.ReadLine(); string? selectedTask = Console.ReadLine();
while(selectedTask is null || selectedTask.Length < 1) while(selectedTask is null || selectedTask.Length < 1)
@ -214,7 +184,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 - 1}):"); Console.WriteLine($"Select Task (0-{taskNames.Length}):");
string? selectedTask = Console.ReadLine(); string? selectedTask = Console.ReadLine();
while(selectedTask is null || selectedTask.Length < 1) while(selectedTask is null || selectedTask.Length < 1)

View File

@ -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.ToString(new NumberFormatInfo() { NumberDecimalSeparator = "." })}"; this.fileName = $"{chapterName} - V{volumeNumber}C{chapterNumber} - {multiplied}";
} }
} }

View File

@ -1,6 +1,5 @@
using System.IO.Compression; using System.IO.Compression;
using System.Net; using System.Net;
using System.Xml.Linq;
namespace Tranga; namespace Tranga;
@ -60,22 +59,10 @@ 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.GetSeriesInfoJson()); File.WriteAllText(seriesInfoPath,publication.GetSeriesInfo());
}
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>
@ -98,7 +85,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, string? comicInfoPath = null) protected static void DownloadChapterImages(string[] imageUrls, string saveArchiveFilePath, DownloadClient downloadClient)
{ {
//Check if Publication Directory already exists //Check if Publication Directory already exists
string[] splitPath = saveArchiveFilePath.Split(Path.DirectorySeparatorChar); string[] splitPath = saveArchiveFilePath.Split(Path.DirectorySeparatorChar);
@ -111,7 +98,9 @@ public abstract class Connector
return; return;
//Create a temporary folder to store images //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; int chapter = 0;
//Download all Images to temporary Folder //Download all Images to temporary Folder
@ -122,9 +111,6 @@ 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

View File

@ -197,19 +197,15 @@ 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, comicInfoPath); DownloadChapterImages(imageUrls.ToArray(), Path.Join(downloadLocation, publication.folderName, chapter.fileName), this.downloadClient);
} }
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())
if (fileInfo.Name.Contains("cover.")) if (fileInfo.Name.Contains("cover."))

View File

@ -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 GetSeriesInfoJson() public string GetSeriesInfo()
{ {
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,43 +51,21 @@ public struct Publication
public SeriesInfo(Metadata metadata) => this.metadata = metadata; 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 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 = status;
this.status = "Continuing";
else if (status == "completed" || status == "cancelled")
this.status = "Ended";
else
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 = "";
} }
} }
} }

View File

@ -68,16 +68,7 @@ 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);
} }