mirror of
https://github.com/C9Glax/tranga.git
synced 2025-09-10 03:48:19 +02:00
Order the chapters
This commit is contained in:
@@ -144,6 +144,20 @@ public class Chapter : Identifiable, IComparable<Chapter>
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
public class ChapterComparer : IComparer<Chapter>
|
||||
{
|
||||
public int Compare(Chapter? x, Chapter? y)
|
||||
{
|
||||
if (x is null && y is null)
|
||||
return 0;
|
||||
if(x is null)
|
||||
return -1;
|
||||
if (y is null)
|
||||
return 1;
|
||||
return CompareChapterNumbers(x.ChapterNumber, y.ChapterNumber);
|
||||
}
|
||||
}
|
||||
|
||||
private static int CompareChapterNumbers(string ch1, string ch2)
|
||||
{
|
||||
int[] ch1Arr = ch1.Split('.').Select(c => int.TryParse(c, out int result) ? result : -1).ToArray();
|
||||
|
@@ -27,9 +27,9 @@ public class StartNewChapterDownloadsWorker(TimeSpan? interval = null, IEnumerab
|
||||
// Maximum Concurrent workers
|
||||
int downloadWorkers = Tranga.GetRunningWorkers().Count(w => w.GetType() == typeof(DownloadChapterFromMangaconnectorWorker));
|
||||
int amountNewWorkers = Math.Min(Tranga.Settings.MaxConcurrentDownloads, Tranga.Settings.MaxConcurrentDownloads - downloadWorkers);
|
||||
|
||||
Log.Debug($"{downloadWorkers} running download Workers. {amountNewWorkers} new download Workers.");
|
||||
IEnumerable<MangaConnectorId<Chapter>> newDownloadChapters = missingChapters.Take(amountNewWorkers);
|
||||
|
||||
IEnumerable<MangaConnectorId<Chapter>> newDownloadChapters = missingChapters.OrderBy(ch => ch.Obj, new Chapter.ChapterComparer()).Take(amountNewWorkers);
|
||||
|
||||
// Create new jobs
|
||||
List<BaseWorker> newWorkers = newDownloadChapters.Select(mcId => new DownloadChapterFromMangaconnectorWorker(mcId)).ToList<BaseWorker>();
|
||||
|
Reference in New Issue
Block a user