add Cinemathek extension (#742)

This commit is contained in:
LuftVerbot
2022-08-08 13:54:20 +02:00
committed by GitHub
parent 2a2fef0bfb
commit 48ae7d7b13
19 changed files with 242 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,12 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
ext {
extName = 'Cinemathek'
pkgNameSuffix = 'de.cinemathek'
extClass = '.Cinemathek'
extVersionCode = 1
libVersion = '13'
}
apply from: "$rootDir/common.gradle"

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@ -0,0 +1,195 @@
package eu.kanade.tachiyomi.animeextension.de.cinemathek
import android.app.Application
import android.content.SharedPreferences
import androidx.preference.ListPreference
import androidx.preference.PreferenceScreen
import eu.kanade.tachiyomi.animeextension.de.cinemathek.extractors.StreamlareExtractor
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.network.POST
import eu.kanade.tachiyomi.util.asJsoup
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody.Companion.toRequestBody
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 Cinemathek : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
override val name = "Cinemathek"
override val baseUrl = "https://cinemathek.net"
override val lang = "de"
override val supportsLatest = false
override val client: OkHttpClient = network.cloudflareClient
private val preferences: SharedPreferences by lazy {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
}
// Popular Anime
override fun popularAnimeSelector(): String = "article.movies"
override fun popularAnimeRequest(page: Int): Request = GET("$baseUrl/movies/page/$page/")
override fun popularAnimeFromElement(element: Element): SAnime {
val anime = SAnime.create()
anime.setUrlWithoutDomain(element.select("div.poster a").attr("href"))
anime.title = element.select("div.data h3").text()
anime.thumbnail_url = element.select("div.poster img").attr("src")
return anime
}
override fun popularAnimeNextPageSelector(): String = ".arrow_pag"
// Episodes
override fun episodeListSelector() = throw Exception("not used")
override fun episodeListParse(response: Response): List<SEpisode> {
val document = response.asJsoup()
val episodeList = mutableListOf<SEpisode>()
val episode = SEpisode.create()
episode.name = document.select("div.data > h1").text()
episode.episode_number = 1F
episode.setUrlWithoutDomain(document.select("link[rel=canonical]").attr("href"))
episodeList.add(episode)
return episodeList.reversed()
}
override fun episodeFromElement(element: Element): SEpisode = throw Exception("not Used")
// Video urls
override fun videoListSelector(): String = throw Exception("not Used")
override fun videoListParse(response: Response): List<Video> {
val document = response.asJsoup()
return videosFromElement(document)
}
private fun videosFromElement(document: Document): List<Video> {
val id = document.select("#player-option-1").attr("data-post")
val ajax = client.newCall(POST("$baseUrl/wp-admin/admin-ajax.php", body = "action=doo_player_ajax&post=$id&nume=1&type=movie".toRequestBody("application/x-www-form-urlencoded".toMediaType()))).execute().body!!.string()
val videoList = mutableListOf<Video>()
val url = ajax.substringAfter("embed_url\":\"").substringBefore("\",").replace("\\", "")
when {
url.contains("https://streamlare.com") -> {
videoList.addAll(StreamlareExtractor(client).videosFromUrl(url))
}
}
return videoList
}
override fun List<Video>.sort(): List<Video> {
val hoster = preferences.getString("preferred_quality", null)
val quality = preferences.getString("preferred_quality", "1080")!!
val hosterList = mutableListOf<Video>()
val otherList = mutableListOf<Video>()
if (hoster != null) {
for (video in this) {
if (video.url.contains(hoster)) {
hosterList.add(video)
} else {
otherList.add(video)
}
}
} else otherList += this
val newList = mutableListOf<Video>()
var preferred = 0
for (video in hosterList) {
if (video.quality.contains(quality)) {
newList.add(preferred, video)
preferred++
} else newList.add(video)
}
for (video in otherList) {
if (video.quality.contains(quality)) {
newList.add(preferred, video)
preferred++
} else newList.add(video)
}
return newList
}
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.select("div.thumbnail a").attr("href"))
anime.title = element.select("div.details div.title a").text()
anime.thumbnail_url = element.select("div.image img").attr("src")
return anime
}
override fun searchAnimeNextPageSelector(): String = ".arrow_pag"
override fun searchAnimeSelector(): String = "div.result-item"
override fun searchAnimeRequest(page: Int, query: String, filters: AnimeFilterList): Request {
return GET("$baseUrl/page/$page/?s=$query")
}
// Details
override fun animeDetailsParse(document: Document): SAnime {
val anime = SAnime.create()
anime.thumbnail_url = document.select(".poster > img").attr("src")
anime.title = document.select("div.data > h1").text()
anime.genre = document.select(".sgeneros > a").joinToString(", ") { it.text() }
anime.status = SAnime.COMPLETED
anime.author = document.select("div.persons div.person[itemprop=director] div.name a").joinToString(", ") { it.text() }
anime.description = document.select(".wp-content > p:nth-child(1)").text()
return anime
}
// 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")
// settings
override fun setupPreferenceScreen(screen: PreferenceScreen) {
val videoQualityPref = ListPreference(screen.context).apply {
key = "preferred_quality"
title = "Preferred quality"
entries = arrayOf("1080p", "720p", "480p", "360p")
entryValues = arrayOf("1080", "720", "480", "360")
setDefaultValue("1080")
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()
}
}
screen.addPreference(videoQualityPref)
}
}

View File

@ -0,0 +1,33 @@
package eu.kanade.tachiyomi.animeextension.de.cinemathek.extractors
import eu.kanade.tachiyomi.animesource.model.Video
import eu.kanade.tachiyomi.network.POST
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.RequestBody.Companion.toRequestBody
class StreamlareExtractor(private val client: OkHttpClient) {
fun videosFromUrl(url: String): List<Video> {
val id = url.substringAfter("/e/").substringBefore("/")
val videoList = mutableListOf<Video>()
val playlist = client.newCall(
POST(
"https://slwatch.co/api/video/stream/get",
body = "{\"id\":\"$id\"}"
.toRequestBody("application/json".toMediaType())
)
)
.execute().body!!.string()
playlist.substringAfter("\"label\":\"").split("\"label\":\"").forEach {
val quality = it.substringAfter("\"label\":\"").substringBefore("\",")
val token = it.substringAfter("\"file\":\"https:\\/\\/larecontent.com\\/video?token=")
.substringBefore("\",")
val response = client.newCall(POST("https://larecontent.com/video?token=$token")).execute()
val videoUrl = response.request.url.toString()
videoList.addAll((listOf(Video(videoUrl, quality, videoUrl))))
}
return videoList
}
}