Option to show list of supported sources
This commit is contained in:
@@ -35,6 +35,7 @@ Options:
|
||||
--throttle Slow down downloading to avoid blocking your IP address by server
|
||||
--chapters=<numbers or range> Numbers of chapters to download. Can be a single numbers or range, e.g. "1-4,8,11" or "all"
|
||||
-v, --verbose Show more information
|
||||
--sources Show list of supported manga sources and exit
|
||||
-h, --help Show this message and exit
|
||||
|
||||
Arguments:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.koitharu.kotatsu.dl
|
||||
|
||||
import com.github.ajalt.clikt.command.main
|
||||
import com.github.ajalt.clikt.core.ProgramResult
|
||||
import com.github.ajalt.clikt.parameters.arguments.argument
|
||||
import com.github.ajalt.clikt.parameters.options.*
|
||||
import com.github.ajalt.clikt.parameters.types.enum
|
||||
@@ -12,6 +13,7 @@ import org.koitharu.kotatsu.dl.download.DownloadFormat
|
||||
import org.koitharu.kotatsu.dl.download.MangaDownloader
|
||||
import org.koitharu.kotatsu.dl.parsers.MangaLoaderContextImpl
|
||||
import org.koitharu.kotatsu.dl.ui.askSelectBranch
|
||||
import org.koitharu.kotatsu.dl.ui.printSourcesList
|
||||
import org.koitharu.kotatsu.dl.util.AppCommand
|
||||
import org.koitharu.kotatsu.dl.util.ChaptersRange
|
||||
import org.koitharu.kotatsu.dl.util.colored
|
||||
@@ -63,6 +65,16 @@ class Main : AppCommand(name = "kotatsu-dl") {
|
||||
help = "Show more information"
|
||||
).flag(default = false)
|
||||
|
||||
init {
|
||||
eagerOption(
|
||||
names = arrayOf("--sources"),
|
||||
help = "Show list of supported manga sources and exit"
|
||||
) {
|
||||
MangaLoaderContextImpl().printSourcesList()
|
||||
throw ProgramResult(0)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun invoke(): Int {
|
||||
val context = MangaLoaderContextImpl()
|
||||
val linkResolver = context.newLinkResolver(link)
|
||||
|
||||
51
src/main/kotlin/org/koitharu/kotatsu/dl/ui/SourcesList.kt
Normal file
51
src/main/kotlin/org/koitharu/kotatsu/dl/ui/SourcesList.kt
Normal file
@@ -0,0 +1,51 @@
|
||||
package org.koitharu.kotatsu.dl.ui
|
||||
|
||||
import org.koitharu.kotatsu.dl.util.colored
|
||||
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
||||
import org.koitharu.kotatsu.parsers.model.ContentType
|
||||
import org.koitharu.kotatsu.parsers.model.MangaParserSource
|
||||
import org.koitharu.kotatsu.parsers.util.toTitleCase
|
||||
import java.util.*
|
||||
|
||||
fun MangaLoaderContext.printSourcesList() {
|
||||
println("List of supported sources:")
|
||||
val groups = MangaParserSource.entries.groupBy { it.locale }
|
||||
for (group in groups) {
|
||||
colored {
|
||||
print(" - ")
|
||||
println(group.key.toLocaleName().cyan)
|
||||
}
|
||||
val sources = group.value.sortedBy { it.title }
|
||||
for (source in sources) {
|
||||
val parser = try {
|
||||
newParserInstance(source)
|
||||
} catch (_: Throwable) {
|
||||
continue
|
||||
}
|
||||
colored {
|
||||
print(source.title.bold)
|
||||
print(' ')
|
||||
print("https://")
|
||||
print(parser.domain)
|
||||
print(' ')
|
||||
when (source.contentType) {
|
||||
ContentType.HENTAI -> print("[Hentai]".yellow)
|
||||
ContentType.COMICS -> print("[Comics]".yellow)
|
||||
else -> Unit
|
||||
}
|
||||
if (source.isBroken) {
|
||||
print("[Broken]".red)
|
||||
}
|
||||
println()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun String.toLocaleName(): String {
|
||||
if (isEmpty()) {
|
||||
return "Multilingual"
|
||||
}
|
||||
val lc = Locale(this)
|
||||
return lc.getDisplayName(lc).toTitleCase(lc)
|
||||
}
|
||||
Reference in New Issue
Block a user