AnimeFire: Add new extractor and a URL intent handler (#615)
This commit is contained in:
@ -1,2 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest package="eu.kanade.tachiyomi.animeextension"/>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="eu.kanade.tachiyomi.animeextension">
|
||||
|
||||
<application>
|
||||
<activity
|
||||
android:name=".pt.animefire.AFUrlActivity"
|
||||
android:excludeFromRecents="true"
|
||||
android:exported="true"
|
||||
android:theme="@android:style/Theme.NoDisplay">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
|
||||
<data
|
||||
android:host="animefire.net"
|
||||
android:pathPattern="/animes/..*"
|
||||
android:scheme="https" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
||||
|
@ -6,9 +6,13 @@ ext {
|
||||
extName = 'Anime Fire'
|
||||
pkgNameSuffix = 'pt.animefire'
|
||||
extClass = '.AnimeFire'
|
||||
extVersionCode = 1
|
||||
extVersionCode = 2
|
||||
libVersion = '12'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
}
|
||||
|
||||
|
||||
apply from: "$rootDir/common.gradle"
|
||||
|
@ -0,0 +1,9 @@
|
||||
package eu.kanade.tachiyomi.animeextension.pt.animefire
|
||||
|
||||
object AFConstants {
|
||||
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/102.0.5005.125 Mobile Safari/537.36"
|
||||
const val PREFERRED_QUALITY = "preferred_quality"
|
||||
const val PREFIX_SEARCH = "id:"
|
||||
val QUALITY_LIST = arrayOf("360p", "720p")
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package eu.kanade.tachiyomi.animeextension.pt.animefire
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
/**
|
||||
* Springboard that accepts https://animefire.net/animes/<id> intents
|
||||
* and redirects them to the main Aniyomi process.
|
||||
*/
|
||||
class AFUrlActivity : Activity() {
|
||||
|
||||
private val TAG = "AFUrlActivity"
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
val pathSegments = intent?.data?.pathSegments
|
||||
if (pathSegments != null && pathSegments.size > 1) {
|
||||
val id = pathSegments[1]
|
||||
val searchQuery = AFConstants.PREFIX_SEARCH + id
|
||||
val mainIntent = Intent().apply {
|
||||
action = "eu.kanade.tachiyomi.ANIMESEARCH"
|
||||
putExtra("query", searchQuery)
|
||||
putExtra("filter", packageName)
|
||||
}
|
||||
|
||||
try {
|
||||
startActivity(mainIntent)
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
Log.e(TAG, e.toString())
|
||||
}
|
||||
} else {
|
||||
Log.e(TAG, "could not parse uri from intent $intent")
|
||||
}
|
||||
|
||||
finish()
|
||||
exitProcess(0)
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ import android.content.SharedPreferences
|
||||
import androidx.preference.ListPreference
|
||||
import androidx.preference.PreferenceScreen
|
||||
import eu.kanade.tachiyomi.animeextension.pt.animefire.extractors.AnimeFireExtractor
|
||||
import eu.kanade.tachiyomi.animeextension.pt.animefire.extractors.IframeExtractor
|
||||
import eu.kanade.tachiyomi.animesource.ConfigurableAnimeSource
|
||||
import eu.kanade.tachiyomi.animesource.model.AnimeFilterList
|
||||
import eu.kanade.tachiyomi.animesource.model.AnimesPage
|
||||
@ -49,7 +50,7 @@ class AnimeFire : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
|
||||
override fun headersBuilder(): Headers.Builder = Headers.Builder()
|
||||
.add("Referer", baseUrl)
|
||||
.add("Accept-Language", ACCEPT_LANGUAGE)
|
||||
.add("Accept-Language", AFConstants.ACCEPT_LANGUAGE)
|
||||
|
||||
// ============================== Popular ===============================
|
||||
override fun popularAnimeSelector() = latestUpdatesSelector()
|
||||
@ -75,8 +76,12 @@ class AnimeFire : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
// ============================ Video Links =============================
|
||||
override fun videoListParse(response: Response): List<Video> {
|
||||
val document: Document = response.asJsoup()
|
||||
val extractor = AnimeFireExtractor(client, json)
|
||||
return extractor.videoListFromDocument(document)
|
||||
val videoElement = document.selectFirst("video#my-video")
|
||||
return if (videoElement != null) {
|
||||
AnimeFireExtractor(client, json).videoListFromElement(videoElement)
|
||||
} else {
|
||||
IframeExtractor(client).videoListFromDocument(document)
|
||||
}
|
||||
}
|
||||
|
||||
override fun videoListSelector() = throw Exception("not used")
|
||||
@ -89,12 +94,27 @@ class AnimeFire : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
override fun searchAnimeNextPageSelector() = latestUpdatesNextPageSelector()
|
||||
|
||||
override fun fetchSearchAnime(page: Int, query: String, filters: AnimeFilterList): Observable<AnimesPage> {
|
||||
val params = AFFilters.getSearchParameters(filters)
|
||||
return client.newCall(searchAnimeRequest(page, query, params))
|
||||
.asObservableSuccess()
|
||||
.map { response ->
|
||||
searchAnimeParse(response)
|
||||
}
|
||||
return if (query.startsWith(AFConstants.PREFIX_SEARCH)) {
|
||||
val id = query.removePrefix(AFConstants.PREFIX_SEARCH)
|
||||
client.newCall(GET("$baseUrl/animes/$id"))
|
||||
.asObservableSuccess()
|
||||
.map { response ->
|
||||
searchAnimeByIdParse(response, id)
|
||||
}
|
||||
} else {
|
||||
val params = AFFilters.getSearchParameters(filters)
|
||||
client.newCall(searchAnimeRequest(page, query, params))
|
||||
.asObservableSuccess()
|
||||
.map { response ->
|
||||
searchAnimeParse(response)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun searchAnimeByIdParse(response: Response, id: String): AnimesPage {
|
||||
val details = animeDetailsParse(response)
|
||||
details.url = "/animes/$id"
|
||||
return AnimesPage(listOf(details), false)
|
||||
}
|
||||
|
||||
override fun searchAnimeRequest(page: Int, query: String, filters: AnimeFilterList): Request = throw Exception("not used")
|
||||
@ -158,11 +178,11 @@ class AnimeFire : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
// ============================== Settings ==============================
|
||||
override fun setupPreferenceScreen(screen: PreferenceScreen) {
|
||||
val videoQualityPref = ListPreference(screen.context).apply {
|
||||
key = PREFERRED_QUALITY
|
||||
key = AFConstants.PREFERRED_QUALITY
|
||||
title = "Qualidade preferida"
|
||||
entries = QUALITY_LIST
|
||||
entryValues = QUALITY_LIST
|
||||
setDefaultValue(QUALITY_LIST.last())
|
||||
entries = AFConstants.QUALITY_LIST
|
||||
entryValues = AFConstants.QUALITY_LIST
|
||||
setDefaultValue(AFConstants.QUALITY_LIST.last())
|
||||
summary = "%s"
|
||||
setOnPreferenceChangeListener { _, newValue ->
|
||||
val selected = newValue as String
|
||||
@ -195,7 +215,7 @@ class AnimeFire : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
}
|
||||
|
||||
override fun List<Video>.sort(): List<Video> {
|
||||
val quality = preferences.getString(PREFERRED_QUALITY, null)
|
||||
val quality = preferences.getString(AFConstants.PREFERRED_QUALITY, null)
|
||||
if (quality != null) {
|
||||
val newList = mutableListOf<Video>()
|
||||
var preferred = 0
|
||||
@ -211,10 +231,4 @@ class AnimeFire : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val ACCEPT_LANGUAGE = "pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7"
|
||||
private const val PREFERRED_QUALITY = "preferred_quality"
|
||||
private val QUALITY_LIST = arrayOf("360p", "720p")
|
||||
}
|
||||
}
|
||||
|
@ -6,11 +6,11 @@ import eu.kanade.tachiyomi.network.GET
|
||||
import kotlinx.serialization.decodeFromString
|
||||
import kotlinx.serialization.json.Json
|
||||
import okhttp3.OkHttpClient
|
||||
import org.jsoup.nodes.Document
|
||||
|
||||
import org.jsoup.nodes.Element
|
||||
class AnimeFireExtractor(private val client: OkHttpClient, private val json: Json) {
|
||||
fun videoListFromDocument(doc: Document): List<Video> {
|
||||
val jsonUrl = doc.selectFirst("video#my-video").attr("data-video-src")
|
||||
|
||||
fun videoListFromElement(videoElement: Element): List<Video> {
|
||||
val jsonUrl = videoElement.attr("data-video-src")
|
||||
val response = client.newCall(GET(jsonUrl)).execute()
|
||||
val responseDto = json.decodeFromString<AFResponseDto>(
|
||||
response.body?.string().orEmpty()
|
||||
|
@ -0,0 +1,25 @@
|
||||
package eu.kanade.tachiyomi.animeextension.pt.animefire.extractors
|
||||
|
||||
import eu.kanade.tachiyomi.animeextension.pt.animefire.AFConstants
|
||||
import eu.kanade.tachiyomi.animesource.model.Video
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import okhttp3.Headers
|
||||
import okhttp3.OkHttpClient
|
||||
import org.jsoup.nodes.Document
|
||||
|
||||
class IframeExtractor(private val client: OkHttpClient) {
|
||||
|
||||
private val headers = Headers.headersOf("User-Agent", AFConstants.USER_AGENT)
|
||||
|
||||
fun videoListFromDocument(doc: Document): List<Video> {
|
||||
val iframeElement = doc.selectFirst("div#div_video iframe")
|
||||
val iframeUrl = iframeElement.attr("src")
|
||||
val response = client.newCall(GET(iframeUrl, headers)).execute()
|
||||
val html = response.body?.string().orEmpty()
|
||||
val url = html.substringAfter("play_url")
|
||||
.substringAfter(":\"")
|
||||
.substringBefore("\"")
|
||||
val video = Video(url, "Default", url, null, headers)
|
||||
return listOf(video)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user