This repository has been archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add PH CDN extractor * update extractor * update code * update gradle version * update version * fix preference screen * fix version
- Loading branch information
1 parent
aa00bfb
commit 1555f1b
Showing
4 changed files
with
66 additions
and
46 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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#Mon Jul 31 23:55:52 NPT 2023 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
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
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
59 changes: 59 additions & 0 deletions
59
...l/pornhub/src/eu/kanade/tachiyomi/animeextension/all/pornhub/extractors/PhCdnExtractor.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,59 @@ | ||
package eu.kanade.tachiyomi.animeextension.all.pornhub.extractors | ||
|
||
import eu.kanade.tachiyomi.animesource.model.Video | ||
import eu.kanade.tachiyomi.network.GET | ||
import eu.kanade.tachiyomi.util.asJsoup | ||
import okhttp3.OkHttpClient | ||
|
||
class PhCdnExtractor(private val client: OkHttpClient) { | ||
fun videoFromUrl(videoUrl: String): MutableList<Video> { | ||
val pattern = Regex("(?<=viewkey=)[^&]+") | ||
val key = pattern.find(videoUrl)?.value | ||
val document = client.newCall(GET("https://www.pornhub.com/embed/$key")).execute().asJsoup() | ||
val scriptPart = document.select("body > script:nth-child(7)").html() | ||
// contains the stream url broken into multiple random variables and comments | ||
var vars = scriptPart.subSequence( | ||
scriptPart.indexOf("var ra"), | ||
scriptPart.indexOf(";flashvars.mediaDefinitions.hls") + 1 | ||
).toString().split(";").toMutableList() | ||
vars = vars.map { | ||
it.replace("var ", "") | ||
}.toMutableList() | ||
|
||
var hls = String() | ||
var quality = String() | ||
// create a map of variable to value | ||
val data = mutableMapOf<String, String>() | ||
for (v in vars) { | ||
if (v.isEmpty()) { | ||
continue | ||
} | ||
val index = v.indexOf("=") | ||
if (v.startsWith("hls")) { | ||
val tmp = removeComment(v) | ||
quality = tmp.replace("hls", "").split("=")[0] | ||
hls = tmp.subSequence(index + 1, tmp.length).toString() | ||
} else { | ||
val x = v.subSequence(0, index).toString() | ||
val y = v.subSequence(index + 1, v.length).toString().replace("\"", "").replace(" + ", "") | ||
data.put(x, y) | ||
} | ||
} | ||
// replace the variables in hls from the map created above | ||
var finalHls = String() | ||
for (part in hls.split(" + ")) { | ||
finalHls += data.get(part) | ||
} | ||
val streamFile = client.newCall(GET(finalHls)).execute().body!!.string().split("\n").filter { | ||
it.contains("index") | ||
}[0] | ||
val streamUrl = finalHls.subSequence(0, finalHls.indexOf("master")).toString() + streamFile | ||
val videoList = mutableListOf<Video>() | ||
videoList.add(Video(streamUrl, quality + 'p', streamUrl)) | ||
return videoList | ||
} | ||
|
||
private fun removeComment(v: String): String { | ||
return v.replace(Regex("""(\/\/[^\n]*|\/\*(.|[\r\n])*?\*\/)"""), "") | ||
} | ||
} |