Skip to content

Commit

Permalink
sflix,dopebox: add subs support (aniyomiorg#700)
Browse files Browse the repository at this point in the history
* Update build.gradle

* sflix,dopebox: add subs support

* fix for stable version
  • Loading branch information
ahmedgamal17 authored Jul 27, 2022
1 parent dcebc40 commit cd26d35
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/en/dopebox/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ext {
extName = 'DopeBox'
pkgNameSuffix = 'en.dopebox'
extClass = '.DopeBox'
extVersionCode = 5
extVersionCode = 6
libVersion = '13'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ import eu.kanade.tachiyomi.animesource.model.AnimeFilter
import eu.kanade.tachiyomi.animesource.model.AnimeFilterList
import eu.kanade.tachiyomi.animesource.model.SAnime
import eu.kanade.tachiyomi.animesource.model.SEpisode
import eu.kanade.tachiyomi.animesource.model.Track
import eu.kanade.tachiyomi.animesource.model.Video
import eu.kanade.tachiyomi.animesource.online.ParsedAnimeHttpSource
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.util.asJsoup
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.jsonArray
import kotlinx.serialization.json.jsonObject
import okhttp3.Headers
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
import okhttp3.OkHttpClient
Expand Down Expand Up @@ -158,29 +164,51 @@ class DopeBox : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
.post().toString().replace("\n", "").substringAfter("rresp\",\"").substringBefore("\"")

val jsonLink = "https://rabbitstream.net/ajax/embed-4/getSources?id=$videoEmbedUrlId&_token=$token&_number=$number&sId=test"
val reloadHeaderss = headers.newBuilder()
/*val reloadHeaderss = headers.newBuilder()
.set("X-Requested-With", "XMLHttpRequest")
.build()
val iframeResponse = client.newCall(GET(jsonLink, reloadHeaderss))
.execute().asJsoup()
*/

return videosFromElement(iframeResponse)
return videosFromElement(jsonLink)
}

private fun videosFromElement(element: Element): List<Video> {
val test = element.text()
val masterUrl = element.text().substringAfter("file\":\"").substringBefore("\",\"type")
if (test.contains("playlist.m3u8")) {
private fun videosFromElement(url: String): List<Video> {
val reloadHeaderss = headers.newBuilder()
.set("X-Requested-With", "XMLHttpRequest")
.build()
val json = Json.decodeFromString<JsonObject>(Jsoup.connect(url).header("X-Requested-With", "XMLHttpRequest").ignoreContentType(true).execute().body())
val masterUrl = json["sources"]!!.jsonArray[0].jsonObject["file"].toString().trim('"')
val subsList = mutableListOf<Track>()
json["tracks"]!!.jsonArray.forEach {
val subLang = it.jsonObject["label"].toString().substringAfter("\"").substringBefore("\"")
val subUrl = it.jsonObject["file"].toString().trim('"')
subsList.add(Track(subUrl, subLang))
}
if (masterUrl.contains("playlist.m3u8")) {
val masterPlaylist = client.newCall(GET(masterUrl)).execute().body!!.string()
val videoList = mutableListOf<Video>()
masterPlaylist.substringAfter("#EXT-X-STREAM-INF:").split("#EXT-X-STREAM-INF:").forEach {
val quality = it.substringAfter("RESOLUTION=").substringAfter("x").substringBefore("\n") + "p"
val videoUrl = it.substringAfter("\n").substringBefore("\n")
videoList.add(Video(videoUrl, quality, videoUrl))
videoList.add(
try {
Video(videoUrl, quality, videoUrl, subtitleTracks = subsList)
} catch (e: NoSuchMethodError) {
Video(videoUrl, quality, videoUrl)
}
)
}
return videoList
} else if (test.contains("index.m3u8")) {
return listOf(Video(masterUrl, "Default", masterUrl))
} else if (masterUrl.contains("index.m3u8")) {
return listOf(
try {
Video(masterUrl, "Default", masterUrl, subtitleTracks = subsList)
} catch (e: NoSuchMethodError) {
Video(masterUrl, "Default", masterUrl)
}
)
} else {
throw Exception("never give up and try again :)")
}
Expand Down
2 changes: 1 addition & 1 deletion src/en/sflix/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ext {
extName = 'Sflix'
pkgNameSuffix = 'en.sflix'
extClass = '.SFlix'
extVersionCode = 6
extVersionCode = 7
libVersion = '13'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ import eu.kanade.tachiyomi.animesource.model.AnimeFilter
import eu.kanade.tachiyomi.animesource.model.AnimeFilterList
import eu.kanade.tachiyomi.animesource.model.SAnime
import eu.kanade.tachiyomi.animesource.model.SEpisode
import eu.kanade.tachiyomi.animesource.model.Track
import eu.kanade.tachiyomi.animesource.model.Video
import eu.kanade.tachiyomi.animesource.online.ParsedAnimeHttpSource
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.util.asJsoup
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.jsonArray
import kotlinx.serialization.json.jsonObject
import okhttp3.Headers
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
import okhttp3.OkHttpClient
Expand Down Expand Up @@ -158,29 +164,50 @@ class SFlix : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
.post().toString().replace("\n", "").substringAfter("rresp\",\"").substringBefore("\"")

val jsonLink = "https://rabbitstream.net/ajax/embed-4/getSources?id=$videoEmbedUrlId&_token=$token&_number=$number&sId=test"
val reloadHeaderss = headers.newBuilder()
/*val reloadHeaderss = headers.newBuilder()
.set("X-Requested-With", "XMLHttpRequest")
.build()
val iframeResponse = client.newCall(GET(jsonLink, reloadHeaderss))
.execute().asJsoup()

return videosFromElement(iframeResponse)
*/
return videosFromElement(jsonLink)
}

private fun videosFromElement(element: Element): List<Video> {
val test = element.text()
val masterUrl = element.text().substringAfter("file\":\"").substringBefore("\",\"type")
if (test.contains("playlist.m3u8")) {
private fun videosFromElement(url: String): List<Video> {
val reloadHeaderss = headers.newBuilder()
.set("X-Requested-With", "XMLHttpRequest")
.build()
val json = Json.decodeFromString<JsonObject>(Jsoup.connect(url).header("X-Requested-With", "XMLHttpRequest").ignoreContentType(true).execute().body())
val masterUrl = json["sources"]!!.jsonArray[0].jsonObject["file"].toString().trim('"')
val subsList = mutableListOf<Track>()
json["tracks"]!!.jsonArray.forEach {
val subLang = it.jsonObject["label"].toString().substringAfter("\"").substringBefore("\"") // .trim('"')
val subUrl = it.jsonObject["file"].toString().trim('"')
subsList.add(Track(subUrl, subLang))
}
if (masterUrl.contains("playlist.m3u8")) {
val masterPlaylist = client.newCall(GET(masterUrl)).execute().body!!.string()
val videoList = mutableListOf<Video>()
masterPlaylist.substringAfter("#EXT-X-STREAM-INF:").split("#EXT-X-STREAM-INF:").forEach {
val quality = it.substringAfter("RESOLUTION=").substringAfter("x").substringBefore("\n") + "p"
val videoUrl = it.substringAfter("\n").substringBefore("\n")
videoList.add(Video(videoUrl, quality, videoUrl))
videoList.add(
try {
Video(videoUrl, quality, videoUrl, subtitleTracks = subsList)
} catch (e: NoSuchMethodError) {
Video(videoUrl, quality, videoUrl)
}
)
}
return videoList
} else if (test.contains("index.m3u8")) {
return listOf(Video(masterUrl, "Default", masterUrl))
} else if (masterUrl.contains("index.m3u8")) {
return listOf(
try {
Video(masterUrl, "Default", masterUrl, subtitleTracks = subsList)
} catch (e: NoSuchMethodError) {
Video(masterUrl, "Default", masterUrl)
}
)
} else {
throw Exception("never give up and try again :)")
}
Expand Down

0 comments on commit cd26d35

Please sign in to comment.