Skip to content

Commit

Permalink
fix(all/lmanime): Fix video extractor (#2397)
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudemirovsky authored Oct 19, 2023
1 parent 05e141c commit 45596e2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
38 changes: 25 additions & 13 deletions multisrc/overrides/animestream/lmanime/src/LMAnime.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import eu.kanade.tachiyomi.animesource.model.Video
import eu.kanade.tachiyomi.lib.dailymotionextractor.DailymotionExtractor
import eu.kanade.tachiyomi.lib.okruextractor.OkruExtractor
import eu.kanade.tachiyomi.multisrc.animestream.AnimeStream
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.util.asJsoup
import okhttp3.Response

Expand All @@ -20,7 +21,7 @@ class LMAnime : AnimeStream(
override val prefQualityEntries = prefQualityValues

override fun videoListParse(response: Response): List<Video> {
val items = response.asJsoup().select(videoListSelector())
val items = response.use { it.asJsoup() }.select(videoListSelector())
val allowed = preferences.getStringSet(PREF_ALLOWED_LANGS_KEY, PREF_ALLOWED_LANGS_DEFAULT)!!
return items
.filter { element ->
Expand All @@ -30,16 +31,29 @@ class LMAnime : AnimeStream(
val language = it.text().substringBefore(" ")
val url = getHosterUrl(it)
getVideoList(url, language)
}.flatten()
}.flatten().ifEmpty { throw Exception("Empty video list!") }
}

override fun getHosterUrl(encodedData: String) =
client.newCall(GET(encodedData, headers)).execute()
.use { it.asJsoup() }
.selectFirst("iframe[src~=.]")!!
.attr("src")
.let { // sometimes the url dont specify its protocol
when {
it.startsWith("http") -> it
else -> "https:$it"
}
}

private val okruExtractor by lazy { OkruExtractor(client) }
private val dailyExtractor by lazy { DailymotionExtractor(client, headers) }

override fun getVideoList(url: String, name: String): List<Video> {
val prefix = "$name -"
return when {
"ok.ru" in url ->
OkruExtractor(client).videosFromUrl(url, prefix)
"dailymotion.com" in url ->
DailymotionExtractor(client, headers).videosFromUrl(url, "Dailymotion ($name)")
"ok.ru" in url -> okruExtractor.videosFromUrl(url, prefix)
"dailymotion.com" in url -> dailyExtractor.videosFromUrl(url, "Dailymotion ($name)")
else -> emptyList()
}
}
Expand All @@ -48,7 +62,8 @@ class LMAnime : AnimeStream(
@Suppress("UNCHECKED_CAST")
override fun setupPreferenceScreen(screen: PreferenceScreen) {
super.setupPreferenceScreen(screen) // Quality preferences
val langPref = ListPreference(screen.context).apply {

ListPreference(screen.context).apply {
key = PREF_LANG_KEY
title = PREF_LANG_TITLE
entries = PREF_LANG_ENTRIES
Expand All @@ -61,9 +76,9 @@ class LMAnime : AnimeStream(
val entry = entryValues[index] as String
preferences.edit().putString(key, entry).commit()
}
}
}.also(screen::addPreference)

val allowedPref = MultiSelectListPreference(screen.context).apply {
MultiSelectListPreference(screen.context).apply {
key = PREF_ALLOWED_LANGS_KEY
title = PREF_ALLOWED_LANGS_TITLE
entries = PREF_ALLOWED_LANGS_ENTRIES
Expand All @@ -73,10 +88,7 @@ class LMAnime : AnimeStream(
setOnPreferenceChangeListener { _, newValue ->
preferences.edit().putStringSet(key, newValue as Set<String>).commit()
}
}

screen.addPreference(langPref)
screen.addPreference(allowedPref)
}.also(screen::addPreference)
}

// ============================= Utilities ==============================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AnimeStreamGenerator : ThemeSourceGenerator {
SingleLang("desu-online", "https://desu-online.pl", "pl", className = "DesuOnline", isNsfw = false, overrideVersionCode = 3),
SingleLang("DonghuaStream", "https://donghuastream.co.in", "en", isNsfw = false, overrideVersionCode = 2),
SingleLang("Hstream", "https://hstream.moe", "en", isNsfw = true, overrideVersionCode = 3),
SingleLang("LMAnime", "https://lmanime.com", "all", isNsfw = false, overrideVersionCode = 3),
SingleLang("LMAnime", "https://lmanime.com", "all", isNsfw = false, overrideVersionCode = 4),
SingleLang("LuciferDonghua", "https://luciferdonghua.in", "en", isNsfw = false, overrideVersionCode = 2),
SingleLang("MiniOppai", "https://minioppai.org", "id", isNsfw = true, overrideVersionCode = 2),
SingleLang("RineCloud", "https://rine.cloud", "pt-BR", isNsfw = false, overrideVersionCode = 3),
Expand Down

0 comments on commit 45596e2

Please sign in to comment.