mirror of
https://github.com/C9Glax/tranga.git
synced 2025-07-04 09:54:16 +02:00
Compare commits
13 Commits
2b18dc9d4f
...
0.3.3
Author | SHA1 | Date | |
---|---|---|---|
d9a7eeb5c3 | |||
e0784b2c38 | |||
0afbfb6010 | |||
c2872bf177 | |||
658b93bc51 | |||
3ff2ac1043 | |||
3effc7aeb6 | |||
621468f498 | |||
2c8e647a04 | |||
9d583b284a | |||
08e0fe7c71 | |||
9d104b25f8 | |||
2550beb621 |
@ -78,15 +78,15 @@ public static class Tranga_Cli
|
|||||||
string? query = Console.ReadLine();
|
string? query = Console.ReadLine();
|
||||||
while (query is null || query.Length < 1)
|
while (query is null || query.Length < 1)
|
||||||
query = Console.ReadLine();
|
query = Console.ReadLine();
|
||||||
PrintTasks(taskManager.GetAllTasks().Where(task =>
|
PrintTasks(taskManager.GetAllTasks().Where(qTask =>
|
||||||
((Publication)task.publication!).sortName.ToLower()
|
((Publication)qTask.publication!).sortName.ToLower()
|
||||||
.Contains(query, StringComparison.OrdinalIgnoreCase)).ToArray());
|
.Contains(query, StringComparison.OrdinalIgnoreCase)).ToArray());
|
||||||
Console.WriteLine("Press any key.");
|
Console.WriteLine("Press any key.");
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
menu = 0;
|
menu = 0;
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
PrintTasks(taskManager.GetAllTasks().Where(task => task.isBeingExecuted).ToArray());
|
PrintTasks(taskManager.GetAllTasks().Where(eTask => eTask.isBeingExecuted).ToArray());
|
||||||
Console.WriteLine("Press any key.");
|
Console.WriteLine("Press any key.");
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
menu = 0;
|
menu = 0;
|
||||||
@ -130,6 +130,7 @@ public static class Tranga_Cli
|
|||||||
selection = Console.ReadKey().Key;
|
selection = Console.ReadKey().Key;
|
||||||
taskManager.Shutdown(selection == ConsoleKey.Y);
|
taskManager.Shutdown(selection == ConsoleKey.Y);
|
||||||
}else
|
}else
|
||||||
|
// ReSharper disable once RedundantArgumentDefaultValue Better readability
|
||||||
taskManager.Shutdown(false);
|
taskManager.Shutdown(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +161,7 @@ public static class Tranga_Cli
|
|||||||
int tIndex = 0;
|
int tIndex = 0;
|
||||||
Console.WriteLine($"Tasks (Running/Total): {taskRunningCount}/{taskCount}");
|
Console.WriteLine($"Tasks (Running/Total): {taskRunningCount}/{taskCount}");
|
||||||
foreach(TrangaTask trangaTask in tasks)
|
foreach(TrangaTask trangaTask in tasks)
|
||||||
Console.WriteLine($"{tIndex++:000}: {trangaTask.ToString()}");
|
Console.WriteLine($"{tIndex++:000}: {trangaTask}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ExecuteTaskNow(TaskManager taskManager)
|
private static void ExecuteTaskNow(TaskManager taskManager)
|
||||||
@ -315,7 +316,7 @@ public static class Tranga_Cli
|
|||||||
selected = Console.ReadLine();
|
selected = Console.ReadLine();
|
||||||
|
|
||||||
int start = 0;
|
int start = 0;
|
||||||
int end = 0;
|
int end;
|
||||||
if (selected == "a")
|
if (selected == "a")
|
||||||
end = chapters.Length - 1;
|
end = chapters.Length - 1;
|
||||||
else if (selected.Contains('-'))
|
else if (selected.Contains('-'))
|
||||||
|
@ -13,16 +13,21 @@ public struct Chapter
|
|||||||
public string? chapterNumber { get; }
|
public string? chapterNumber { get; }
|
||||||
public string url { get; }
|
public string url { get; }
|
||||||
public string fileName { get; }
|
public string fileName { get; }
|
||||||
|
public string sortNumber { get; }
|
||||||
|
|
||||||
public Chapter(string? name, string? volumeNumber, string? chapterNumber, string url)
|
public Chapter(string? name, string? volumeNumber, string? chapterNumber, string url)
|
||||||
{
|
{
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.volumeNumber = volumeNumber;
|
this.volumeNumber = volumeNumber is { Length: > 0 } ? volumeNumber : "1";
|
||||||
this.chapterNumber = chapterNumber;
|
this.chapterNumber = chapterNumber;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
string chapterName = string.Concat((name ?? "").Split(Path.GetInvalidFileNameChars()));
|
string chapterName = string.Concat((name ?? "").Split(Path.GetInvalidFileNameChars()));
|
||||||
double multiplied = Convert.ToDouble(chapterNumber, new NumberFormatInfo() { NumberDecimalSeparator = "." }) *
|
NumberFormatInfo nfi = new NumberFormatInfo()
|
||||||
Convert.ToInt32(volumeNumber);
|
{
|
||||||
this.fileName = $"{chapterName} - V{volumeNumber}C{chapterNumber} - {multiplied.ToString(new NumberFormatInfo() { NumberDecimalSeparator = "." })}";
|
NumberDecimalSeparator = "."
|
||||||
|
};
|
||||||
|
sortNumber = decimal.Round(Convert.ToDecimal(this.volumeNumber) * Convert.ToDecimal(this.chapterNumber, nfi), 1)
|
||||||
|
.ToString(nfi);
|
||||||
|
this.fileName = $"{chapterName} - V{volumeNumber}C{chapterNumber} - {sortNumber}";
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -68,16 +68,28 @@ public abstract class Connector
|
|||||||
File.WriteAllText(seriesInfoPath,publication.GetSeriesInfoJson());
|
File.WriteAllText(seriesInfoPath,publication.GetSeriesInfoJson());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string CreateComicInfo(Publication publication, Chapter chapter)
|
protected static string CreateComicInfo(Publication publication, Chapter chapter)
|
||||||
{
|
{
|
||||||
XElement comicInfo = new XElement("ComicInfo",
|
XElement comicInfo = new XElement("ComicInfo",
|
||||||
new XElement("Tags", string.Join(',',publication.tags)),
|
new XElement("Tags", string.Join(',',publication.tags)),
|
||||||
new XElement("LanguageISO", publication.originalLanguage),
|
new XElement("LanguageISO", publication.originalLanguage),
|
||||||
new XElement("Title", chapter.name)
|
new XElement("Title", chapter.name),
|
||||||
|
new XElement("Volume", chapter.volumeNumber),
|
||||||
|
new XElement("Number", chapter.sortNumber)
|
||||||
);
|
);
|
||||||
return comicInfo.ToString();
|
return comicInfo.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool ChapterIsDownloaded(Publication publication, Chapter chapter)
|
||||||
|
{
|
||||||
|
return File.Exists(CreateFullFilepath(publication, chapter));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected string CreateFullFilepath(Publication publication, Chapter chapter)
|
||||||
|
{
|
||||||
|
return Path.Join(downloadLocation, publication.folderName, chapter.fileName);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Downloads Image from URL and saves it to the given path(incl. fileName)
|
/// Downloads Image from URL and saves it to the given path(incl. fileName)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -98,6 +110,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>
|
||||||
|
/// <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)
|
protected static void DownloadChapterImages(string[] imageUrls, string saveArchiveFilePath, DownloadClient downloadClient, string? comicInfoPath = null)
|
||||||
{
|
{
|
||||||
//Check if Publication Directory already exists
|
//Check if Publication Directory already exists
|
||||||
@ -118,7 +131,7 @@ public abstract class Connector
|
|||||||
foreach (string imageUrl in imageUrls)
|
foreach (string imageUrl in imageUrls)
|
||||||
{
|
{
|
||||||
string[] split = imageUrl.Split('.');
|
string[] split = imageUrl.Split('.');
|
||||||
string extension = split[split.Length - 1];
|
string extension = split[^1];
|
||||||
DownloadImage(imageUrl, Path.Join(tempFolder, $"{chapter++}.{extension}"), downloadClient);
|
DownloadImage(imageUrl, Path.Join(tempFolder, $"{chapter++}.{extension}"), downloadClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ public class MangaDex : Connector
|
|||||||
|
|
||||||
string title = attributes["title"]!.AsObject().ContainsKey("en") && attributes["title"]!["en"] is not null
|
string title = attributes["title"]!.AsObject().ContainsKey("en") && attributes["title"]!["en"] is not null
|
||||||
? attributes["title"]!["en"]!.GetValue<string>()
|
? 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
|
string? description = attributes["description"]!.AsObject().ContainsKey("en") && attributes["description"]!["en"] is not null
|
||||||
? attributes["description"]!["en"]!.GetValue<string?>()
|
? attributes["description"]!["en"]!.GetValue<string?>()
|
||||||
@ -201,7 +201,7 @@ public class MangaDex : Connector
|
|||||||
File.WriteAllText(comicInfoPath, CreateComicInfo(publication, chapter));
|
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(), CreateFullFilepath(publication, chapter), downloadClient, comicInfoPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void DownloadCover(Publication publication)
|
public override void DownloadCover(Publication publication)
|
||||||
@ -224,13 +224,13 @@ public class MangaDex : Connector
|
|||||||
if (result is null)
|
if (result is null)
|
||||||
return;
|
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}";
|
string coverUrl = $"https://uploads.mangadex.org/covers/{publication.downloadUrl}/{fileName}";
|
||||||
|
|
||||||
//Get file-extension (jpg, png)
|
//Get file-extension (jpg, png)
|
||||||
string[] split = coverUrl.Split('.');
|
string[] split = coverUrl.Split('.');
|
||||||
string extension = split[split.Length - 1];
|
string extension = split[^1];
|
||||||
|
|
||||||
string outFolderPath = Path.Join(downloadLocation, publication.folderName);
|
string outFolderPath = Path.Join(downloadLocation, publication.folderName);
|
||||||
Directory.CreateDirectory(outFolderPath);
|
Directory.CreateDirectory(outFolderPath);
|
||||||
|
@ -5,10 +5,12 @@ namespace Tranga;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Contains information on a Publication (Manga)
|
/// Contains information on a Publication (Manga)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public struct Publication
|
public readonly struct Publication
|
||||||
{
|
{
|
||||||
public string sortName { get; }
|
public string sortName { get; }
|
||||||
|
// ReSharper disable UnusedAutoPropertyAccessor.Global we need it, trust
|
||||||
[JsonIgnore]public string[,] altTitles { get; }
|
[JsonIgnore]public string[,] altTitles { get; }
|
||||||
|
// ReSharper disable trice MemberCanBePrivate.Global, trust
|
||||||
public string? description { get; }
|
public string? description { get; }
|
||||||
public string[] tags { get; }
|
public string[] tags { get; }
|
||||||
public string? posterUrl { get; }
|
public string? posterUrl { get; }
|
||||||
@ -31,7 +33,7 @@ public struct Publication
|
|||||||
this.originalLanguage = originalLanguage;
|
this.originalLanguage = originalLanguage;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.downloadUrl = downloadUrl;
|
this.downloadUrl = downloadUrl;
|
||||||
this.folderName = string.Concat(sortName.Split(Path.GetInvalidPathChars()));
|
this.folderName = string.Concat(sortName.Split(Path.GetInvalidPathChars().Concat(Path.GetInvalidFileNameChars()).ToArray()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -47,6 +49,7 @@ public struct Publication
|
|||||||
//Only for series.json
|
//Only for series.json
|
||||||
private struct SeriesInfo
|
private struct SeriesInfo
|
||||||
{
|
{
|
||||||
|
// ReSharper disable once UnusedAutoPropertyAccessor.Local we need it, trust
|
||||||
[JsonRequired]public Metadata metadata { get; }
|
[JsonRequired]public Metadata metadata { get; }
|
||||||
public SeriesInfo(Metadata metadata) => this.metadata = metadata;
|
public SeriesInfo(Metadata metadata) => this.metadata = metadata;
|
||||||
}
|
}
|
||||||
@ -54,6 +57,7 @@ public struct Publication
|
|||||||
//Only for series.json what an abomination, why are all the fields not-null????
|
//Only for series.json what an abomination, why are all the fields not-null????
|
||||||
private struct Metadata
|
private struct Metadata
|
||||||
{
|
{
|
||||||
|
// ReSharper disable UnusedAutoPropertyAccessor.Local we need it, trust
|
||||||
[JsonRequired] public string type { get; }
|
[JsonRequired] public string type { get; }
|
||||||
[JsonRequired] public string publisher { get; }
|
[JsonRequired] public string publisher { get; }
|
||||||
// ReSharper disable twice IdentifierTypo
|
// ReSharper disable twice IdentifierTypo
|
||||||
|
@ -93,14 +93,11 @@ public static class TaskExecutor
|
|||||||
private static List<Chapter> UpdateChapters(Connector connector, Publication publication, string language, Dictionary<Publication, List<Chapter>> chapterCollection)
|
private static List<Chapter> UpdateChapters(Connector connector, Publication publication, string language, Dictionary<Publication, List<Chapter>> chapterCollection)
|
||||||
{
|
{
|
||||||
List<Chapter> newChaptersList = new();
|
List<Chapter> newChaptersList = new();
|
||||||
if (!chapterCollection.ContainsKey(publication))
|
chapterCollection.TryAdd(publication, newChaptersList); //To ensure publication is actually in collection
|
||||||
return newChaptersList;
|
|
||||||
|
|
||||||
List<Chapter> currentChapters = chapterCollection[publication];
|
|
||||||
Chapter[] newChapters = connector.GetChapters(publication, language);
|
Chapter[] newChapters = connector.GetChapters(publication, language);
|
||||||
|
newChaptersList = newChapters.Where(nChapter => !connector.ChapterIsDownloaded(publication, nChapter)).ToList();
|
||||||
|
|
||||||
newChaptersList = newChapters.ToList()
|
|
||||||
.ExceptBy(currentChapters.Select(cChapter => cChapter.url), nChapter => nChapter.url).ToList();
|
|
||||||
return newChaptersList;
|
return newChaptersList;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -12,8 +12,7 @@ public class TaskManager
|
|||||||
private readonly Dictionary<Publication, List<Chapter>> _chapterCollection;
|
private readonly Dictionary<Publication, List<Chapter>> _chapterCollection;
|
||||||
private readonly HashSet<TrangaTask> _allTasks;
|
private readonly HashSet<TrangaTask> _allTasks;
|
||||||
private bool _continueRunning = true;
|
private bool _continueRunning = true;
|
||||||
private readonly Connector[] connectors;
|
private readonly Connector[] _connectors;
|
||||||
private readonly string folderPath;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -21,8 +20,7 @@ public class TaskManager
|
|||||||
/// <param name="folderPath">Local path to save data (Manga) to</param>
|
/// <param name="folderPath">Local path to save data (Manga) to</param>
|
||||||
public TaskManager(string folderPath)
|
public TaskManager(string folderPath)
|
||||||
{
|
{
|
||||||
this.folderPath = folderPath;
|
this._connectors = new Connector[]{ new MangaDex(folderPath) };
|
||||||
this.connectors = new Connector[]{ new MangaDex(folderPath) };
|
|
||||||
_chapterCollection = new();
|
_chapterCollection = new();
|
||||||
_allTasks = ImportTasks(Directory.GetCurrentDirectory());
|
_allTasks = ImportTasks(Directory.GetCurrentDirectory());
|
||||||
Thread taskChecker = new(TaskCheckerThread);
|
Thread taskChecker = new(TaskCheckerThread);
|
||||||
@ -36,7 +34,7 @@ public class TaskManager
|
|||||||
foreach (TrangaTask task in _allTasks)
|
foreach (TrangaTask task in _allTasks)
|
||||||
{
|
{
|
||||||
if(task.ShouldExecute())
|
if(task.ShouldExecute())
|
||||||
TaskExecutor.Execute(this.connectors, task, this._chapterCollection);
|
TaskExecutor.Execute(this._connectors, task, this._chapterCollection); //Might crash here, when adding new Task while another Task is running. Check later
|
||||||
}
|
}
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(1000);
|
||||||
}
|
}
|
||||||
@ -53,7 +51,7 @@ public class TaskManager
|
|||||||
|
|
||||||
Task t = new Task(() =>
|
Task t = new Task(() =>
|
||||||
{
|
{
|
||||||
TaskExecutor.Execute(this.connectors, task, this._chapterCollection);
|
TaskExecutor.Execute(this._connectors, task, this._chapterCollection);
|
||||||
});
|
});
|
||||||
t.Start();
|
t.Start();
|
||||||
}
|
}
|
||||||
@ -71,7 +69,7 @@ public class TaskManager
|
|||||||
string language = "")
|
string language = "")
|
||||||
{
|
{
|
||||||
//Get appropriate Connector from available Connectors for TrangaTask
|
//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)
|
if (connector is null)
|
||||||
throw new ArgumentException($"Connector {connectorName} is not a known connector.");
|
throw new ArgumentException($"Connector {connectorName} is not a known connector.");
|
||||||
|
|
||||||
@ -108,7 +106,7 @@ public class TaskManager
|
|||||||
/// <returns>All available Connectors</returns>
|
/// <returns>All available Connectors</returns>
|
||||||
public Dictionary<string, Connector> GetAvailableConnectors()
|
public Dictionary<string, Connector> GetAvailableConnectors()
|
||||||
{
|
{
|
||||||
return this.connectors.ToDictionary(connector => connector.name, connector => connector);
|
return this._connectors.ToDictionary(connector => connector.name, connector => connector);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -7,6 +7,8 @@ namespace Tranga;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class TrangaTask
|
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 TimeSpan reoccurrence { get; }
|
||||||
public DateTime lastExecuted { get; set; }
|
public DateTime lastExecuted { get; set; }
|
||||||
public string connectorName { get; }
|
public string connectorName { get; }
|
||||||
|
Reference in New Issue
Block a user