Add Header Referer (#2424)

- Fixes thumbnail hotlink protection
This commit is contained in:
happywillow0 2020-03-15 13:09:31 -04:00 committed by GitHub
parent 61409c94b2
commit 4bb19c8456
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 27 deletions

View File

@ -5,7 +5,7 @@ ext {
appName = 'Tachiyomi: Mangahasu'
pkgNameSuffix = 'en.mangahasu'
extClass = '.Mangahasu'
extVersionCode = 6
extVersionCode = 7
libVersion = '1.2'
}

View File

@ -1,7 +1,10 @@
package eu.kanade.tachiyomi.extension.en.mangahasu
import android.util.Base64
import com.github.salomonbrys.kotson.*
import com.github.salomonbrys.kotson.array
import com.github.salomonbrys.kotson.get
import com.github.salomonbrys.kotson.int
import com.github.salomonbrys.kotson.string
import com.google.gson.JsonParser
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.source.model.FilterList
@ -15,7 +18,7 @@ import okhttp3.Request
import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import java.text.SimpleDateFormat
import java.util.*
import java.util.Locale
class Mangahasu : ParsedHttpSource() {
@ -29,6 +32,10 @@ class Mangahasu: ParsedHttpSource() {
override val client: OkHttpClient = network.cloudflareClient
override fun headersBuilder(): Headers.Builder {
return super.headersBuilder().add("Referer", baseUrl)
}
override fun popularMangaRequest(page: Int): Request =
GET("$baseUrl/directory.html?page=$page", headers)
@ -57,7 +64,10 @@ class Mangahasu: ParsedHttpSource() {
override fun latestUpdatesNextPageSelector() = popularMangaNextPageSelector()
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
return GET("$baseUrl/advanced-search.html?keyword=$query&author=&artist=&status=&typeid=&page=$page", headers)
return GET(
"$baseUrl/advanced-search.html?keyword=$query&author=&artist=&status=&typeid=&page=$page",
headers
)
}
override fun searchMangaSelector() =
@ -98,7 +108,7 @@ class Mangahasu: ParsedHttpSource() {
chapter.name = urlElement.text()
chapter.date_upload = element.select(".date-updated").last()?.text()?.let {
SimpleDateFormat("MMM dd, yyyy", Locale.US).parse(it).time
SimpleDateFormat("MMM dd, yyyy", Locale.US).parse(it)?.time ?: 0
} ?: 0
return chapter
}
@ -129,7 +139,9 @@ class Mangahasu: ParsedHttpSource() {
//Some images are not yet loaded onto Mangahasu's image server.
//Decode temporary URLs and replace placeholder images.
val lstDUrls = document.select("script:containsData(lstDUrls)").html().substringAfter("lstDUrls").substringAfter("\"").substringBefore("\"")
val lstDUrls =
document.select("script:containsData(lstDUrls)").html().substringAfter("lstDUrls")
.substringAfter("\"").substringBefore("\"")
if (lstDUrls != "W10=") { //Base64 = [] or empty file
val decoded = String(Base64.decode(lstDUrls, Base64.DEFAULT))
val json = JsonParser().parse(decoded).array
@ -144,12 +156,4 @@ class Mangahasu: ParsedHttpSource() {
}
override fun imageUrlParse(document: Document) = ""
override fun imageRequest(page: Page): Request {
val imgHeader = headers.newBuilder().apply {
add("Referer", baseUrl)
}.build()
return GET(page.imageUrl!!, imgHeader)
}
}