-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(pt/animesdigital): Fix video extractor (#2892)
- Loading branch information
1 parent
566b9e4
commit a77dcad
Showing
4 changed files
with
85 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,4 @@ apply from: "$rootDir/common.gradle" | |
|
||
dependencies { | ||
implementation(project(":lib:unpacker")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
.../src/eu/kanade/tachiyomi/animeextension/pt/animesdigital/extractors/ProtectorExtractor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package eu.kanade.tachiyomi.animeextension.pt.animesdigital.extractors | ||
|
||
import eu.kanade.tachiyomi.animesource.model.Video | ||
import eu.kanade.tachiyomi.network.GET | ||
import eu.kanade.tachiyomi.util.asJsoup | ||
import okhttp3.Headers | ||
import okhttp3.HttpUrl.Companion.toHttpUrl | ||
import okhttp3.OkHttpClient | ||
|
||
private const val HOST = "https://sabornutritivo.com" | ||
|
||
class ProtectorExtractor(private val client: OkHttpClient) { | ||
fun videosFromUrl(url: String): List<Video> { | ||
val fixedUrl = if (!url.startsWith("https")) "https:$url" else url | ||
val token = fixedUrl.toHttpUrl().queryParameter("token")!! | ||
val headers = Headers.headersOf("cookie", "token=$token;") | ||
val doc = client.newCall(GET("$HOST/social.php", headers)).execute().asJsoup() | ||
val videoHeaders = Headers.headersOf("referer", doc.location()) | ||
val iframeUrl = doc.selectFirst("iframe")!!.attr("src").trim() | ||
return listOf(Video(iframeUrl, "Animes Digital", iframeUrl, videoHeaders)) | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...tal/src/eu/kanade/tachiyomi/animeextension/pt/animesdigital/extractors/ScriptExtractor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package eu.kanade.tachiyomi.animeextension.pt.animesdigital.extractors | ||
|
||
import eu.kanade.tachiyomi.animesource.model.Video | ||
import eu.kanade.tachiyomi.lib.unpacker.Unpacker | ||
import okhttp3.Headers | ||
|
||
object ScriptExtractor { | ||
fun videosFromScript(scriptData: String, headers: Headers): List<Video> { | ||
val script = when { | ||
"eval(function" in scriptData -> Unpacker.unpack(scriptData) | ||
else -> scriptData | ||
}.ifEmpty { null }?.replace("\\", "") ?: return emptyList() | ||
|
||
return script.substringAfter("sources:").substringAfter(".src(") | ||
.substringBefore(")") | ||
.substringAfter("[") | ||
.substringBefore("]") | ||
.split("{") | ||
.drop(1) | ||
.map { | ||
val quality = it.substringAfter("label", "") | ||
.substringAfterKey() | ||
.trim() | ||
.ifEmpty { "Animes Digital" } | ||
val url = it.substringAfter("file").substringAfter("src") | ||
.substringAfterKey() | ||
.trim() | ||
Video(url, quality, url, headers) | ||
} | ||
} | ||
|
||
private fun String.substringAfterKey() = substringAfter(':') | ||
.substringAfter('"') | ||
.substringBefore('"') | ||
.substringAfter("'") | ||
.substringBefore("'") | ||
} |