@@ -12,6 +12,11 @@ import eu.kanade.tachiyomi.animesource.model.Video
12
12
import eu.kanade.tachiyomi.animesource.online.ParsedAnimeHttpSource
13
13
import eu.kanade.tachiyomi.network.GET
14
14
import eu.kanade.tachiyomi.util.asJsoup
15
+ import kotlinx.serialization.ExperimentalSerializationApi
16
+ import kotlinx.serialization.SerialName
17
+ import kotlinx.serialization.Serializable
18
+ import kotlinx.serialization.decodeFromString
19
+ import kotlinx.serialization.json.Json
15
20
import okhttp3.OkHttpClient
16
21
import okhttp3.Request
17
22
import okhttp3.Response
@@ -21,6 +26,7 @@ import org.jsoup.nodes.Document
21
26
import org.jsoup.nodes.Element
22
27
import uy.kohesive.injekt.Injekt
23
28
import uy.kohesive.injekt.api.get
29
+ import uy.kohesive.injekt.injectLazy
24
30
import java.lang.Exception
25
31
26
32
class Pornhub : ConfigurableAnimeSource , ParsedAnimeHttpSource () {
@@ -35,6 +41,8 @@ class Pornhub : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
35
41
36
42
override val client: OkHttpClient = network.cloudflareClient
37
43
44
+ private val json: Json by injectLazy()
45
+
38
46
private val preferences: SharedPreferences by lazy {
39
47
Injekt .get<Application >().getSharedPreferences(" source_$id " , 0x0000 )
40
48
}
@@ -59,8 +67,6 @@ class Pornhub : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
59
67
override fun episodeListParse (response : Response ): List <SEpisode > {
60
68
val episodes = mutableListOf<SEpisode >()
61
69
62
- val jsoup = response.asJsoup()
63
-
64
70
val episode = SEpisode .create().apply {
65
71
name = " Video"
66
72
date_upload = System .currentTimeMillis()
@@ -75,33 +81,24 @@ class Pornhub : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
75
81
76
82
override fun episodeFromElement (element : Element ) = throw Exception (" not used" )
77
83
84
+ @OptIn(ExperimentalSerializationApi ::class )
78
85
override fun videoListParse (response : Response ): List <Video > {
79
86
val url = response.request.url.toString()
80
87
val videoList = mutableListOf<Video >()
81
88
// credits to: https://github.com/Joel2B
82
- val document = Jsoup .connect(" https://appsdev.cyou/xv-ph-rt/api/?data=$url " ).ignoreContentType(true ).get()
83
- val jsonObject = JSONObject (document.select(" body" ).text())[" hls" ]
84
- val jsonUrls = JSONObject (jsonObject.toString())
85
-
86
- val url1080 = jsonUrls[" 1080p" ].toString().replace(" amp;" , " " )
87
- val url720 = jsonUrls[" 720p" ].toString().replace(" amp;" , " " )
88
- val url480 = jsonUrls[" 480p" ].toString().replace(" amp;" , " " )
89
- val url240 = jsonUrls[" 240p" ].toString().replace(" amp;" , " " )
90
-
91
- if (jsonUrls[" 1080p" ] != " " ) {
92
- videoList.add(Video (url1080, " 1080p" , url1080))
93
- }
94
- if (jsonUrls[" 720p" ] != " " ) {
95
- videoList.add(Video (url720, " 720p" , url720))
96
- }
97
- if (jsonUrls[" 480p" ] != " " ) {
98
- videoList.add(Video (url480, " 480p" , url480))
99
- }
100
- if (jsonUrls[" 240p" ] != " " ) {
101
- videoList.add(Video (url240, " 240p" , url240))
102
- }
103
-
104
- return videoList
89
+ val document = client.newCall(GET (" https://appsdev.cyou/xv-ph-rt/api/?data=$url " )).execute().asJsoup().body().text()
90
+ val jsonResponse = json.decodeFromString<PornApiResponse >(document)
91
+
92
+ return listOf (
93
+ Video (jsonResponse.hls!! .all!! ," HLS: ALL" ,jsonResponse.hls!! .all),
94
+ Video (jsonResponse.hls!! .low!! ," HLS: LOW" ,jsonResponse.hls!! .low),
95
+ Video (jsonResponse.hls!! .hd!! ," HLS: HD" ,jsonResponse.hls!! .hd),
96
+ Video (jsonResponse.hls!! .fhd!! ," HLS: FHD" ,jsonResponse.hls!! .fhd),
97
+ Video (jsonResponse.mp4!! .low!! ," MP4: LOW" ,jsonResponse.mp4!! .low),
98
+ Video (jsonResponse.mp4!! .sd!! ," MP4: SD" ,jsonResponse.mp4!! .sd),
99
+ Video (jsonResponse.mp4!! .hd!! ," MP4: HD" ,jsonResponse.mp4!! .hd),
100
+ Video (jsonResponse.mp4!! .fhd!! ," MP4: FHD" ,jsonResponse.mp4!! .fhd)
101
+ ).filter { it.url.isNotBlank() }
105
102
}
106
103
107
104
override fun videoListSelector () = throw Exception (" not used" )
@@ -131,9 +128,7 @@ class Pornhub : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
131
128
override fun searchAnimeRequest (page : Int , query : String , filters : AnimeFilterList ): Request {
132
129
return GET (" $baseUrl /video/search?search=$query &page=$page " , headers)
133
130
}
134
- override fun searchAnimeFromElement (element : Element ): SAnime {
135
- return popularAnimeFromElement(element)
136
- }
131
+ override fun searchAnimeFromElement (element : Element ): SAnime = popularAnimeFromElement(element)
137
132
138
133
override fun searchAnimeNextPageSelector (): String = popularAnimeNextPageSelector()
139
134
@@ -175,4 +170,33 @@ class Pornhub : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
175
170
}
176
171
screen.addPreference(videoQualityPref)
177
172
}
173
+
174
+ @Serializable
175
+ data class PornApiResponse (
176
+ var hls : Hls ? = Hls (),
177
+ var mp4 : Mp4 ? = Mp4 (),
178
+ var thumb : String? = null ,
179
+ var thumbnails : String? = null
180
+
181
+ )
182
+
183
+ @Serializable
184
+ data class Hls (
185
+ var all : String? = " " ,
186
+ @SerialName(" 1080p" ) var fhd : String? = " " ,
187
+ @SerialName(" 720p" ) var hd : String? = " " ,
188
+ @SerialName(" 480p" ) var sd : String? = " " ,
189
+ @SerialName(" 240p" ) var low : String? = " "
190
+
191
+ )
192
+
193
+ @Serializable
194
+ data class Mp4 (
195
+ @SerialName(" 1080p" ) var fhd : String? = " " ,
196
+ @SerialName(" 720p" ) var hd : String? = " " ,
197
+ @SerialName(" 480p" ) var sd : String? = " " ,
198
+ @SerialName(" 240p" ) var low : String? = " "
199
+ )
200
+
201
+
178
202
}
0 commit comments