diff --git a/Tranga/Chapter.cs b/Tranga/Chapter.cs index af6afea..9beb14a 100644 --- a/Tranga/Chapter.cs +++ b/Tranga/Chapter.cs @@ -2,6 +2,10 @@ namespace Tranga; +/// +/// Has to be Part of a publication +/// Includes the Chapter-Name, -VolumeNumber, -ChapterNumber, the location of the chapter on the internet and the saveName of the local file. +/// public struct Chapter { public string? name { get; } diff --git a/Tranga/Connector.cs b/Tranga/Connector.cs index af6fff0..2a61164 100644 --- a/Tranga/Connector.cs +++ b/Tranga/Connector.cs @@ -3,6 +3,10 @@ using System.Net; namespace Tranga; +/// +/// Base-Class for all Connectors +/// Provides some methods to be used by all Connectors, as well as a DownloadClient +/// public abstract class Connector { internal string downloadLocation { get; } //Location of local files @@ -14,15 +18,51 @@ public abstract class Connector this.downloadClient = new DownloadClient(downloadDelay); } - internal string downloadLocation { get; } - public abstract string name { get; } + public abstract string name { get; } //Name of the Connector (e.g. Website) + + /// + /// Returns all Publications with the given string. + /// If the string is empty or null, returns all Publication of the Connector + /// + /// Search-Query + /// Publications matching the query public abstract Publication[] GetPublications(string publicationTitle = ""); + + /// + /// Returns all Chapters of the publication in the provided language. + /// If the language is empty or null, returns all Chapters in all Languages. + /// + /// Publication to get Chapters for + /// Language of the Chapters + /// Array of Chapters matching Publication and Language public abstract Chapter[] GetChapters(Publication publication, string language = ""); - public abstract void DownloadChapter(Publication publication, Chapter chapter); //where to? - protected abstract void DownloadImage(string url, string savePath); + + /// + /// Retrieves the Chapter (+Images) from the website. + /// Should later call DownloadChapterImages to retrieve the individual Images of the Chapter. + /// + /// Publication that contains Chapter + /// Chapter with Images to retrieve + public abstract void DownloadChapter(Publication publication, Chapter chapter); + + /// + /// Retrieves the Cover from the Website + /// + /// Publication to retrieve Cover for public abstract void DownloadCover(Publication publication); - protected void DownloadImage(string imageUrl, string fullPath, DownloadClient downloadClient) + /// + /// Saves the series-info to series.json in the Publication Folder + /// + /// Publication to save series.json for + public void SaveSeriesInfo(Publication publication) + { + string seriesInfoPath = Path.Join(downloadLocation, publication.folderName, "series.json"); + if(!File.Exists(seriesInfoPath)) + File.WriteAllText(seriesInfoPath,publication.GetSeriesInfo()); + } + + protected static void DownloadImage(string imageUrl, string fullPath, DownloadClient downloadClient) { DownloadClient.RequestResult requestResult = downloadClient.MakeRequest(imageUrl); byte[] buffer = new byte[requestResult.result.Length]; @@ -30,7 +70,7 @@ public abstract class Connector File.WriteAllBytes(fullPath, buffer); } - protected void DownloadChapterImages(string[] imageUrls, string saveArchiveFilePath, DownloadClient downloadClient) + protected static void DownloadChapterImages(string[] imageUrls, string saveArchiveFilePath, DownloadClient downloadClient) { string[] splitPath = saveArchiveFilePath.Split(Path.DirectorySeparatorChar); string directoryPath = Path.Combine(splitPath.Take(splitPath.Length - 1).ToArray()); @@ -56,13 +96,7 @@ public abstract class Connector ZipFile.CreateFromDirectory(tempFolder, fullPath); } - public void SaveSeriesInfo(Publication publication) - { - string seriesInfoPath = Path.Join(downloadLocation, publication.folderName, "series.json"); - if(!File.Exists(seriesInfoPath)) - File.WriteAllText(seriesInfoPath,publication.GetSeriesInfo()); - } - + protected class DownloadClient { private readonly TimeSpan _requestSpeed;