add animetoast extension (#856)

This commit is contained in:
LuftVerbot
2022-09-10 23:11:13 +02:00
committed by GitHub
parent 5f335ade61
commit 4082065eac
20 changed files with 319 additions and 0 deletions

View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="eu.kanade.tachiyomi.animeextension" />

View File

@ -0,0 +1,13 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlinx-serialization'
ext {
extName = 'AnimeToast'
pkgNameSuffix = 'de.animetoast'
extClass = '.AnimeToast'
extVersionCode = 1
libVersion = '13'
}
apply from: "$rootDir/common.gradle"

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

View File

@ -0,0 +1,247 @@
package eu.kanade.tachiyomi.animeextension.de.animetoast
import android.app.Application
import android.content.SharedPreferences
import androidx.preference.ListPreference
import androidx.preference.MultiSelectListPreference
import androidx.preference.PreferenceScreen
import eu.kanade.tachiyomi.animeextension.de.animetoast.extractors.DoodExtractor
import eu.kanade.tachiyomi.animeextension.de.animetoast.extractors.VoeExtractor
import eu.kanade.tachiyomi.animesource.ConfigurableAnimeSource
import eu.kanade.tachiyomi.animesource.model.AnimeFilterList
import eu.kanade.tachiyomi.animesource.model.SAnime
import eu.kanade.tachiyomi.animesource.model.SEpisode
import eu.kanade.tachiyomi.animesource.model.Video
import eu.kanade.tachiyomi.animesource.online.ParsedAnimeHttpSource
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.util.asJsoup
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import kotlin.Exception
class AnimeToast : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
override val name = "AnimeToast"
override val baseUrl = "https://www.animetoast.cc"
override val lang = "de"
override val supportsLatest = true
override val client: OkHttpClient = network.cloudflareClient
private val preferences: SharedPreferences by lazy {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
}
override fun popularAnimeSelector(): String = "div.row div.col-md-4 div.video-item"
override fun popularAnimeRequest(page: Int): Request = GET(baseUrl)
override fun popularAnimeFromElement(element: Element): SAnime {
val anime = SAnime.create()
anime.setUrlWithoutDomain(element.select("div.item-thumbnail a").attr("href"))
val document = client.newCall(GET(baseUrl + anime.url)).execute().asJsoup()
anime.thumbnail_url = document.select(".item-content p img").attr("src")
anime.title = element.select("div.item-thumbnail a").attr("title")
return anime
}
override fun popularAnimeNextPageSelector(): String? = null
// episodes
override fun episodeListSelector() = throw Exception("not used")
override fun episodeListParse(response: Response): List<SEpisode> {
val document = response.asJsoup()
val episodeList = mutableListOf<SEpisode>()
val file = document.select("a[rel=\"category tag\"]").text()
if (file.contains("Serie")) {
val elements = document.select("#multi_link_tab0")
elements.forEach {
val episode = parseEpisodesFromSeries(it)
episodeList.addAll(episode)
}
} else {
val episode = SEpisode.create()
episode.setUrlWithoutDomain(document.select("link[rel=canonical]").attr("href"))
episode.name = document.select("h1.light-title").text()
episode.episode_number = 1F
episodeList.add(episode)
}
return episodeList.reversed()
}
private fun parseEpisodesFromSeries(element: Element): List<SEpisode> {
val episodeElements = element.select("div.tab-pane a")
return episodeElements.map { episodeFromElement(it) }
}
override fun episodeFromElement(element: Element): SEpisode {
val episode = SEpisode.create()
episode.episode_number = element.text().replace("Ep. ", "").toFloat()
episode.name = element.text()
episode.setUrlWithoutDomain(element.attr("href"))
return episode
}
// Video Extractor
override fun videoListParse(response: Response): List<Video> {
val document = response.asJsoup()
return videosFromElement(document)
}
private fun videosFromElement(document: Document): List<Video> {
val videoList = mutableListOf<Video>()
val epcu = document.select("div.tab-pane a.current-link").text().replace("Ep. ", "").toInt()
val ep = document.select("div.tab-pane a")
ep.forEach {
if (it.text().replace("Ep. ", "").toInt() == epcu) {
val url = it.attr("href")
val newdoc = client.newCall(GET(url)).execute().asJsoup()
val element = newdoc.select("#player-embed")
val hosterSelection = preferences.getStringSet("hoster_selection", setOf("voe", "dood"))
for (elements in element) {
val link = element.select("a").attr("abs:href")
when {
link.contains("https://voe.sx") && hosterSelection?.contains("voe") == true -> {
val quality = "Voe"
val video = VoeExtractor(client).videoFromUrl(link, quality)
if (video != null) {
videoList.add(video)
}
}
}
}
for (elements in element) {
val link = element.select("iframe").attr("abs:src")
when {
link.contains("https://dood") && hosterSelection?.contains("dood") == true -> {
val quality = "DoodStream"
val video = DoodExtractor(client).videoFromUrl(link, quality)
if (video != null) {
videoList.add(video)
}
}
}
}
}
}
return videoList.reversed()
}
override fun List<Video>.sort(): List<Video> {
val hoster = preferences.getString("preferred_hoster", null)
if (hoster != null) {
val newList = mutableListOf<Video>()
var preferred = 0
for (video in this) {
if (video.quality.contains(hoster)) {
newList.add(preferred, video)
preferred++
} else {
newList.add(video)
}
}
return newList
}
return this
}
override fun videoListSelector() = throw Exception("not used")
override fun videoFromElement(element: Element) = throw Exception("not used")
override fun videoUrlParse(document: Document) = throw Exception("not used")
// Search
override fun searchAnimeFromElement(element: Element): SAnime {
val anime = SAnime.create()
anime.setUrlWithoutDomain(element.attr("href"))
val document = client.newCall(GET(baseUrl + anime.url)).execute().asJsoup()
anime.thumbnail_url = document.select(".item-content p img").attr("src")
anime.title = element.attr("title")
return anime
}
override fun searchAnimeNextPageSelector(): String = ".nextpostslink"
override fun searchAnimeSelector(): String = "div.item-thumbnail a[href]"
override fun searchAnimeRequest(page: Int, query: String, filters: AnimeFilterList): Request {
val url = "$baseUrl/page/$page/?s=$query"
return GET(url)
}
// Details
override fun animeDetailsParse(document: Document): SAnime {
val anime = SAnime.create()
anime.thumbnail_url = document.select(".item-content p img").attr("src")
anime.title = document.select("h1.light-title.entry-title").text()
anime.genre = document.select("a[rel=tag]").joinToString(", ") { it.text() }
val heigt = document.select("div.item-content p img").attr("height")
anime.description = document.select("div.item-content").toString()
.substringAfter("$heigt\">").replace("</p>", "").substringBefore("<strong>Genre:").replace("<p>", "")
anime.status = parseStatus(document.select("a[rel=\"category tag\"]").text())
return anime
}
private fun parseStatus(status: String?) = when {
status == null -> SAnime.UNKNOWN
status.contains("Airing", ignoreCase = true) -> SAnime.ONGOING
else -> SAnime.COMPLETED
}
// Latest
override fun latestUpdatesNextPageSelector(): String = throw Exception("Not used")
override fun latestUpdatesFromElement(element: Element): SAnime = throw Exception("Not used")
override fun latestUpdatesRequest(page: Int): Request = throw Exception("Not used")
override fun latestUpdatesSelector(): String = throw Exception("Not used")
// Preferences
override fun setupPreferenceScreen(screen: PreferenceScreen) {
val hosterPref = ListPreference(screen.context).apply {
key = "preferred_hoster"
title = "Standard-Hoster"
entries = arrayOf("Voe", "DoodStream")
entryValues = arrayOf("https://voe.sx", "https://dood")
setDefaultValue("https://voe.sx")
summary = "%s"
setOnPreferenceChangeListener { _, newValue ->
val selected = newValue as String
val index = findIndexOfValue(selected)
val entry = entryValues[index] as String
preferences.edit().putString(key, entry).commit()
}
}
val subSelection = MultiSelectListPreference(screen.context).apply {
key = "hoster_selection"
title = "Hoster auswählen"
entries = arrayOf("Voe", "DoodStream")
entryValues = arrayOf("voe", "dood")
setDefaultValue(setOf("voe", "dood"))
setOnPreferenceChangeListener { _, newValue ->
preferences.edit().putStringSet(key, newValue as Set<String>).commit()
}
}
screen.addPreference(hosterPref)
screen.addPreference(subSelection)
}
}

View File

@ -0,0 +1,40 @@
package eu.kanade.tachiyomi.animeextension.de.animetoast.extractors
import eu.kanade.tachiyomi.animesource.model.Video
import eu.kanade.tachiyomi.network.GET
import okhttp3.Headers
import okhttp3.OkHttpClient
class DoodExtractor(private val client: OkHttpClient) {
fun videoFromUrl(url: String, quality: String): Video? {
val response = client.newCall(GET(url)).execute()
val doodTld = url.substringAfter("https://dood.").substringBefore("/")
val content = response.body!!.string()
if (!content.contains("'/pass_md5/")) return null
val md5 = content.substringAfter("'/pass_md5/").substringBefore("',")
val token = md5.substringAfterLast("/")
val randomString = getRandomString()
val expiry = System.currentTimeMillis()
val videoUrlStart = client.newCall(
GET(
"https://dood.$doodTld/pass_md5/$md5",
Headers.headersOf("referer", url)
)
).execute().body!!.string()
val videoUrl = "$videoUrlStart$randomString?token=$token&expiry=$expiry"
return Video(url, quality, videoUrl, null, doodHeaders(doodTld))
}
private fun getRandomString(length: Int = 10): String {
val allowedChars = ('A'..'Z') + ('a'..'z') + ('0'..'9')
return (1..length)
.map { allowedChars.random() }
.joinToString("")
}
private fun doodHeaders(tld: String) = Headers.Builder().apply {
add("User-Agent", "Aniyomi")
add("Referer", "https://dood.$tld/")
}.build()
}

View File

@ -0,0 +1,17 @@
package eu.kanade.tachiyomi.animeextension.de.animetoast.extractors
import eu.kanade.tachiyomi.animesource.model.Video
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.util.asJsoup
import okhttp3.OkHttpClient
class VoeExtractor(private val client: OkHttpClient) {
fun videoFromUrl(url: String, quality: String): Video? {
val document = client.newCall(GET(url)).execute().asJsoup()
val script = document.select("script:containsData(function d04ad2e48229ae25a282e15c7c2f69a2(dea04c5949242bfd216e35def894b930))")
.firstOrNull()?.data()?.substringAfter("\"hls\": \"") ?: return null
val videoUrl = script.substringAfter("\"hls\": \"").substringBefore("\",")
return Video(url, quality, videoUrl)
}
}