fix(lib/voe-extractor): Fix regex (#3183)

This commit is contained in:
imper1aldev 2024-04-26 04:27:34 -06:00 committed by GitHub
parent a4f9576f6b
commit 3bdc3f9e3a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -16,6 +16,10 @@ class VoeExtractor(private val client: OkHttpClient) {
private val playlistUtils by lazy { PlaylistUtils(client) } private val playlistUtils by lazy { PlaylistUtils(client) }
private val linkRegex = "(http|https)://([\\w_-]+(?:\\.[\\w_-]+)+)([\\w.,@?^=%&:/~+#-]*[\\w@?^=%&/~+#-])".toRegex()
private val base64Regex = Regex("'.*'")
@Serializable @Serializable
data class VideoLinkDTO(val file: String) data class VideoLinkDTO(val file: String)
@ -27,11 +31,12 @@ class VoeExtractor(private val client: OkHttpClient) {
val playlistUrl = when { val playlistUrl = when {
// Layout 1 // Layout 1
script.contains("sources") -> { script.contains("sources") -> {
script.substringAfter("hls': '").substringBefore("'") val link = script.substringAfter("hls': '").substringBefore("'")
if (linkRegex.matches(link)) link else String(Base64.decode(link, Base64.DEFAULT))
} }
// Layout 2 // Layout 2
script.contains("wc0") -> { script.contains("wc0") -> {
val base64 = Regex("'.*'").find(script)!!.value val base64 = base64Regex.find(script)!!.value
val decoded = Base64.decode(base64, Base64.DEFAULT).let(::String) val decoded = Base64.decode(base64, Base64.DEFAULT).let(::String)
json.decodeFromString<VideoLinkDTO>(decoded).file json.decodeFromString<VideoLinkDTO>(decoded).file
} }