WP Mangastream - refactor, fixes (#2680)
This commit is contained in:
parent
4ab893f4d8
commit
1584eba36a
|
@ -5,7 +5,7 @@ ext {
|
||||||
appName = 'Tachiyomi: WP Manga Stream'
|
appName = 'Tachiyomi: WP Manga Stream'
|
||||||
pkgNameSuffix = 'all.wpmangastream'
|
pkgNameSuffix = 'all.wpmangastream'
|
||||||
extClass = '.WPMangaStreamFactory'
|
extClass = '.WPMangaStreamFactory'
|
||||||
extVersionCode = 7
|
extVersionCode = 8
|
||||||
libVersion = '1.2'
|
libVersion = '1.2'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,9 +19,17 @@ import org.jsoup.nodes.Element
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
import java.lang.UnsupportedOperationException
|
import java.lang.UnsupportedOperationException
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.Locale
|
||||||
|
import java.util.Calendar
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
abstract class WPMangaStream(override val name: String, override val baseUrl: String, override val lang: String) : ConfigurableSource, ParsedHttpSource() {
|
abstract class WPMangaStream(
|
||||||
|
override val name: String,
|
||||||
|
override val baseUrl: String,
|
||||||
|
override val lang: String,
|
||||||
|
private val dateFormat: SimpleDateFormat = SimpleDateFormat("MMM d, yyyy", Locale.US)
|
||||||
|
) : ConfigurableSource, ParsedHttpSource() {
|
||||||
override val supportsLatest = true
|
override val supportsLatest = true
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -168,17 +176,52 @@ abstract class WPMangaStream(override val name: String, override val baseUrl: St
|
||||||
else -> SManga.UNKNOWN
|
else -> SManga.UNKNOWN
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun chapterListSelector() = "div.bxcl ul li"
|
override fun chapterListSelector() = "div.bxcl ul li, div.cl ul li"
|
||||||
|
|
||||||
override fun chapterFromElement(element: Element): SChapter {
|
override fun chapterFromElement(element: Element): SChapter {
|
||||||
val urlElement = element.select(".lchx > a").first()
|
val urlElement = element.select(".lchx > a, span.leftoff a").first()
|
||||||
val chapter = SChapter.create()
|
val chapter = SChapter.create()
|
||||||
chapter.setUrlWithoutDomain(urlElement.attr("href"))
|
chapter.setUrlWithoutDomain(urlElement.attr("href"))
|
||||||
chapter.name = urlElement.text()
|
chapter.name = urlElement.text()
|
||||||
chapter.date_upload = 0
|
chapter.date_upload = element.select("span.rightoff, time").firstOrNull()?.text()?.let { parseChapterDate(it) } ?: 0
|
||||||
return chapter
|
return chapter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun parseChapterDate(date: String): Long {
|
||||||
|
return if (date.contains("ago")) {
|
||||||
|
val value = date.split(' ')[0].toInt()
|
||||||
|
when {
|
||||||
|
"min" in date -> Calendar.getInstance().apply {
|
||||||
|
add(Calendar.MINUTE, value * -1)
|
||||||
|
}.timeInMillis
|
||||||
|
"hour" in date -> Calendar.getInstance().apply {
|
||||||
|
add(Calendar.HOUR_OF_DAY, value * -1)
|
||||||
|
}.timeInMillis
|
||||||
|
"day" in date -> Calendar.getInstance().apply {
|
||||||
|
add(Calendar.DATE, value * -1)
|
||||||
|
}.timeInMillis
|
||||||
|
"week" in date -> Calendar.getInstance().apply {
|
||||||
|
add(Calendar.DATE, value * 7 * -1)
|
||||||
|
}.timeInMillis
|
||||||
|
"month" in date -> Calendar.getInstance().apply {
|
||||||
|
add(Calendar.MONTH, value * -1)
|
||||||
|
}.timeInMillis
|
||||||
|
"year" in date -> Calendar.getInstance().apply {
|
||||||
|
add(Calendar.YEAR, value * -1)
|
||||||
|
}.timeInMillis
|
||||||
|
else -> {
|
||||||
|
0L
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
dateFormat.parse(date).time
|
||||||
|
} catch (_: Exception) {
|
||||||
|
0L
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun prepareNewChapter(chapter: SChapter, manga: SManga) {
|
override fun prepareNewChapter(chapter: SChapter, manga: SManga) {
|
||||||
val basic = Regex("""Chapter\s([0-9]+)""")
|
val basic = Regex("""Chapter\s([0-9]+)""")
|
||||||
when {
|
when {
|
||||||
|
|
|
@ -12,14 +12,9 @@ import okhttp3.Request
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import okhttp3.Interceptor
|
import okhttp3.Interceptor
|
||||||
import okhttp3.HttpUrl
|
import okhttp3.HttpUrl
|
||||||
import org.json.JSONObject
|
|
||||||
import org.jsoup.nodes.Document
|
import org.jsoup.nodes.Document
|
||||||
import org.jsoup.nodes.Element
|
import org.jsoup.nodes.Element
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
import java.text.ParseException
|
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.util.Locale
|
|
||||||
import java.util.Calendar
|
|
||||||
|
|
||||||
class WPMangaStreamFactory : SourceFactory {
|
class WPMangaStreamFactory : SourceFactory {
|
||||||
override fun createSources(): List<Source> = listOf(
|
override fun createSources(): List<Source> = listOf(
|
||||||
|
@ -126,62 +121,9 @@ class KomikCast : WPMangaStream("Komik Cast (WP Manga Stream)", "https://komikca
|
||||||
return manga
|
return manga
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun chapterListSelector() = "div.cl ul li"
|
override fun pageListParse(document: Document): List<Page> {
|
||||||
|
return document.select("div#readerarea img.size-full")
|
||||||
override fun chapterFromElement(element: Element): SChapter {
|
.mapIndexed { i, img -> Page(i, "", img.attr("abs:Src")) }
|
||||||
val urlElement = element.select("a").first()
|
|
||||||
val timeElement = element.select("span.rightoff").first()
|
|
||||||
val chapter = SChapter.create()
|
|
||||||
chapter.setUrlWithoutDomain(urlElement.attr("href"))
|
|
||||||
chapter.name = urlElement.text()
|
|
||||||
chapter.date_upload = parseChapterDate(timeElement.text())
|
|
||||||
return chapter
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun parseChapterDate(date: String): Long {
|
|
||||||
val value = date.split(' ')[0].toInt()
|
|
||||||
|
|
||||||
return when {
|
|
||||||
"mins" in date -> Calendar.getInstance().apply {
|
|
||||||
add(Calendar.MINUTE, value * -1)
|
|
||||||
}.timeInMillis
|
|
||||||
"hours" in date -> Calendar.getInstance().apply {
|
|
||||||
add(Calendar.HOUR_OF_DAY, value * -1)
|
|
||||||
}.timeInMillis
|
|
||||||
"days" in date -> Calendar.getInstance().apply {
|
|
||||||
add(Calendar.DATE, value * -1)
|
|
||||||
}.timeInMillis
|
|
||||||
"weeks" in date -> Calendar.getInstance().apply {
|
|
||||||
add(Calendar.DATE, value * 7 * -1)
|
|
||||||
}.timeInMillis
|
|
||||||
"months" in date -> Calendar.getInstance().apply {
|
|
||||||
add(Calendar.MONTH, value * -1)
|
|
||||||
}.timeInMillis
|
|
||||||
"years" in date -> Calendar.getInstance().apply {
|
|
||||||
add(Calendar.YEAR, value * -1)
|
|
||||||
}.timeInMillis
|
|
||||||
"min" in date -> Calendar.getInstance().apply {
|
|
||||||
add(Calendar.MINUTE, value * -1)
|
|
||||||
}.timeInMillis
|
|
||||||
"hour" in date -> Calendar.getInstance().apply {
|
|
||||||
add(Calendar.HOUR_OF_DAY, value * -1)
|
|
||||||
}.timeInMillis
|
|
||||||
"day" in date -> Calendar.getInstance().apply {
|
|
||||||
add(Calendar.DATE, value * -1)
|
|
||||||
}.timeInMillis
|
|
||||||
"week" in date -> Calendar.getInstance().apply {
|
|
||||||
add(Calendar.DATE, value * 7 * -1)
|
|
||||||
}.timeInMillis
|
|
||||||
"month" in date -> Calendar.getInstance().apply {
|
|
||||||
add(Calendar.MONTH, value * -1)
|
|
||||||
}.timeInMillis
|
|
||||||
"year" in date -> Calendar.getInstance().apply {
|
|
||||||
add(Calendar.YEAR, value * -1)
|
|
||||||
}.timeInMillis
|
|
||||||
else -> {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getFilterList() = FilterList(
|
override fun getFilterList() = FilterList(
|
||||||
|
@ -264,27 +206,6 @@ class WestManga : WPMangaStream("West Manga (WP Manga Stream)", "https://westman
|
||||||
else -> SManga.UNKNOWN
|
else -> SManga.UNKNOWN
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun chapterListSelector() = "div.cl ul li"
|
|
||||||
|
|
||||||
override fun chapterFromElement(element: Element): SChapter {
|
|
||||||
val urlElement = element.select(".leftoff > a").first()
|
|
||||||
val chapter = SChapter.create()
|
|
||||||
val timeElement = element.select("span.rightoff").first()
|
|
||||||
chapter.setUrlWithoutDomain(urlElement.attr("href"))
|
|
||||||
chapter.name = urlElement.text()
|
|
||||||
chapter.date_upload = parseChapterDate(timeElement.text())
|
|
||||||
return chapter
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("SimpleDateFormat")
|
|
||||||
private fun parseChapterDate(date: String): Long {
|
|
||||||
val sdf = SimpleDateFormat("MMM dd, yyyy")
|
|
||||||
val parse = sdf.parse(date)
|
|
||||||
val cal = Calendar.getInstance()
|
|
||||||
cal.time = parse
|
|
||||||
return cal.timeInMillis
|
|
||||||
}
|
|
||||||
|
|
||||||
private class SortByFilter : UriPartFilter("Sort By", arrayOf(
|
private class SortByFilter : UriPartFilter("Sort By", arrayOf(
|
||||||
Pair("Default", ""),
|
Pair("Default", ""),
|
||||||
Pair("A-Z", "A-Z"),
|
Pair("A-Z", "A-Z"),
|
||||||
|
@ -454,61 +375,6 @@ class KomikGo : WPMangaStream("Komik GO (WP Manga Stream)", "https://komikgo.com
|
||||||
|
|
||||||
override fun chapterListSelector() = "li.wp-manga-chapter"
|
override fun chapterListSelector() = "li.wp-manga-chapter"
|
||||||
|
|
||||||
|
|
||||||
private fun parseChapterDate(date: String): Long {
|
|
||||||
if (date.contains(",")) {
|
|
||||||
return try {
|
|
||||||
SimpleDateFormat("MMM d, yyyy", Locale.US).parse(date).time
|
|
||||||
} catch (e: ParseException) {
|
|
||||||
0
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
val value = date.split(' ')[0].toInt()
|
|
||||||
|
|
||||||
return when {
|
|
||||||
"mins" in date -> Calendar.getInstance().apply {
|
|
||||||
add(Calendar.MINUTE, value * -1)
|
|
||||||
}.timeInMillis
|
|
||||||
"hours" in date -> Calendar.getInstance().apply {
|
|
||||||
add(Calendar.HOUR_OF_DAY, value * -1)
|
|
||||||
}.timeInMillis
|
|
||||||
"days" in date -> Calendar.getInstance().apply {
|
|
||||||
add(Calendar.DATE, value * -1)
|
|
||||||
}.timeInMillis
|
|
||||||
"weeks" in date -> Calendar.getInstance().apply {
|
|
||||||
add(Calendar.DATE, value * 7 * -1)
|
|
||||||
}.timeInMillis
|
|
||||||
"months" in date -> Calendar.getInstance().apply {
|
|
||||||
add(Calendar.MONTH, value * -1)
|
|
||||||
}.timeInMillis
|
|
||||||
"years" in date -> Calendar.getInstance().apply {
|
|
||||||
add(Calendar.YEAR, value * -1)
|
|
||||||
}.timeInMillis
|
|
||||||
"min" in date -> Calendar.getInstance().apply {
|
|
||||||
add(Calendar.MINUTE, value * -1)
|
|
||||||
}.timeInMillis
|
|
||||||
"hour" in date -> Calendar.getInstance().apply {
|
|
||||||
add(Calendar.HOUR_OF_DAY, value * -1)
|
|
||||||
}.timeInMillis
|
|
||||||
"day" in date -> Calendar.getInstance().apply {
|
|
||||||
add(Calendar.DATE, value * -1)
|
|
||||||
}.timeInMillis
|
|
||||||
"week" in date -> Calendar.getInstance().apply {
|
|
||||||
add(Calendar.DATE, value * 7 * -1)
|
|
||||||
}.timeInMillis
|
|
||||||
"month" in date -> Calendar.getInstance().apply {
|
|
||||||
add(Calendar.MONTH, value * -1)
|
|
||||||
}.timeInMillis
|
|
||||||
"year" in date -> Calendar.getInstance().apply {
|
|
||||||
add(Calendar.YEAR, value * -1)
|
|
||||||
}.timeInMillis
|
|
||||||
else -> {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun chapterFromElement(element: Element): SChapter {
|
override fun chapterFromElement(element: Element): SChapter {
|
||||||
val urlElement = element.select("a").first()
|
val urlElement = element.select("a").first()
|
||||||
val chapter = SChapter.create()
|
val chapter = SChapter.create()
|
||||||
|
@ -519,16 +385,9 @@ class KomikGo : WPMangaStream("Komik GO (WP Manga Stream)", "https://komikgo.com
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun pageListParse(document: Document): List<Page> {
|
override fun pageListParse(document: Document): List<Page> {
|
||||||
val pages = mutableListOf<Page>()
|
return document.select("div.reading-content * img").mapIndexed { i, img ->
|
||||||
var i = 0
|
Page(i, "", img.let { if (it.hasAttr("data-src")) it.attr("abs:data-src") else it.attr("abs:src") })
|
||||||
document.select("div.reading-content * img").forEach { element ->
|
|
||||||
val url = element.attr("src")
|
|
||||||
i++
|
|
||||||
if (url.isNotEmpty()) {
|
|
||||||
pages.add(Page(i, "", url))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return pages
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TextField(name: String, val key: String) : Filter.Text(name)
|
private class TextField(name: String, val key: String) : Filter.Text(name)
|
||||||
|
@ -704,27 +563,6 @@ class KomikIndo : WPMangaStream("Komik Indo (WP Manga Stream)", "https://www.kom
|
||||||
return manga
|
return manga
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun chapterListSelector() = "div.cl ul li"
|
|
||||||
|
|
||||||
override fun chapterFromElement(element: Element): SChapter {
|
|
||||||
val urlElement = element.select(".leftoff > a").first()
|
|
||||||
val chapter = SChapter.create()
|
|
||||||
val timeElement = element.select("span.rightoff").first()
|
|
||||||
chapter.setUrlWithoutDomain(urlElement.attr("href"))
|
|
||||||
chapter.name = urlElement.text()
|
|
||||||
chapter.date_upload = parseChapterDate(timeElement.text())
|
|
||||||
return chapter
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("SimpleDateFormat")
|
|
||||||
private fun parseChapterDate(date: String): Long {
|
|
||||||
val sdf = SimpleDateFormat("MMM dd, yyyy")
|
|
||||||
val parse = sdf.parse(date)
|
|
||||||
val cal = Calendar.getInstance()
|
|
||||||
cal.time = parse
|
|
||||||
return cal.timeInMillis
|
|
||||||
}
|
|
||||||
|
|
||||||
private class GenreListFilter : UriPartFilter("Genre", arrayOf(
|
private class GenreListFilter : UriPartFilter("Genre", arrayOf(
|
||||||
Pair("Default", ""),
|
Pair("Default", ""),
|
||||||
Pair("4-Koma", "4-koma"),
|
Pair("4-Koma", "4-koma"),
|
||||||
|
@ -912,32 +750,13 @@ class MaidManga : WPMangaStream("Maid Manga (WP Manga Stream)", "https://www.mai
|
||||||
|
|
||||||
override fun chapterListParse(response: Response): List<SChapter> {
|
override fun chapterListParse(response: Response): List<SChapter> {
|
||||||
val document = response.asJsoup()
|
val document = response.asJsoup()
|
||||||
val chapters = mutableListOf<SChapter>()
|
val chapters = document.select(chapterListSelector()).map { chapterFromElement(it) }
|
||||||
document.select(chapterListSelector()).map { chapters.add(chapterFromElement(it)) }
|
|
||||||
// Add date for latest chapter only
|
// Add date for latest chapter only
|
||||||
document.select("script.yoast-schema-graph").html()
|
document.select("ul.anf span:has(b:contains(release date))").text().substringAfter(": ")
|
||||||
.let {
|
.let { chapters[0].date_upload = parseChapterDate(it) }
|
||||||
val date = JSONObject(it).getJSONArray("@graph").getJSONObject(3).getString("dateModified")
|
|
||||||
chapters[0].date_upload = parseDate(date)
|
|
||||||
}
|
|
||||||
return chapters
|
return chapters
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("SimpleDateFormat")
|
|
||||||
private fun parseDate(date: String): Long {
|
|
||||||
return SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX").parse(date).time
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun chapterListSelector() = "ul#chapter_list li a:contains(chapter)"
|
|
||||||
|
|
||||||
override fun chapterFromElement(element: Element): SChapter {
|
|
||||||
val urlElement = element.select("a:contains(chapter)")
|
|
||||||
val chapter = SChapter.create()
|
|
||||||
chapter.url = urlElement.attr("href")
|
|
||||||
chapter.name = urlElement.text()
|
|
||||||
return chapter
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun pageListRequest(chapter: SChapter): Request {
|
override fun pageListRequest(chapter: SChapter): Request {
|
||||||
if (chapter.url.startsWith("http")) {
|
if (chapter.url.startsWith("http")) {
|
||||||
return GET(chapter.url, headers)
|
return GET(chapter.url, headers)
|
||||||
|
@ -1047,6 +866,6 @@ class MangaRaw : WPMangaStream("Manga Raw", "https://mangaraw.org", "ja") {
|
||||||
.let { lastNum -> IntRange(1, lastNum) }
|
.let { lastNum -> IntRange(1, lastNum) }
|
||||||
.map { num -> Page(num, "$chapterUrl/$num") }
|
.map { num -> Page(num, "$chapterUrl/$num") }
|
||||||
}
|
}
|
||||||
override fun imageUrlParse(document: Document) = document.select("a.img-block img").attr("abs:src")
|
override fun imageUrlParse(document: Document): String = document.select("a.img-block img").attr("abs:src")
|
||||||
override fun getFilterList(): FilterList = FilterList()
|
override fun getFilterList(): FilterList = FilterList()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue