Compare commits

..

No commits in common. "08e0fe7c710f563ffc22baa443a949da41890005" and "2b18dc9d4ff2f7b841933aeb752617d2fd93cc8c" have entirely different histories.

6 changed files with 20 additions and 26 deletions

View File

@ -78,15 +78,15 @@ public static class Tranga_Cli
string? query = Console.ReadLine();
while (query is null || query.Length < 1)
query = Console.ReadLine();
PrintTasks(taskManager.GetAllTasks().Where(qTask =>
((Publication)qTask.publication!).sortName.ToLower()
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(eTask => eTask.isBeingExecuted).ToArray());
PrintTasks(taskManager.GetAllTasks().Where(task => task.isBeingExecuted).ToArray());
Console.WriteLine("Press any key.");
Console.ReadKey();
menu = 0;
@ -130,7 +130,6 @@ public static class Tranga_Cli
selection = Console.ReadKey().Key;
taskManager.Shutdown(selection == ConsoleKey.Y);
}else
// ReSharper disable once RedundantArgumentDefaultValue Better readability
taskManager.Shutdown(false);
}
@ -161,7 +160,7 @@ public static class Tranga_Cli
int tIndex = 0;
Console.WriteLine($"Tasks (Running/Total): {taskRunningCount}/{taskCount}");
foreach(TrangaTask trangaTask in tasks)
Console.WriteLine($"{tIndex++:000}: {trangaTask}");
Console.WriteLine($"{tIndex++:000}: {trangaTask.ToString()}");
}
private static void ExecuteTaskNow(TaskManager taskManager)
@ -316,7 +315,7 @@ public static class Tranga_Cli
selected = Console.ReadLine();
int start = 0;
int end;
int end = 0;
if (selected == "a")
end = chapters.Length - 1;
else if (selected.Contains('-'))

View File

@ -68,7 +68,7 @@ public abstract class Connector
File.WriteAllText(seriesInfoPath,publication.GetSeriesInfoJson());
}
protected static string CreateComicInfo(Publication publication, Chapter chapter)
public static string CreateComicInfo(Publication publication, Chapter chapter)
{
XElement comicInfo = new XElement("ComicInfo",
new XElement("Tags", string.Join(',',publication.tags)),
@ -98,7 +98,6 @@ 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>
/// <param name="comicInfoPath">Path of the generate Chapter ComicInfo.xml, if it was generated</param>
protected static void DownloadChapterImages(string[] imageUrls, string saveArchiveFilePath, DownloadClient downloadClient, string? comicInfoPath = null)
{
//Check if Publication Directory already exists
@ -119,7 +118,7 @@ public abstract class Connector
foreach (string imageUrl in imageUrls)
{
string[] split = imageUrl.Split('.');
string extension = split[^1];
string extension = split[split.Length - 1];
DownloadImage(imageUrl, Path.Join(tempFolder, $"{chapter++}.{extension}"), downloadClient);
}

View File

@ -49,7 +49,7 @@ public class MangaDex : Connector
string title = attributes["title"]!.AsObject().ContainsKey("en") && attributes["title"]!["en"] is not null
? attributes["title"]!["en"]!.GetValue<string>()
: attributes["title"]![((IDictionary<string, JsonNode?>)attributes["title"]!.AsObject()).Keys.First()]!.GetValue<string>();
: "";
string? description = attributes["description"]!.AsObject().ContainsKey("en") && attributes["description"]!["en"] is not null
? attributes["description"]!["en"]!.GetValue<string?>()
@ -224,13 +224,13 @@ public class MangaDex : Connector
if (result is null)
return;
string fileName = result["data"]!["attributes"]!["fileName"]!.GetValue<string>();
string fileName = result!["data"]!["attributes"]!["fileName"]!.GetValue<string>();
string coverUrl = $"https://uploads.mangadex.org/covers/{publication.downloadUrl}/{fileName}";
//Get file-extension (jpg, png)
string[] split = coverUrl.Split('.');
string extension = split[^1];
string extension = split[split.Length - 1];
string outFolderPath = Path.Join(downloadLocation, publication.folderName);
Directory.CreateDirectory(outFolderPath);

View File

@ -5,12 +5,10 @@ namespace Tranga;
/// <summary>
/// Contains information on a Publication (Manga)
/// </summary>
public readonly struct Publication
public struct Publication
{
public string sortName { get; }
// ReSharper disable UnusedAutoPropertyAccessor.Global we need it, trust
[JsonIgnore]public string[,] altTitles { get; }
// ReSharper disable trice MemberCanBePrivate.Global, trust
public string? description { get; }
public string[] tags { get; }
public string? posterUrl { get; }
@ -49,7 +47,6 @@ public readonly struct Publication
//Only for series.json
private struct SeriesInfo
{
// ReSharper disable once UnusedAutoPropertyAccessor.Local we need it, trust
[JsonRequired]public Metadata metadata { get; }
public SeriesInfo(Metadata metadata) => this.metadata = metadata;
}
@ -57,7 +54,6 @@ public readonly struct Publication
//Only for series.json what an abomination, why are all the fields not-null????
private struct Metadata
{
// ReSharper disable UnusedAutoPropertyAccessor.Local we need it, trust
[JsonRequired] public string type { get; }
[JsonRequired] public string publisher { get; }
// ReSharper disable twice IdentifierTypo

View File

@ -12,7 +12,8 @@ public class TaskManager
private readonly Dictionary<Publication, List<Chapter>> _chapterCollection;
private readonly HashSet<TrangaTask> _allTasks;
private bool _continueRunning = true;
private readonly Connector[] _connectors;
private readonly Connector[] connectors;
private readonly string folderPath;
/// <summary>
///
@ -20,7 +21,8 @@ public class TaskManager
/// <param name="folderPath">Local path to save data (Manga) to</param>
public TaskManager(string folderPath)
{
this._connectors = new Connector[]{ new MangaDex(folderPath) };
this.folderPath = folderPath;
this.connectors = new Connector[]{ new MangaDex(folderPath) };
_chapterCollection = new();
_allTasks = ImportTasks(Directory.GetCurrentDirectory());
Thread taskChecker = new(TaskCheckerThread);
@ -34,7 +36,7 @@ public class TaskManager
foreach (TrangaTask task in _allTasks)
{
if(task.ShouldExecute())
TaskExecutor.Execute(this._connectors, task, this._chapterCollection);
TaskExecutor.Execute(this.connectors, task, this._chapterCollection);
}
Thread.Sleep(1000);
}
@ -51,7 +53,7 @@ public class TaskManager
Task t = new Task(() =>
{
TaskExecutor.Execute(this._connectors, task, this._chapterCollection);
TaskExecutor.Execute(this.connectors, task, this._chapterCollection);
});
t.Start();
}
@ -69,7 +71,7 @@ public class TaskManager
string language = "")
{
//Get appropriate Connector from available Connectors for TrangaTask
Connector? connector = _connectors.FirstOrDefault(c => c.name == connectorName);
Connector? connector = connectors.FirstOrDefault(c => c.name == connectorName);
if (connector is null)
throw new ArgumentException($"Connector {connectorName} is not a known connector.");
@ -106,7 +108,7 @@ public class TaskManager
/// <returns>All available Connectors</returns>
public Dictionary<string, Connector> GetAvailableConnectors()
{
return this._connectors.ToDictionary(connector => connector.name, connector => connector);
return this.connectors.ToDictionary(connector => connector.name, connector => connector);
}
/// <summary>

View File

@ -7,8 +7,6 @@ namespace Tranga;
/// </summary>
public class TrangaTask
{
// ReSharper disable once CommentTypo ...tell me why!
// ReSharper disable once MemberCanBePrivate.Global I want it thaaat way
public TimeSpan reoccurrence { get; }
public DateTime lastExecuted { get; set; }
public string connectorName { get; }