Replace fragile Niadd patch with patch script
Build Futon with Niadd patch / Build debug APK (push) Successful in 12m49s
Build Futon with Niadd patch / Build debug APK (push) Successful in 12m49s
This commit is contained in:
3 files changed
+128
-48
No files matched your search
@@ -0,0 +1,106 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
|
||||
if len(sys.argv) != 2:
|
||||
print(f"Usage: {sys.argv[0]} <kotatsu-parsers-redo-dir>", file=sys.stderr)
|
||||
sys.exit(2)
|
||||
|
||||
|
||||
repo_dir = Path(sys.argv[1]).resolve()
|
||||
|
||||
parser_file = (
|
||||
repo_dir
|
||||
/ "src/main/kotlin/org/koitharu/kotatsu/parsers/site/all/NineMangaParser.kt"
|
||||
)
|
||||
|
||||
if not parser_file.is_file():
|
||||
print(f"ERROR: parser file not found: {parser_file}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
text = parser_file.read_text(encoding="utf-8")
|
||||
|
||||
|
||||
def replace_exact(name: str, old: str, new: str) -> None:
|
||||
global text
|
||||
|
||||
count = text.count(old)
|
||||
|
||||
if count != 1:
|
||||
print(
|
||||
f"ERROR: patch '{name}' expected exactly 1 match, found {count}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
print(
|
||||
"Upstream NineMangaParser.kt has probably changed.",
|
||||
file=sys.stderr,
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
text = text.replace(old, new, 1)
|
||||
print(f"[OK] {name}")
|
||||
|
||||
|
||||
replace_exact(
|
||||
"Niadd category pagination",
|
||||
''' } else {
|
||||
append("/category/index_")
|
||||
append(page.toString())
|
||||
}
|
||||
''',
|
||||
''' } else if (domain.endsWith("niadd.com")) {
|
||||
if (page == 1) {
|
||||
append("/category/")
|
||||
} else {
|
||||
append("/category/index_")
|
||||
append(page.toString())
|
||||
append(".html")
|
||||
}
|
||||
} else {
|
||||
append("/category/index_")
|
||||
append(page.toString())
|
||||
}
|
||||
''',
|
||||
)
|
||||
|
||||
|
||||
replace_exact(
|
||||
"Russian status parsing",
|
||||
''' //ru
|
||||
status.contains("постоянный") -> MangaState.ONGOING
|
||||
status.contains("завершенный") -> MangaState.FINISHED
|
||||
''',
|
||||
''' //ru
|
||||
status.contains("постоянный", ignoreCase = true) -> MangaState.ONGOING
|
||||
status.contains("завершенный", ignoreCase = true) -> MangaState.FINISHED
|
||||
''',
|
||||
)
|
||||
|
||||
|
||||
replace_exact(
|
||||
"NineManga RU to Niadd RU",
|
||||
''' @Broken
|
||||
@MangaSourceParser("NINEMANGA_RU", "NineManga Русский", "ru")
|
||||
class Russian(context: MangaLoaderContext) : NineMangaParser(
|
||||
context,
|
||||
MangaParserSource.NINEMANGA_RU,
|
||||
"ru.ninemanga.com",
|
||||
)
|
||||
''',
|
||||
''' @MangaSourceParser("NINEMANGA_RU", "Niadd Русский", "ru")
|
||||
class Russian(context: MangaLoaderContext) : NineMangaParser(
|
||||
context,
|
||||
MangaParserSource.NINEMANGA_RU,
|
||||
"ru.niadd.com",
|
||||
)
|
||||
''',
|
||||
)
|
||||
|
||||
|
||||
parser_file.write_text(text, encoding="utf-8")
|
||||
|
||||
print()
|
||||
print(f"[OK] Patched: {parser_file}")
|
||||
Reference in new issue
Block a user