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:
Claudemirovsky
2023-02-22 15:33:43 -03:00
committed by GitHub
parent eea45e94f7
commit 6db103a490
5 changed files with 33 additions and 26 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = 'Animes House'
pkgNameSuffix = 'pt.animeshouse'
extClass = '.AnimesHouse'
extVersionCode = 3
extVersionCode = 4
libVersion = '13'
}

View File

@ -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")
}

View File

@ -20,7 +20,7 @@ class AHUrlActivity : Activity() {
val pathSegments = intent?.data?.pathSegments
if (pathSegments != null && pathSegments.size > 1) {
val slug = pathSegments[1]
val searchQuery = AHConstants.PREFIX_SEARCH + slug
val searchQuery = AnimesHouse.PREFIX_SEARCH + slug
val mainIntent = Intent().apply {
action = "eu.kanade.tachiyomi.ANIMESEARCH"
putExtra("query", searchQuery)

View File

@ -48,8 +48,8 @@ class AnimesHouse : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
override fun headersBuilder(): Headers.Builder = Headers.Builder()
.add("Referer", baseUrl)
.add("Accept-Language", AHConstants.ACCEPT_LANGUAGE)
.add("User-Agent", AHConstants.USER_AGENT)
.add("Accept-Language", ACCEPT_LANGUAGE)
.add("User-Agent", USER_AGENT)
private val preferences: SharedPreferences by lazy {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
@ -129,7 +129,7 @@ class AnimesHouse : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
private fun getPlayerVideos(url: String): List<Video> {
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)
@ -180,8 +180,8 @@ class AnimesHouse : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
}
override fun fetchSearchAnime(page: Int, query: String, filters: AnimeFilterList): Observable<AnimesPage> {
return if (query.startsWith(AHConstants.PREFIX_SEARCH)) {
val slug = query.removePrefix(AHConstants.PREFIX_SEARCH)
return if (query.startsWith(PREFIX_SEARCH)) {
val slug = query.removePrefix(PREFIX_SEARCH)
client.newCall(GET("$baseUrl/anime/$slug", headers))
.asObservableSuccess()
.map { response ->
@ -252,14 +252,15 @@ class AnimesHouse : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
override fun latestUpdatesFromElement(element: Element) = popularAnimeFromElement(element)
override fun latestUpdatesRequest(page: Int): Request = GET("$baseUrl/episodio/page/$page", headers)
// ============================== Settings ==============================
override fun setupPreferenceScreen(screen: PreferenceScreen) {
val videoQualityPref = ListPreference(screen.context).apply {
key = AHConstants.PREFERRED_QUALITY
title = "Qualidade preferida"
entries = AHConstants.QUALITY_LIST
entryValues = AHConstants.QUALITY_LIST
setDefaultValue(AHConstants.DEFAULT_QUALITY)
key = PREF_QUALITY_KEY
title = PREF_QUALITY_TITLE
entries = PREF_QUALITY_ENTRIES
entryValues = PREF_QUALITY_VALUES
setDefaultValue(PREF_QUALITY_DEFAULT)
summary = "%s"
setOnPreferenceChangeListener { _, newValue ->
val selected = newValue as String
@ -295,9 +296,26 @@ class AnimesHouse : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
}
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(
compareBy { it.quality.contains(quality) }
).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")
}
}

View File

@ -1,6 +1,6 @@
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.network.GET
import okhttp3.Headers
@ -19,7 +19,7 @@ class McpExtractor(
val epId = REGEX_EP_ID.find(js)!!.groupValues[1]
val req = client.newCall(GET("$API_URL/s_control.php?mid=$epId", headers))
.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
.get(1)
.replace("\\", "")