AnimesHouse: Make quality preferences more readable (#1318)
* feat: Make quality prefs more readable * refactor: Move constants to companion object * chore: Bump version
This commit is contained in:
@ -5,7 +5,7 @@ ext {
|
|||||||
extName = 'Animes House'
|
extName = 'Animes House'
|
||||||
pkgNameSuffix = 'pt.animeshouse'
|
pkgNameSuffix = 'pt.animeshouse'
|
||||||
extClass = '.AnimesHouse'
|
extClass = '.AnimesHouse'
|
||||||
extVersionCode = 3
|
extVersionCode = 4
|
||||||
libVersion = '13'
|
libVersion = '13'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
package eu.kanade.tachiyomi.animeextension.pt.animeshouse
|
|
||||||
|
|
||||||
object AHConstants {
|
|
||||||
const val ACCEPT_LANGUAGE = "pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7"
|
|
||||||
const val USER_AGENT = "Mozilla/5.0 (Linux; Android 10; SM-A307GT Build/QP1A.190711.020;) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/103.0.5060.71 Mobile Safari/537.36"
|
|
||||||
const val MSG_ERR_BODY = "Erro ao obter dados do episódio."
|
|
||||||
const val PREFERRED_QUALITY = "preferred_quality"
|
|
||||||
const val DEFAULT_QUALITY = "720p"
|
|
||||||
const val PREFIX_SEARCH = "slug:"
|
|
||||||
val QUALITY_LIST = arrayOf("240p", "360p", "480p", "720p", "1080p")
|
|
||||||
}
|
|
@ -20,7 +20,7 @@ class AHUrlActivity : Activity() {
|
|||||||
val pathSegments = intent?.data?.pathSegments
|
val pathSegments = intent?.data?.pathSegments
|
||||||
if (pathSegments != null && pathSegments.size > 1) {
|
if (pathSegments != null && pathSegments.size > 1) {
|
||||||
val slug = pathSegments[1]
|
val slug = pathSegments[1]
|
||||||
val searchQuery = AHConstants.PREFIX_SEARCH + slug
|
val searchQuery = AnimesHouse.PREFIX_SEARCH + slug
|
||||||
val mainIntent = Intent().apply {
|
val mainIntent = Intent().apply {
|
||||||
action = "eu.kanade.tachiyomi.ANIMESEARCH"
|
action = "eu.kanade.tachiyomi.ANIMESEARCH"
|
||||||
putExtra("query", searchQuery)
|
putExtra("query", searchQuery)
|
||||||
|
@ -48,8 +48,8 @@ class AnimesHouse : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
|||||||
|
|
||||||
override fun headersBuilder(): Headers.Builder = Headers.Builder()
|
override fun headersBuilder(): Headers.Builder = Headers.Builder()
|
||||||
.add("Referer", baseUrl)
|
.add("Referer", baseUrl)
|
||||||
.add("Accept-Language", AHConstants.ACCEPT_LANGUAGE)
|
.add("Accept-Language", ACCEPT_LANGUAGE)
|
||||||
.add("User-Agent", AHConstants.USER_AGENT)
|
.add("User-Agent", USER_AGENT)
|
||||||
|
|
||||||
private val preferences: SharedPreferences by lazy {
|
private val preferences: SharedPreferences by lazy {
|
||||||
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
||||||
@ -129,7 +129,7 @@ class AnimesHouse : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
|||||||
|
|
||||||
private fun getPlayerVideos(url: String): List<Video> {
|
private fun getPlayerVideos(url: String): List<Video> {
|
||||||
val iframeBody = client.newCall(GET(url, headers)).execute()
|
val iframeBody = client.newCall(GET(url, headers)).execute()
|
||||||
.body?.string() ?: throw Exception(AHConstants.MSG_ERR_BODY)
|
.body?.string() ?: throw Exception(MSG_ERR_BODY)
|
||||||
|
|
||||||
val unpackedBody = JsUnpacker.unpack(iframeBody)
|
val unpackedBody = JsUnpacker.unpack(iframeBody)
|
||||||
|
|
||||||
@ -180,8 +180,8 @@ class AnimesHouse : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun fetchSearchAnime(page: Int, query: String, filters: AnimeFilterList): Observable<AnimesPage> {
|
override fun fetchSearchAnime(page: Int, query: String, filters: AnimeFilterList): Observable<AnimesPage> {
|
||||||
return if (query.startsWith(AHConstants.PREFIX_SEARCH)) {
|
return if (query.startsWith(PREFIX_SEARCH)) {
|
||||||
val slug = query.removePrefix(AHConstants.PREFIX_SEARCH)
|
val slug = query.removePrefix(PREFIX_SEARCH)
|
||||||
client.newCall(GET("$baseUrl/anime/$slug", headers))
|
client.newCall(GET("$baseUrl/anime/$slug", headers))
|
||||||
.asObservableSuccess()
|
.asObservableSuccess()
|
||||||
.map { response ->
|
.map { response ->
|
||||||
@ -252,14 +252,15 @@ class AnimesHouse : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
|||||||
override fun latestUpdatesFromElement(element: Element) = popularAnimeFromElement(element)
|
override fun latestUpdatesFromElement(element: Element) = popularAnimeFromElement(element)
|
||||||
|
|
||||||
override fun latestUpdatesRequest(page: Int): Request = GET("$baseUrl/episodio/page/$page", headers)
|
override fun latestUpdatesRequest(page: Int): Request = GET("$baseUrl/episodio/page/$page", headers)
|
||||||
|
|
||||||
// ============================== Settings ==============================
|
// ============================== Settings ==============================
|
||||||
override fun setupPreferenceScreen(screen: PreferenceScreen) {
|
override fun setupPreferenceScreen(screen: PreferenceScreen) {
|
||||||
val videoQualityPref = ListPreference(screen.context).apply {
|
val videoQualityPref = ListPreference(screen.context).apply {
|
||||||
key = AHConstants.PREFERRED_QUALITY
|
key = PREF_QUALITY_KEY
|
||||||
title = "Qualidade preferida"
|
title = PREF_QUALITY_TITLE
|
||||||
entries = AHConstants.QUALITY_LIST
|
entries = PREF_QUALITY_ENTRIES
|
||||||
entryValues = AHConstants.QUALITY_LIST
|
entryValues = PREF_QUALITY_VALUES
|
||||||
setDefaultValue(AHConstants.DEFAULT_QUALITY)
|
setDefaultValue(PREF_QUALITY_DEFAULT)
|
||||||
summary = "%s"
|
summary = "%s"
|
||||||
setOnPreferenceChangeListener { _, newValue ->
|
setOnPreferenceChangeListener { _, newValue ->
|
||||||
val selected = newValue as String
|
val selected = newValue as String
|
||||||
@ -295,9 +296,26 @@ class AnimesHouse : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun List<Video>.sort(): List<Video> {
|
override fun List<Video>.sort(): List<Video> {
|
||||||
val quality = preferences.getString(AHConstants.PREFERRED_QUALITY, AHConstants.DEFAULT_QUALITY)!!
|
val quality = preferences.getString(PREF_QUALITY_KEY, PREF_QUALITY_DEFAULT)!!
|
||||||
return sortedWith(
|
return sortedWith(
|
||||||
compareBy { it.quality.contains(quality) }
|
compareBy { it.quality.contains(quality) }
|
||||||
).reversed()
|
).reversed()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val PREFIX_SEARCH = "slug:"
|
||||||
|
const val MSG_ERR_BODY = "Erro ao obter dados do episódio."
|
||||||
|
|
||||||
|
private const val ACCEPT_LANGUAGE = "pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7"
|
||||||
|
private const val USER_AGENT = "Mozilla/5.0 (Linux; Android 10; SM-A307GT Build/QP1A.190711.020;) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/103.0.5060.71 Mobile Safari/537.36"
|
||||||
|
|
||||||
|
private const val PREF_QUALITY_DEFAULT = "720p"
|
||||||
|
private const val PREF_QUALITY_KEY = "preferred_quality"
|
||||||
|
private const val PREF_QUALITY_TITLE = "Qualidade preferida"
|
||||||
|
private val PREF_QUALITY_ENTRIES = arrayOf(
|
||||||
|
"SD - 240p", "SD - 360p", "SD - 480p",
|
||||||
|
"HD - 720p", "FULLHD - 1080p"
|
||||||
|
)
|
||||||
|
private val PREF_QUALITY_VALUES = arrayOf("240p", "360p", "480p", "720p", "1080p")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package eu.kanade.tachiyomi.animeextension.pt.animeshouse.extractors
|
package eu.kanade.tachiyomi.animeextension.pt.animeshouse.extractors
|
||||||
|
|
||||||
import eu.kanade.tachiyomi.animeextension.pt.animeshouse.AHConstants
|
import eu.kanade.tachiyomi.animeextension.pt.animeshouse.AnimesHouse
|
||||||
import eu.kanade.tachiyomi.animesource.model.Video
|
import eu.kanade.tachiyomi.animesource.model.Video
|
||||||
import eu.kanade.tachiyomi.network.GET
|
import eu.kanade.tachiyomi.network.GET
|
||||||
import okhttp3.Headers
|
import okhttp3.Headers
|
||||||
@ -19,7 +19,7 @@ class McpExtractor(
|
|||||||
val epId = REGEX_EP_ID.find(js)!!.groupValues[1]
|
val epId = REGEX_EP_ID.find(js)!!.groupValues[1]
|
||||||
val req = client.newCall(GET("$API_URL/s_control.php?mid=$epId", headers))
|
val req = client.newCall(GET("$API_URL/s_control.php?mid=$epId", headers))
|
||||||
.execute()
|
.execute()
|
||||||
val reqBody = req.body?.string() ?: throw Exception(AHConstants.MSG_ERR_BODY)
|
val reqBody = req.body?.string() ?: throw Exception(AnimesHouse.MSG_ERR_BODY)
|
||||||
val videoUrl = REGEX_VIDEO_URL.find(reqBody)!!.groupValues
|
val videoUrl = REGEX_VIDEO_URL.find(reqBody)!!.groupValues
|
||||||
.get(1)
|
.get(1)
|
||||||
.replace("\\", "")
|
.replace("\\", "")
|
||||||
|
Reference in New Issue
Block a user