diff --git a/README.md b/README.md index fd67c74..76d6836 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ Options: --throttle Slow down downloading to avoid blocking your IP address by server --chapters= 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: diff --git a/src/main/kotlin/org/koitharu/kotatsu/dl/Main.kt b/src/main/kotlin/org/koitharu/kotatsu/dl/Main.kt index 47f9a3a..5ab6b33 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/dl/Main.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/dl/Main.kt @@ -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) diff --git a/src/main/kotlin/org/koitharu/kotatsu/dl/ui/SourcesList.kt b/src/main/kotlin/org/koitharu/kotatsu/dl/ui/SourcesList.kt new file mode 100644 index 0000000..42bee5a --- /dev/null +++ b/src/main/kotlin/org/koitharu/kotatsu/dl/ui/SourcesList.kt @@ -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) +} \ No newline at end of file