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

fix(tr/hdfilmcehennemi): Update baseUrl + add another extractor #2490

Merged
merged 3 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/tr/hdfilmcehennemi/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<category android:name="android.intent.category.BROWSABLE" />

<data
android:host="www.hdfilmcehennemi.life"
android:host="www.hdfilmcehennemi.de"
android:pathPattern="/..*"
android:scheme="https" />
</intent-filter>
Expand Down
2 changes: 1 addition & 1 deletion src/tr/hdfilmcehennemi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ext {
extName = 'HDFilmCehennemi'
pkgNameSuffix = 'tr.hdfilmcehennemi'
extClass = '.HDFilmCehennemi'
extVersionCode = 3
extVersionCode = 4
libVersion = '13'
containsNsfw = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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.animeextension.tr.hdfilmcehennemi.extractors.XBetExtractor
import eu.kanade.tachiyomi.animesource.ConfigurableAnimeSource
import eu.kanade.tachiyomi.animesource.model.AnimeFilterList
import eu.kanade.tachiyomi.animesource.model.AnimesPage
Expand Down Expand Up @@ -37,7 +38,7 @@ class HDFilmCehennemi : ConfigurableAnimeSource, ParsedAnimeHttpSource() {

override val name = "HDFilmCehennemi"

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

override val lang = "tr"

Expand Down Expand Up @@ -96,8 +97,6 @@ class HDFilmCehennemi : ConfigurableAnimeSource, ParsedAnimeHttpSource() {

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()

Expand Down Expand Up @@ -175,6 +174,7 @@ class HDFilmCehennemi : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
// ============================ Video Links =============================
private val vidmolyExtractor by lazy { VidmolyExtractor(client, headers) }
private val rapidrameExtractor by lazy { RapidrameExtractor(client, headers) }
private val xbetExtractor by lazy { XBetExtractor(client, headers, json) }

override fun videoListParse(response: Response): List<Video> {
val doc = response.use { it.asJsoup() }
Expand All @@ -190,9 +190,10 @@ class HDFilmCehennemi : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
when {
url.contains("vidmoly") -> vidmolyExtractor.videosFromUrl(url)
url.contains("$baseUrl/playerr") -> rapidrameExtractor.videosFromUrl(url)
else -> emptyList<Video>()
url.contains("trstx.org") -> xbetExtractor.videosFromUrl(url)
else -> emptyList()
}
}.getOrNull() ?: emptyList<Video>()
}.getOrNull().orEmpty()
}.flatten().ifEmpty { throw Exception("No videos available xD") }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import android.util.Log
import kotlin.system.exitProcess

/**
* Springboard that accepts https://www.hdfilmcehennemi.life/<item> intents
* Springboard that accepts https://www.hdfilmcehennemi.de/<item> intents
* and redirects them to the main Aniyomi process.
*/
class HDFilmCehennemiUrlActivity : Activity() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
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 eu.kanade.tachiyomi.network.POST
import eu.kanade.tachiyomi.util.asJsoup
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import okhttp3.Headers
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.OkHttpClient
import okhttp3.Response

class XBetExtractor(
private val client: OkHttpClient,
private val headers: Headers,
private val json: Json,
) {
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(playerConfigs =)")?.data()
?: return emptyList()

val host = "https://${url.toHttpUrl().host}"

val postPath = script.substringAfter("file\":\"").substringBefore('"')
.replace("\\", "")

val postHeaders = headers.newBuilder()
.set("Referer", url)
.set("Origin", host)
.build()

val postRes = client.newCall(POST(host + postPath, postHeaders)).execute()
.parseAs<List<VideoItemDto>> { it.replace("[],", "") }

return postRes.flatMap { video ->
runCatching {
val playlistUrl = client.newCall(POST(host + video.path, postHeaders)).execute()
.use { it.body.string() }

playlistUtils.extractFromHls(
playlistUrl,
url,
videoNameGen = { "[${video.title}] XBet - $it" },
)
}.getOrElse { emptyList() }
}
}

@Serializable
data class VideoItemDto(val file: String, val title: String) {
val path = "/playlist/${file.removeSuffix("~")}.txt"
}

private inline fun <reified T> Response.parseAs(transform: (String) -> String = { it }): T {
val responseBody = use { transform(it.body.string()) }
return json.decodeFromString(responseBody)
}
}