Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(src/tr): New source: HDFilmCehennemi #2345

Merged
merged 10 commits into from
Oct 10, 2023
22 changes: 22 additions & 0 deletions src/tr/hdfilmcehennemi/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application>
<activity
android:name=".tr.hdfilmcehennemi.HDFilmCehennemiUrlActivity"
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="www.hdfilmcehennemi.life"
android:pathPattern="/..*"
android:scheme="https" />
</intent-filter>
</activity>
</application>
</manifest>
21 changes: 21 additions & 0 deletions src/tr/hdfilmcehennemi/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.serialization)
}

ext {
extName = 'HDFilmCehennemi'
pkgNameSuffix = 'tr.hdfilmcehennemi'
extClass = '.HDFilmCehennemi'
extVersionCode = 1
libVersion = '13'
containsNsfw = true
}

dependencies {
implementation(project(":lib-unpacker"))
implementation(project(":lib-playlist-utils"))
}

apply from: "$rootDir/common.gradle"
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
package eu.kanade.tachiyomi.animeextension.tr.hdfilmcehennemi

import android.app.Application
import androidx.preference.ListPreference
import androidx.preference.PreferenceScreen
import eu.kanade.tachiyomi.animeextension.tr.hdfilmcehennemi.extractors.RapidrameExtractor
import eu.kanade.tachiyomi.animeextension.tr.hdfilmcehennemi.extractors.VidmolyExtractor
import eu.kanade.tachiyomi.animesource.ConfigurableAnimeSource
import eu.kanade.tachiyomi.animesource.model.AnimeFilterList
import eu.kanade.tachiyomi.animesource.model.AnimesPage
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.network.asObservableSuccess
import eu.kanade.tachiyomi.util.asJsoup
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.runBlocking
import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import okhttp3.FormBody
import okhttp3.Request
import okhttp3.Response
import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import rx.Observable
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy

class HDFilmCehennemi : ConfigurableAnimeSource, ParsedAnimeHttpSource() {

override val name = "HDFilmCehennemi"

override val baseUrl = "https://www.hdfilmcehennemi.life"

override val lang = "tr"

override val supportsLatest = true

override val client = network.cloudflareClient

override fun headersBuilder() = super.headersBuilder()
.add("Referer", "$baseUrl/")
.add("Origin", baseUrl)

private val json: Json by injectLazy()

private val preferences by lazy {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
}

// ============================== Popular ===============================
override fun popularAnimeRequest(page: Int) = GET("$baseUrl/en-cok-begenilen-filmleri-izle/page/$page/")

override fun popularAnimeSelector() = "div.row div.poster > a"

override fun popularAnimeFromElement(element: Element) = SAnime.create().apply {
setUrlWithoutDomain(element.attr("href"))
title = element.selectFirst("h2.title")!!.text()
thumbnail_url = element.selectFirst("img")?.absUrl("data-src")
}

override fun popularAnimeNextPageSelector() = "ul.pagination > li > a[rel=next]"

// =============================== Latest ===============================
override fun latestUpdatesRequest(page: Int) = GET("$baseUrl/page/$page/")

override fun latestUpdatesSelector() = popularAnimeSelector()

override fun latestUpdatesFromElement(element: Element) = popularAnimeFromElement(element)

override fun latestUpdatesNextPageSelector() = popularAnimeNextPageSelector()

// =============================== Search ===============================
override fun fetchSearchAnime(page: Int, query: String, filters: AnimeFilterList): Observable<AnimesPage> {
return if (query.startsWith(PREFIX_SEARCH)) { // URL intent handler
val id = query.removePrefix(PREFIX_SEARCH)
client.newCall(GET("$baseUrl/$id"))
.asObservableSuccess()
.map(::searchAnimeByIdParse)
} else {
super.fetchSearchAnime(page, query, filters)
}
}

private fun searchAnimeByIdParse(response: Response): AnimesPage {
val details = animeDetailsParse(response.use { it.asJsoup() })
return AnimesPage(listOf(details), false)
}

override fun searchAnimeRequest(page: Int, query: String, filters: AnimeFilterList): Request {
val headers = headersBuilder()
.add("Referer", "$baseUrl/")
.add("Origin", baseUrl)
.add("X-Requested-With", "XMLHttpRequest")
.build()

val body = FormBody.Builder().add("query", query).build()

return POST("$baseUrl/search/", headers, body)
}

@Serializable
data class SearchResponse(val result: List<MovieDto>)

@Serializable
data class MovieDto(val title: String, val poster: String, val slug: String)

override fun searchAnimeParse(response: Response): AnimesPage {
val data = response.parseAs<SearchResponse>()
val movies = data.result.map {
SAnime.create().apply {
title = it.title
thumbnail_url = "$baseUrl/uploads/poster/" + it.poster
url = "/" + it.slug
}
}

return AnimesPage(movies, false)
}

override fun searchAnimeSelector(): String {
throw UnsupportedOperationException("Not used.")
}

override fun searchAnimeFromElement(element: Element): SAnime {
throw UnsupportedOperationException("Not used.")
}

override fun searchAnimeNextPageSelector(): String? {
throw UnsupportedOperationException("Not used.")
}

// =========================== Anime Details ============================
override fun animeDetailsParse(document: Document) = SAnime.create().apply {
status = SAnime.COMPLETED

val div = document.selectFirst("div.card-body > div.row")!!

div.selectFirst("img")!!.run {
thumbnail_url = absUrl("src")
title = attr("alt")
}

genre = div.select("div > a[href*=tur/]").eachText().joinToString().takeIf(String::isNotEmpty)
artist = div.select("a.chip[href*=oyuncu/]").eachText().joinToString().takeIf(String::isNotEmpty)

description = div.selectFirst("article > p")?.text()
}

// ============================== Episodes ==============================
override fun fetchEpisodeList(anime: SAnime) = Observable.just(
listOf(
SEpisode.create().apply {
url = anime.url
name = "Movie"
},
),
)

override fun episodeListSelector(): String {
throw UnsupportedOperationException("Not used.")
}

override fun episodeFromElement(element: Element): SEpisode {
throw UnsupportedOperationException("Not used.")
}

// ============================ Video Links =============================
private val vidmolyExtractor by lazy { VidmolyExtractor(client, headers) }
private val rapidrameExtractor by lazy { RapidrameExtractor(client, headers) }

override fun videoListParse(response: Response): List<Video> {
val doc = response.use { it.asJsoup() }

return doc.select("div.card-body > nav > a:not([href=#])")
.drop(1)
.parallelMap { client.newCall(GET(it.attr("href") + "/")).execute().use { it.asJsoup() } }
.let { listOf(doc) + it }
.mapNotNull { it.selectFirst("div.card-video > iframe")?.attr("data-src") }
.filter(String::isNotBlank)
.parallelMap { url ->
runCatching {
when {
url.contains("vidmoly") -> vidmolyExtractor.videosFromUrl(url)
url.contains("$baseUrl/playerr") -> rapidrameExtractor.videosFromUrl(url)
else -> emptyList<Video>()
}
}.getOrNull() ?: emptyList<Video>()
}.flatten().ifEmpty { throw Exception("No videos available xD") }
}

override fun videoListSelector(): String {
throw UnsupportedOperationException("Not used.")
}

override fun videoFromElement(element: Element): Video {
throw UnsupportedOperationException("Not used.")
}

override fun videoUrlParse(document: Document): String {
throw UnsupportedOperationException("Not used.")
}

// ============================== Settings ==============================
override fun setupPreferenceScreen(screen: PreferenceScreen) {
ListPreference(screen.context).apply {
key = PREF_QUALITY_KEY
title = PREF_QUALITY_TITLE
entries = PREF_QUALITY_ENTRIES
entryValues = PREF_QUALITY_VALUES
setDefaultValue(PREF_QUALITY_DEFAULT)
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()
}
}.also(screen::addPreference)
}

// ============================= Utilities ==============================
private inline fun <reified T> Response.parseAs(): T {
return use { it.body.string() }.let(json::decodeFromString)
}

private inline fun <A, B> Iterable<A>.parallelMap(crossinline f: suspend (A) -> B): List<B> =
runBlocking {
map { async(Dispatchers.Default) { f(it) } }.awaitAll()
}

override fun List<Video>.sort(): List<Video> {
val quality = preferences.getString(PREF_QUALITY_KEY, PREF_QUALITY_DEFAULT)!!

return sortedWith(
compareBy { it.quality.contains(quality) },
).reversed()
}

companion object {
const val PREFIX_SEARCH = "id:"

private const val PREF_QUALITY_KEY = "pref_quality_key"
private const val PREF_QUALITY_TITLE = "Preferred quality"
private const val PREF_QUALITY_DEFAULT = "720p"
private val PREF_QUALITY_ENTRIES = arrayOf("360p", "480p", "720p", "1080p")
private val PREF_QUALITY_VALUES = PREF_QUALITY_ENTRIES
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package eu.kanade.tachiyomi.animeextension.tr.hdfilmcehennemi

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://www.hdfilmcehennemi.life/<item> intents
* and redirects them to the main Aniyomi process.
*/
class HDFilmCehennemiUrlActivity : Activity() {

private val tag = javaClass.simpleName

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val pathSegments = intent?.data?.pathSegments
if (pathSegments != null && pathSegments.size == 1) {
val item = pathSegments.first()
val mainIntent = Intent().apply {
action = "eu.kanade.tachiyomi.ANIMESEARCH"
putExtra("query", "${HDFilmCehennemi.PREFIX_SEARCH}$item")
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)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package eu.kanade.tachiyomi.animeextension.tr.hdfilmcehennemi.extractors

import android.util.Base64
import eu.kanade.tachiyomi.animesource.model.Video
import eu.kanade.tachiyomi.lib.playlistutils.PlaylistUtils
import eu.kanade.tachiyomi.lib.unpacker.Unpacker
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.util.asJsoup
import okhttp3.Headers
import okhttp3.OkHttpClient

class RapidrameExtractor(private val client: OkHttpClient, private val headers: Headers) {
private val playlistUtils by lazy { PlaylistUtils(client, headers) }

fun videosFromUrl(url: String): List<Video> {
val doc = client.newCall(GET(url, headers)).execute().use { it.asJsoup() }
val script = doc.selectFirst("script:containsData(eval):containsData(file_link)")
?.data()
?.let(Unpacker::unpack)
?.takeIf(String::isNotEmpty)
?: return emptyList()

val playlistUrl = script.substringAfter('"').substringBefore('"')
.let { String(Base64.decode(it, Base64.DEFAULT)) }

return playlistUtils.extractFromHls(playlistUrl, url, videoNameGen = { "Rapidrame - $it" })
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package eu.kanade.tachiyomi.animeextension.tr.hdfilmcehennemi.extractors

import eu.kanade.tachiyomi.animesource.model.Video
import eu.kanade.tachiyomi.lib.playlistutils.PlaylistUtils
import eu.kanade.tachiyomi.network.GET
import okhttp3.Headers
import okhttp3.OkHttpClient

class VidmolyExtractor(private val client: OkHttpClient, private val headers: Headers) {
private val playlistUtils by lazy { PlaylistUtils(client, headers) }

fun videosFromUrl(url: String): List<Video> {
val body = client.newCall(GET(url, headers)).execute()
.use { it.body.string() }

val playlistUrl = body.substringAfter("file:\"", "").substringBefore('"', "")
.takeIf(String::isNotBlank)
?: return emptyList()

return playlistUtils.extractFromHls(playlistUrl, url, videoNameGen = { "Vidmoly - $it" })
}
}