10 Commits
0.3 ... 0.3.3

Author SHA1 Message Date
d9a7eeb5c3 Why is it so complicated to multiply some numbers 2023-05-20 02:42:36 +02:00
e0784b2c38 Added field sortNumber to chapter 2023-05-20 02:39:23 +02:00
0afbfb6010 Add Volume and chapter number to ComicInfo.xml 2023-05-20 02:29:54 +02:00
c2872bf177 cutoff after first decimal 2023-05-20 02:23:37 +02:00
658b93bc51 I hate floating point 2023-05-20 02:10:10 +02:00
3ff2ac1043 Changed numbering scheme, because floating point. 2023-05-20 01:56:33 +02:00
3effc7aeb6 Check later 2023-05-20 01:35:19 +02:00
621468f498 Added InvalidFileNameCharacters to list of replaced Characters in folder-names 2023-05-20 01:31:06 +02:00
2c8e647a04 Simplification 2023-05-20 01:30:34 +02:00
9d583b284a Created Method to check wether file is already downloaded.
Using this method when running TaskExecutor.UpdateChapters to get a list of all chapters that have not yet been downloaded.
2023-05-20 01:30:23 +02:00
6 changed files with 27 additions and 13 deletions

View File

@ -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}";
} }
} }

View File

@ -73,10 +73,22 @@ public abstract class Connector
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)

View File

@ -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)

View File

@ -33,7 +33,7 @@ public readonly 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>

View File

@ -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;
} }
} }

View File

@ -34,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);
} }