diff --git a/Tranga-CLI/Program.cs b/Tranga-CLI/Tranga_Cli.cs similarity index 96% rename from Tranga-CLI/Program.cs rename to Tranga-CLI/Tranga_Cli.cs index 14ddce4..59031e8 100644 --- a/Tranga-CLI/Program.cs +++ b/Tranga-CLI/Tranga_Cli.cs @@ -1,8 +1,9 @@ -// See https://aka.ms/new-console-template for more information -using Tranga; +using Tranga; using Tranga.Connectors; -public class Program +namespace Tranga_CLI; + +public static class Tranga_Cli { public static void Main(string[] args) { diff --git a/Tranga/Connector.cs b/Tranga/Connector.cs index 943551f..d176f54 100644 --- a/Tranga/Connector.cs +++ b/Tranga/Connector.cs @@ -15,7 +15,7 @@ public abstract class Connector public abstract Publication[] GetPublications(string publicationTitle = ""); public abstract Chapter[] GetChapters(Publication publication, string language = ""); public abstract void DownloadChapter(Publication publication, Chapter chapter); //where to? - internal abstract void DownloadImage(string url, string path); + protected abstract void DownloadImage(string url, string path); internal void DownloadChapter(string[] imageUrls, string outputFilePath) { diff --git a/Tranga/Connectors/MangaDex.cs b/Tranga/Connectors/MangaDex.cs index 49bfde7..d35fdff 100644 --- a/Tranga/Connectors/MangaDex.cs +++ b/Tranga/Connectors/MangaDex.cs @@ -8,7 +8,7 @@ namespace Tranga.Connectors; public class MangaDex : Connector { public override string name { get; } - private DownloadClient _downloadClient = new (750); + private readonly DownloadClient _downloadClient = new (750); public MangaDex(string downloadLocation) : base(downloadLocation) { @@ -31,9 +31,10 @@ public class MangaDex : Connector total = result["total"]!.GetValue(); JsonArray mangaInResult = result["data"]!.AsArray(); - foreach (JsonObject manga in mangaInResult) + foreach (JsonNode? mangeNode in mangaInResult) { - JsonObject attributes = manga["attributes"].AsObject(); + JsonObject manga = (JsonObject)mangeNode!; + JsonObject attributes = manga["attributes"]!.AsObject(); string title = attributes["title"]!.AsObject().ContainsKey("en") && attributes["title"]!["en"] is not null ? attributes["title"]!["en"]!.GetValue() @@ -46,19 +47,21 @@ public class MangaDex : Connector JsonArray altTitlesObject = attributes["altTitles"]!.AsArray(); string[,] altTitles = new string[altTitlesObject.Count, 2]; int titleIndex = 0; - foreach (JsonObject altTitleObject in altTitlesObject) + foreach (JsonNode? altTitleNode in altTitlesObject) { - string key = ((IDictionary)altTitleObject!).Keys.ToArray()[0]; + JsonObject altTitleObject = (JsonObject)altTitleNode!; + string key = ((IDictionary)altTitleObject).Keys.ToArray()[0]; altTitles[titleIndex, 0] = key; altTitles[titleIndex++, 1] = altTitleObject[key]!.GetValue(); } JsonArray tagsObject = attributes["tags"]!.AsArray(); HashSet tags = new(); - foreach (JsonObject tagObject in tagsObject) + foreach (JsonNode? tagNode in tagsObject) { - if(tagObject!["attributes"]!["name"]!.AsObject().ContainsKey("en")) - tags.Add(tagObject!["attributes"]!["name"]!["en"]!.GetValue()); + JsonObject tagObject = (JsonObject)tagNode!; + if(tagObject["attributes"]!["name"]!.AsObject().ContainsKey("en")) + tags.Add(tagObject["attributes"]!["name"]!["en"]!.GetValue()); } string? poster = null; @@ -130,9 +133,10 @@ public class MangaDex : Connector total = result["total"]!.GetValue(); JsonArray chaptersInResult = result["data"]!.AsArray(); - foreach (JsonObject chapter in chaptersInResult) + foreach (JsonNode? jsonNode in chaptersInResult) { - JsonObject attributes = chapter!["attributes"]!.AsObject(); + JsonObject chapter = (JsonObject)jsonNode!; + JsonObject attributes = chapter["attributes"]!.AsObject(); string chapterId = chapter["id"]!.GetValue(); string? title = attributes.ContainsKey("title") && attributes["title"] is not null @@ -154,7 +158,7 @@ public class MangaDex : Connector } } - NumberFormatInfo chapterNumberFormatInfo = new NumberFormatInfo() + NumberFormatInfo chapterNumberFormatInfo = new() { NumberDecimalSeparator = "." }; @@ -173,7 +177,7 @@ public class MangaDex : Connector string hash = result["chapter"]!["hash"]!.GetValue(); JsonArray imageFileNames = result["chapter"]!["data"]!.AsArray(); HashSet imageUrls = new(); - foreach (JsonNode image in imageFileNames) + foreach (JsonNode? image in imageFileNames) imageUrls.Add($"{baseUrl}/data/{hash}/{image!.GetValue()}"); string seriesFolder = string.Concat(publication.sortName.Split(Path.GetInvalidPathChars())); @@ -181,7 +185,7 @@ public class MangaDex : Connector DownloadChapter(imageUrls.ToArray(), Path.Join(downloadLocation, seriesFolder, chapter.relativeFilePath)); } - internal override void DownloadImage(string url, string path) + protected override void DownloadImage(string url, string path) { DownloadClient.RequestResult requestResult = _downloadClient.MakeRequest(url); byte[] buffer = new byte[requestResult.result.Length]; diff --git a/Tranga/Publication.cs b/Tranga/Publication.cs index bea9539..36c30bb 100644 --- a/Tranga/Publication.cs +++ b/Tranga/Publication.cs @@ -6,7 +6,7 @@ public struct Publication public string[,] altTitles { get; } public string? description { get; } public string[] tags { get; } - public string? posterUrl { get; } //maybe there is a better way? + public string? posterUrl { get; } public string[,]? links { get; } public int? year { get; } public string? originalLanguage { get; }