Add verbose flag

This commit is contained in:
Koitharu
2024-10-15 10:47:03 +03:00
parent 74d95c5d42
commit 0fba6c6800
3 changed files with 20 additions and 2 deletions

View File

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

View File

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

View File

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