Mangastream: fix some chapter URLs being decoded when stored (closes #1148)

This commit is contained in:
Eugene 2019-09-07 17:39:24 -04:00
parent 31175e3b6d
commit e2d2a8afc2
No known key found for this signature in database
GPG Key ID: E1FD745328866B0A
2 changed files with 28 additions and 19 deletions

View File

@ -5,7 +5,7 @@ ext {
appName = 'Tachiyomi: Mangastream' appName = 'Tachiyomi: Mangastream'
pkgNameSuffix = 'en.mangastream' pkgNameSuffix = 'en.mangastream'
extClass = '.Mangastream' extClass = '.Mangastream'
extVersionCode = 3 extVersionCode = 4
libVersion = '1.2' libVersion = '1.2'
} }

View File

@ -2,7 +2,11 @@ package eu.kanade.tachiyomi.extension.en.mangastream
import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.asObservableSuccess import eu.kanade.tachiyomi.network.asObservableSuccess
import eu.kanade.tachiyomi.source.model.* import eu.kanade.tachiyomi.source.model.FilterList
import eu.kanade.tachiyomi.source.model.MangasPage
import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.source.online.ParsedHttpSource import eu.kanade.tachiyomi.source.online.ParsedHttpSource
import eu.kanade.tachiyomi.util.asJsoup import eu.kanade.tachiyomi.util.asJsoup
import okhttp3.Response import okhttp3.Response
@ -11,20 +15,24 @@ import org.jsoup.nodes.Element
import rx.Observable import rx.Observable
import java.text.ParseException import java.text.ParseException
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.* import java.util.Calendar
import java.util.Date
import java.util.Locale
import java.util.regex.Pattern import java.util.regex.Pattern
class Mangastream : ParsedHttpSource() { class Mangastream : ParsedHttpSource() {
override val name = "Mangastream" override val name = "Mangastream"
override val baseUrl = "https://mangastream.com" override val baseUrl = "https://readms.net/"
override val lang = "en" override val lang = "en"
override val supportsLatest = true override val supportsLatest = true
private val datePattern = Pattern.compile("(\\d+) days? ago") private val datePattern by lazy {
Pattern.compile("(\\d+) days? ago")
}
override fun popularMangaSelector() = "table.table-striped > tbody > tr > td:nth-of-type(1)" override fun popularMangaSelector() = "table.table-striped > tbody > tr > td:nth-of-type(1)"
@ -83,10 +91,10 @@ class Mangastream : ParsedHttpSource() {
override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable<MangasPage> { override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable<MangasPage> {
return client.newCall(searchMangaRequest(page, query, filters)) return client.newCall(searchMangaRequest(page, query, filters))
.asObservableSuccess() .asObservableSuccess()
.map { response -> .map { response ->
searchMangaParse(response, query) searchMangaParse(response, query)
} }
} }
override fun mangaDetailsParse(document: Document): SManga { override fun mangaDetailsParse(document: Document): SManga {
@ -114,27 +122,27 @@ class Mangastream : ParsedHttpSource() {
val dateEl = element.select("td:nth-of-type(2)") val dateEl = element.select("td:nth-of-type(2)")
val chapter = SChapter.create() val chapter = SChapter.create()
chapter.setUrlWithoutDomain(urlEl.attr("href")) chapter.url = urlEl.attr("href")
chapter.name = urlEl.text() chapter.name = urlEl.text()
chapter.date_upload = dateEl.text()?.let { dateParse(it) } ?: 0 chapter.date_upload = dateEl.text()?.let { dateParse(it) } ?: 0
return chapter return chapter
} }
private fun dateParse(dateAsString: String): Long { private fun dateParse(dateAsString: String): Long {
var date: Date val date: Date = try {
try { SimpleDateFormat("MMM dd, yyyy", Locale.ENGLISH).parse(dateAsString.replace(Regex("(st|nd|rd|th)"), ""))
date = SimpleDateFormat("MMM dd, yyyy", Locale.ENGLISH).parse(dateAsString.replace(Regex("(st|nd|rd|th)"), ""))
} catch (e: ParseException) { } catch (e: ParseException) {
val m = datePattern.matcher(dateAsString) val m = datePattern.matcher(dateAsString)
if (dateAsString != "Today" && m.matches()) { if (dateAsString != "Today" && m.matches()) {
val amount = m.group(1).toInt() val amount = m.group(1).toInt()
date = Calendar.getInstance().apply { Calendar.getInstance().apply {
add(Calendar.DATE, -amount) add(Calendar.DATE, -amount)
}.time }.time
} else if (dateAsString == "Today"){ } else if (dateAsString == "Today") {
date = Calendar.getInstance().time Calendar.getInstance().time
} else return 0 } else return 0
} }
@ -147,13 +155,14 @@ class Mangastream : ParsedHttpSource() {
val pages = mutableListOf<Page>() val pages = mutableListOf<Page>()
for (i in 1..num) for (i in 1..num)
pages.add(Page(i-1, url + i )) pages.add(Page(i - 1, url + i))
pages.getOrNull(0)?.imageUrl = imageUrlParse(document) pages.getOrNull(0)?.imageUrl = imageUrlParse(document)
return pages return pages
} }
override fun imageUrlParse(document: Document) = "http:" + document.getElementById("manga-page").attr("src") override fun imageUrlParse(document: Document): String {
return "http:" + document.getElementById("manga-page").attr("src")
}
override fun getFilterList() = super.getFilterList()
} }