Compare commits

...

12 Commits

Author SHA1 Message Date
3c1865de31 Added Menu options:
List Running Tasks
Search Task (by name)
2023-05-20 00:30:24 +02:00
84542640dc Renamed Method GetSeriesInfo to GetSeriesInfoJson to avoid confusion with xml 2023-05-20 00:19:40 +02:00
a3520dfd77 Now adding ComicInfo.xml to chapterse 2023-05-20 00:19:04 +02:00
68b40e087e rage 2023-05-19 23:02:08 +02:00
1674d70995 Moved SaveSeriesInfo to 6 lines of code... 2023-05-19 23:01:34 +02:00
ccbe8a95f8 Proper naming 2023-05-19 23:01:04 +02:00
78d8deb9de Properly create directory, not file, ya doofus 2023-05-19 23:00:45 +02:00
1d0883cbab strings 2023-05-19 23:00:04 +02:00
7726259d19 resharper 2023-05-19 22:59:37 +02:00
dc97774587 series.json is an abomination 2023-05-19 22:59:16 +02:00
26ef59ab42 Check if directory exists before creating 2023-05-19 22:58:59 +02:00
1b59475254 Number Format 2023-05-19 22:58:04 +02:00
6 changed files with 99 additions and 20 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} - {connector.name} - {publication?.sortName}");
Console.WriteLine($"{task} - {reoccurrence} - {publication?.sortName} - {connector.name}");
Console.WriteLine("Press any key.");
Console.ReadKey();
menu = 0;
@ -68,7 +68,25 @@ public static class Tranga_Cli
menu = 0;
break;
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.ReadKey();
menu = 0;
@ -89,6 +107,15 @@ 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;
@ -112,10 +139,13 @@ 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();
@ -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")}");
}
private static void ExecuteTask(TaskManager taskManager)
private static void ExecuteTaskNow(TaskManager taskManager)
{
TrangaTask[] tasks = taskManager.GetAllTasks();
if (tasks.Length < 1)
@ -144,7 +174,7 @@ public static class Tranga_Cli
}
PrintTasks(tasks);
Console.WriteLine($"Select Task (0-{tasks.Length}):");
Console.WriteLine($"Select Task (0-{tasks.Length - 1}):");
string? selectedTask = Console.ReadLine();
while(selectedTask is null || selectedTask.Length < 1)
@ -165,7 +195,7 @@ public static class Tranga_Cli
}
PrintTasks(tasks);
Console.WriteLine($"Select Task (0-{tasks.Length}):");
Console.WriteLine($"Select Task (0-{tasks.Length - 1}):");
string? selectedTask = Console.ReadLine();
while(selectedTask is null || selectedTask.Length < 1)
@ -184,7 +214,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}):");
Console.WriteLine($"Select Task (0-{taskNames.Length - 1}):");
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}";
this.fileName = $"{chapterName} - V{volumeNumber}C{chapterNumber} - {multiplied.ToString(new NumberFormatInfo() { NumberDecimalSeparator = "." })}";
}
}

View File

@ -1,5 +1,6 @@
using System.IO.Compression;
using System.Net;
using System.Xml.Linq;
namespace Tranga;
@ -59,10 +60,22 @@ public abstract class Connector
{
//Check if Publication already has a Folder and a series.json
string publicationFolder = Path.Join(downloadLocation, publication.folderName);
Directory.CreateDirectory(publicationFolder);
if(!Directory.Exists(publicationFolder))
Directory.CreateDirectory(publicationFolder);
string seriesInfoPath = Path.Join(publicationFolder, "series.json");
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>
@ -85,7 +98,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)
protected static void DownloadChapterImages(string[] imageUrls, string saveArchiveFilePath, DownloadClient downloadClient, string? comicInfoPath = null)
{
//Check if Publication Directory already exists
string[] splitPath = saveArchiveFilePath.Split(Path.DirectorySeparatorChar);
@ -98,9 +111,7 @@ public abstract class Connector
return;
//Create a temporary folder to store images
string tempFolder = Path.GetTempFileName();
File.Delete(tempFolder);
Directory.CreateDirectory(tempFolder);
string tempFolder = Directory.CreateTempSubdirectory().FullName;
int chapter = 0;
//Download all Images to temporary Folder
@ -111,6 +122,9 @@ 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,15 +197,19 @@ 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);
DownloadChapterImages(imageUrls.ToArray(), Path.Join(downloadLocation, publication.folderName, chapter.fileName), this.downloadClient, comicInfoPath);
}
public override void DownloadCover(Publication publication)
{
//Check if Publication already has a Folder and cover
string publicationFolder = Path.Join(downloadLocation, publication.folderName);
Directory.CreateDirectory(publicationFolder);
if(!Directory.Exists(publicationFolder))
Directory.CreateDirectory(publicationFolder);
DirectoryInfo dirInfo = new (publicationFolder);
foreach(FileInfo fileInfo in dirInfo.EnumerateFiles())
if (fileInfo.Name.Contains("cover."))

View File

@ -38,7 +38,7 @@ public struct Publication
///
/// </summary>
/// <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 ?? ""));
return System.Text.Json.JsonSerializer.Serialize(si);
@ -51,21 +51,43 @@ public struct Publication
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
{
[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;
this.status = status;
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,7 +68,16 @@ public static class TaskExecutor
{
List<Chapter> newChapters = UpdateChapters(connector, publication, language, chapterCollection);
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)
connector.DownloadChapter(publication, newChapter);
}