Skip to content

Commit

Permalink
Update parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
Koitharu committed Feb 25, 2025
1 parent 2114098 commit 5f10ff9
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies {
testImplementation(kotlin("test"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.9.0")
implementation("com.github.ajalt.clikt:clikt-core:5.0.1")
implementation("com.github.KotatsuApp:kotatsu-parsers:764c65563b")
implementation("com.github.KotatsuApp:kotatsu-parsers:1.6")
implementation("com.squareup.okhttp3:okhttp:4.12.0")
implementation("com.squareup.okio:okio:3.9.0")
implementation("io.webfolder:quickjs:1.1.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import kotlinx.coroutines.runInterruptible
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import okhttp3.internal.closeQuietly
import org.koitharu.kotatsu.dl.util.toFileNameSafe
import org.koitharu.kotatsu.parsers.model.Manga
import org.koitharu.kotatsu.parsers.model.MangaChapter
import org.koitharu.kotatsu.parsers.util.toFileNameSafe
import java.io.File

class LocalMangaDirOutput(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runInterruptible
import okio.Closeable
import org.koitharu.kotatsu.dl.util.getNextAvailable
import org.koitharu.kotatsu.dl.util.toFileNameSafe
import org.koitharu.kotatsu.parsers.model.Manga
import org.koitharu.kotatsu.parsers.model.MangaChapter
import org.koitharu.kotatsu.parsers.util.toFileNameSafe
import java.io.File

sealed class LocalMangaOutput(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class MangaDownloader(
val totalChapters = chaptersRange.size(chapters)
try {
val parser = context.newParserInstance(manga.source as MangaParserSource)
val coverUrl = manga.largeCoverUrl.ifNullOrEmpty { manga.coverUrl }
val coverUrl = manga.largeCoverUrl.ifNullOrEmpty { manga.coverUrl.orEmpty() }
if (coverUrl.isNotEmpty()) {
downloadFile(coverUrl, tempDir, parser.source).let { file ->
output.addCover(file, getFileExtensionFromUrl(coverUrl).orEmpty())
Expand Down
30 changes: 30 additions & 0 deletions src/main/kotlin/org/koitharu/kotatsu/dl/util/Util.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.koitharu.kotatsu.dl.util

import androidx.collection.IntList
import androidx.collection.arraySetOf
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
import okhttp3.Response
import okhttp3.internal.closeQuietly
Expand Down Expand Up @@ -51,3 +52,32 @@ fun File.getNextAvailable(): File {
}
}
}

fun String.transliterate(skipMissing: Boolean): String {
val cyr = charArrayOf(
'а', 'б', 'в', 'г', 'д', 'е', 'ж', 'з', 'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п',
'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ъ', 'ы', 'ь', 'э', 'ю', 'я', 'ё', 'ў',
)
val lat = arrayOf(
"a", "b", "v", "g", "d", "e", "zh", "z", "i", "y", "k", "l", "m", "n", "o", "p",
"r", "s", "t", "u", "f", "h", "ts", "ch", "sh", "sch", "", "i", "", "e", "ju", "ja", "jo", "w",
)
return buildString(length + 5) {
for (c in this@transliterate) {
val p = cyr.binarySearch(c.lowercaseChar())
if (p in lat.indices) {
if (c.isUpperCase()) {
append(lat[p].uppercase())
} else {
append(lat[p])
}
} else if (!skipMissing) {
append(c)
}
}
}
}

fun String.toFileNameSafe(): String = this.transliterate(false)
.replace(Regex("[^a-z0-9_\\-]", arraySetOf(RegexOption.IGNORE_CASE)), " ")
.replace(Regex("\\s+"), "_")

0 comments on commit 5f10ff9

Please sign in to comment.