Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
LuftVerbot committed Oct 14, 2023
1 parent 834f1fa commit 277d0f9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class PlaylistUtils(private val client: OkHttpClient, private val headers: Heade
fun extractFromHls(
playlistUrl: String,
referer: String = "",
baseOnOff: Boolean = true,
masterHeaders: Headers,
videoHeaders: Headers,
videoNameGen: (String) -> String = { quality -> quality },
Expand All @@ -40,7 +39,6 @@ class PlaylistUtils(private val client: OkHttpClient, private val headers: Heade
return extractFromHls(
playlistUrl,
referer,
baseOnOff,
{ _, _ -> masterHeaders },
{ _, _, _ -> videoHeaders },
videoNameGen,
Expand Down Expand Up @@ -73,7 +71,6 @@ class PlaylistUtils(private val client: OkHttpClient, private val headers: Heade
fun extractFromHls(
playlistUrl: String,
referer: String = "",
baseOnOff: Boolean = true,
masterHeadersGen: (Headers, String) -> Headers = { baseHeaders, referer ->
generateMasterHeaders(baseHeaders, referer)
},
Expand All @@ -100,26 +97,25 @@ class PlaylistUtils(private val client: OkHttpClient, private val headers: Heade

val playlistHttpUrl = playlistUrl.toHttpUrl()

val masterBase = if(baseOnOff) {
playlistHttpUrl.newBuilder().apply {
removePathSegment(playlistHttpUrl.pathSize - 1)
}.build().toString() + "/"
} else {
playlistUrl
}
val masterUrlBasePath = playlistHttpUrl.newBuilder().apply {
removePathSegment(playlistHttpUrl.pathSize - 1)
addPathSegment("")
query(null)
fragment(null)
}.build().toString()

// Get subtitles
val subtitleTracks = subtitleList + SUBTITLE_REGEX.findAll(masterPlaylist).mapNotNull {
Track(
getAbsoluteUrl(it.groupValues[2], playlistUrl, masterBase) ?: return@mapNotNull null,
getAbsoluteUrl(it.groupValues[2], playlistUrl, masterUrlBasePath ) ?: return@mapNotNull null,
it.groupValues[1]
)
}.toList()

// Get audio tracks
val audioTracks = audioList + AUDIO_REGEX.findAll(masterPlaylist).mapNotNull {
Track(
getAbsoluteUrl(it.groupValues[2], playlistUrl, masterBase) ?: return@mapNotNull null,
getAbsoluteUrl(it.groupValues[2], playlistUrl, masterUrlBasePath ) ?: return@mapNotNull null,
it.groupValues[1]
)
}.toList()
Expand All @@ -131,7 +127,7 @@ class PlaylistUtils(private val client: OkHttpClient, private val headers: Heade
.substringBefore(",") + "p"

val videoUrl = it.substringAfter("\n").substringBefore("\n").let { url ->
getAbsoluteUrl(url, playlistUrl, masterBase)
getAbsoluteUrl(url, playlistUrl, masterUrlBasePath )
} ?: return@mapNotNull null


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import eu.kanade.tachiyomi.util.asJsoup
import okhttp3.Headers
import okhttp3.OkHttpClient

class StreamWishExtractor(private val client: OkHttpClient, private val headers: Headers, private val baseOnOff: Boolean = true) {
class StreamWishExtractor(private val client: OkHttpClient, private val headers: Headers) {
private val playlistUtils by lazy { PlaylistUtils(client, headers) }

fun videosFromUrl(url: String, prefix: String) = videosFromUrl(url) { "$prefix - $it" }
Expand All @@ -31,6 +31,6 @@ class StreamWishExtractor(private val client: OkHttpClient, private val headers:
?.takeIf(String::isNotBlank)
?: return emptyList()

return playlistUtils.extractFromHls(masterUrl, url, videoNameGen = videoNameGen, baseOnOff = baseOnOff)
return playlistUtils.extractFromHls(masterUrl, url, videoNameGen = videoNameGen)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class MoflixStream : ConfigurableAnimeSource, AnimeHttpSource() {
videoList.addAll(videos)
}
host.contains("Filelions") && hosterSelection?.contains("flions") == true -> {
val videos = StreamWishExtractor(client, headers, baseOnOff = false).videosFromUrl(eUrl, videoNameGen = { quality -> "FileLions - $quality" })
val videos = StreamWishExtractor(client, headers).videosFromUrl(eUrl, videoNameGen = { quality -> "FileLions - $quality" })
videoList.addAll(videos)
}
host.contains("LuluStream") && hosterSelection?.contains("lstream") == true -> {
Expand Down Expand Up @@ -235,7 +235,7 @@ class MoflixStream : ConfigurableAnimeSource, AnimeHttpSource() {
videoList.addAll(videos)
}
host.contains("Filelions") && hosterSelection?.contains("flions") == true -> {
val videos = StreamWishExtractor(client, headers, baseOnOff = false).videosFromUrl(fUrl, videoNameGen = { quality -> "FileLions - $quality" })
val videos = StreamWishExtractor(client, headers).videosFromUrl(fUrl, videoNameGen = { quality -> "FileLions - $quality" })
videoList.addAll(videos)
}
host.contains("VidGuard") && hosterSelection?.contains("vidg") == true -> {
Expand Down

0 comments on commit 277d0f9

Please sign in to comment.