From 0fba6c68003f497f0e5b9872d4b82a35607996a4 Mon Sep 17 00:00:00 2001 From: Koitharu Date: Tue, 15 Oct 2024 10:47:03 +0300 Subject: [PATCH] Add verbose flag --- src/main/kotlin/org/koitharu/kotatsu/dl/Main.kt | 5 +++++ .../kotatsu/dl/download/LocalMangaOutput.kt | 2 +- .../kotatsu/dl/download/MangaDownloader.kt | 15 ++++++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/org/koitharu/kotatsu/dl/Main.kt b/src/main/kotlin/org/koitharu/kotatsu/dl/Main.kt index 82f0ec0..8ef431c 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/dl/Main.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/dl/Main.kt @@ -52,6 +52,10 @@ class Main : AppCommand(name = "kotatsu-dl") { ).convert { ChaptersRange.parse(it) }.validate { range -> range.validate() } + private val verbose: Boolean by option( + names = arrayOf("-v", "--verbose"), + help = "Show more information" + ).flag(default = false) override suspend fun invoke(): Int { val context = MangaLoaderContextImpl() @@ -107,6 +111,7 @@ class Main : AppCommand(name = "kotatsu-dl") { chaptersRange = range, format = format, throttle = throttle, + verbose = verbose, ) val file = downloader.download() colored { diff --git a/src/main/kotlin/org/koitharu/kotatsu/dl/download/LocalMangaOutput.kt b/src/main/kotlin/org/koitharu/kotatsu/dl/download/LocalMangaOutput.kt index 4671b02..76096b7 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/dl/download/LocalMangaOutput.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/dl/download/LocalMangaOutput.kt @@ -39,7 +39,7 @@ sealed class LocalMangaOutput( } else { DownloadFormat.DIR } - var file = if (target.isDirectory || (!target.exists() && format == DownloadFormat.DIR)) { + var file = if (target.isDirectory || (!target.exists() && targetFormat == DownloadFormat.DIR)) { if (!target.exists()) { target.mkdirs() } diff --git a/src/main/kotlin/org/koitharu/kotatsu/dl/download/MangaDownloader.kt b/src/main/kotlin/org/koitharu/kotatsu/dl/download/MangaDownloader.kt index 1f3e01d..2ab137b 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/dl/download/MangaDownloader.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/dl/download/MangaDownloader.kt @@ -34,6 +34,7 @@ class MangaDownloader( private val chaptersRange: ChaptersRange, private val format: DownloadFormat?, private val throttle: Boolean, + private val verbose: Boolean, ) { private val progressBarStyle = ProgressBarStyle.builder() @@ -44,13 +45,19 @@ class MangaDownloader( .build() suspend fun download(): File { + val output = LocalMangaOutput.create(destination ?: File("").absoluteFile, manga, format) + if (verbose) { + colored { + print("Output: ".cyan) + println(output.rootFile.canonicalPath) + } + } val progressBar = ProgressBarBuilder() .setStyle(progressBarStyle) .setTaskName("Downloading") .clearDisplayOnFinish() .build() progressBar.setExtraMessage("Preparing...") - val output = LocalMangaOutput.create(destination ?: File(""), manga, format) val tempDir = Files.createTempDirectory("kdl_").toFile() val counters = MutableIntList() val totalChapters = chaptersRange.size(chapters) @@ -96,6 +103,12 @@ class MangaDownloader( return output.rootFile.canonicalFile } catch (e: Throwable) { progressBar.close() + if (e is CancellationException) { + colored { + println() + println("Interrupted by user".red) + } + } throw e } finally { withContext(NonCancellable) {