This commit is contained in:
cats 2025-05-12 17:46:53 +05:30 committed by GitHub
commit 6837f7cfd8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 68 additions and 8 deletions

View file

@ -1,7 +1,7 @@
ext { ext {
extName = 'Torrentio Anime (Torrent / Debrid)' extName = 'Torrentio Anime (Torrent / Debrid)'
extClass = '.Torrentio' extClass = '.Torrentio'
extVersionCode = 16 extVersionCode = 17
containsNsfw = false containsNsfw = false
} }

View file

@ -459,14 +459,46 @@ class Torrentio : ConfigurableAnimeSource, AnimeHttpSource() {
override fun List<Video>.sort(): List<Video> { override fun List<Video>.sort(): List<Video> {
val isDub = preferences.getBoolean(IS_DUB_KEY, IS_DUB_DEFAULT) val isDub = preferences.getBoolean(IS_DUB_KEY, IS_DUB_DEFAULT)
val isEfficient = preferences.getBoolean(IS_EFFICIENT_KEY, IS_EFFICIENT_DEFAULT) val isEfficient = preferences.getBoolean(IS_EFFICIENT_KEY, IS_EFFICIENT_DEFAULT)
val codecPreferences = preferences.getStringSet(PREF_CODEC_KEY, PREF_CODEC_DEFAULT) ?: setOf()
return sortedWith( return if (codecPreferences.isNotEmpty()) {
// Filter to only show videos matching selected codecs
filter { video ->
codecPreferences.any { codec ->
when (codec) {
"x264" -> video.quality.contains("264", true) ||
(!video.quality.contains("265", true) &&
!video.quality.contains("hevc", true) &&
!video.quality.contains("av1", true) &&
!video.quality.contains("vp9", true))
"x265" -> video.quality.contains("265", true) ||
video.quality.contains("hevc", true)
"av1" -> video.quality.contains("av1", true)
"vp9" -> video.quality.contains("vp9", true)
"other" -> !video.quality.contains("264", true) &&
!video.quality.contains("265", true) &&
!video.quality.contains("hevc", true) &&
!video.quality.contains("av1", true) &&
!video.quality.contains("vp9", true)
else -> false
}
}
}.sortedWith(
compareBy(
{ Regex("\\[(.+?) download]").containsMatchIn(it.quality) },
{ isDub && !it.quality.contains("dubbed", true) }
)
)
} else {
// If no codec preferences, use old sorting logic
sortedWith(
compareBy( compareBy(
{ Regex("\\[(.+?) download]").containsMatchIn(it.quality) }, { Regex("\\[(.+?) download]").containsMatchIn(it.quality) },
{ isDub && !it.quality.contains("dubbed", true) }, { isDub && !it.quality.contains("dubbed", true) },
{ isEfficient && !arrayOf("hevc", "265", "av1").any { q -> it.quality.contains(q, true) } }, { isEfficient && !arrayOf("hevc", "265", "av1").any { q -> it.quality.contains(q, true) } },
),
) )
)
}
} }
private fun fetchTrackers(): String { private fun fetchTrackers(): String {
@ -615,6 +647,18 @@ class Torrentio : ConfigurableAnimeSource, AnimeHttpSource() {
preferences.edit().putBoolean(key, newValue as Boolean).commit() preferences.edit().putBoolean(key, newValue as Boolean).commit()
} }
summary = "Codec: (HEVC / x265) & AV1. High-quality video with less data usage." summary = "Codec: (HEVC / x265) & AV1. High-quality video with less data usage."
}.also(screen::addPreference)
MultiSelectListPreference(screen.context).apply {
key = PREF_CODEC_KEY
title = "Preferred Codecs"
entries = PREF_CODEC
entryValues = PREF_CODEC_VALUE
setDefaultValue(PREF_CODEC_DEFAULT)
setOnPreferenceChangeListener { _, newValue ->
@Suppress("UNCHECKED_CAST")
preferences.edit().putStringSet(key, newValue as Set<String>).commit()
}
}.also(screen::addPreference) }.also(screen::addPreference)
} }
@ -897,7 +941,22 @@ class Torrentio : ConfigurableAnimeSource, AnimeHttpSource() {
private const val IS_EFFICIENT_KEY = "efficient" private const val IS_EFFICIENT_KEY = "efficient"
private const val IS_EFFICIENT_DEFAULT = false private const val IS_EFFICIENT_DEFAULT = false
private const val PREF_CODEC_KEY = "codec_selection"
private val PREF_CODEC = arrayOf(
"x264",
"x265/HEVC",
"AV1",
"VP9",
"Other"
)
private val PREF_CODEC_VALUE = arrayOf(
"x264",
"x265",
"av1",
"vp9",
"other"
)
private val PREF_CODEC_DEFAULT = setOf<String>() // Empty by default to show al
private val DATE_TIME_FORMATTER by lazy { private val DATE_TIME_FORMATTER by lazy {
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.ENGLISH) SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.ENGLISH)
} }
@ -905,5 +964,6 @@ class Torrentio : ConfigurableAnimeSource, AnimeHttpSource() {
private val DATE_FORMATTER by lazy { private val DATE_FORMATTER by lazy {
SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH) SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH)
} }
} }
} }