Add verbose flag
This commit is contained in:
@@ -52,6 +52,10 @@ class Main : AppCommand(name = "kotatsu-dl") {
|
|||||||
).convert {
|
).convert {
|
||||||
ChaptersRange.parse(it)
|
ChaptersRange.parse(it)
|
||||||
}.validate { range -> range.validate() }
|
}.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 {
|
override suspend fun invoke(): Int {
|
||||||
val context = MangaLoaderContextImpl()
|
val context = MangaLoaderContextImpl()
|
||||||
@@ -107,6 +111,7 @@ class Main : AppCommand(name = "kotatsu-dl") {
|
|||||||
chaptersRange = range,
|
chaptersRange = range,
|
||||||
format = format,
|
format = format,
|
||||||
throttle = throttle,
|
throttle = throttle,
|
||||||
|
verbose = verbose,
|
||||||
)
|
)
|
||||||
val file = downloader.download()
|
val file = downloader.download()
|
||||||
colored {
|
colored {
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ sealed class LocalMangaOutput(
|
|||||||
} else {
|
} else {
|
||||||
DownloadFormat.DIR
|
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()) {
|
if (!target.exists()) {
|
||||||
target.mkdirs()
|
target.mkdirs()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ class MangaDownloader(
|
|||||||
private val chaptersRange: ChaptersRange,
|
private val chaptersRange: ChaptersRange,
|
||||||
private val format: DownloadFormat?,
|
private val format: DownloadFormat?,
|
||||||
private val throttle: Boolean,
|
private val throttle: Boolean,
|
||||||
|
private val verbose: Boolean,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val progressBarStyle = ProgressBarStyle.builder()
|
private val progressBarStyle = ProgressBarStyle.builder()
|
||||||
@@ -44,13 +45,19 @@ class MangaDownloader(
|
|||||||
.build()
|
.build()
|
||||||
|
|
||||||
suspend fun download(): File {
|
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()
|
val progressBar = ProgressBarBuilder()
|
||||||
.setStyle(progressBarStyle)
|
.setStyle(progressBarStyle)
|
||||||
.setTaskName("Downloading")
|
.setTaskName("Downloading")
|
||||||
.clearDisplayOnFinish()
|
.clearDisplayOnFinish()
|
||||||
.build()
|
.build()
|
||||||
progressBar.setExtraMessage("Preparing...")
|
progressBar.setExtraMessage("Preparing...")
|
||||||
val output = LocalMangaOutput.create(destination ?: File(""), manga, format)
|
|
||||||
val tempDir = Files.createTempDirectory("kdl_").toFile()
|
val tempDir = Files.createTempDirectory("kdl_").toFile()
|
||||||
val counters = MutableIntList()
|
val counters = MutableIntList()
|
||||||
val totalChapters = chaptersRange.size(chapters)
|
val totalChapters = chaptersRange.size(chapters)
|
||||||
@@ -96,6 +103,12 @@ class MangaDownloader(
|
|||||||
return output.rootFile.canonicalFile
|
return output.rootFile.canonicalFile
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
progressBar.close()
|
progressBar.close()
|
||||||
|
if (e is CancellationException) {
|
||||||
|
colored {
|
||||||
|
println()
|
||||||
|
println("Interrupted by user".red)
|
||||||
|
}
|
||||||
|
}
|
||||||
throw e
|
throw e
|
||||||
} finally {
|
} finally {
|
||||||
withContext(NonCancellable) {
|
withContext(NonCancellable) {
|
||||||
|
|||||||
Reference in New Issue
Block a user