mirror of
https://github.com/C9Glax/tranga.git
synced 2025-06-14 15:27:53 +02:00
Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
d9a7eeb5c3 | |||
e0784b2c38 | |||
0afbfb6010 | |||
c2872bf177 | |||
658b93bc51 | |||
3ff2ac1043 | |||
3effc7aeb6 | |||
621468f498 | |||
2c8e647a04 | |||
9d583b284a |
@ -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}";
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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)
|
||||||
|
@ -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)
|
||||||
|
@ -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>
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user