Skip to content

Commit

Permalink
fix(it/animeunity): Fix video streams URLs (Kohi-den#621)
Browse files Browse the repository at this point in the history
* Fix AnimeUnity video streams URLs

The video streams URLs have been moved from JS to a single m3u8 file, this commit adapts to the change. The subtitles seem to have disappeared entirely, so I've left them commented.

* Update Years filter

* Bump AnimeUnity extVersionCode
  • Loading branch information
PGgamer2 authored Feb 5, 2025
1 parent 16b2eae commit ba2ba44
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/it/animeunity/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {
extName = 'AnimeUnity'
extClass = '.AnimeUnity'
extVersionCode = 8
extVersionCode = 9
}

apply from: "$rootDir/common.gradle"
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import eu.kanade.tachiyomi.animesource.model.AnimeFilterList
import eu.kanade.tachiyomi.animesource.model.AnimesPage
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.AnimeHttpSource
import eu.kanade.tachiyomi.network.GET
Expand Down Expand Up @@ -38,7 +37,7 @@ class AnimeUnity :

// TODO: Check frequency of url changes to potentially
// add back overridable baseurl preference
override val baseUrl = "https://www.animeunity.to"
override val baseUrl = "https://www.animeunity.so"

override val lang = "it"

Expand Down Expand Up @@ -366,42 +365,42 @@ class AnimeUnity :
.asJsoup()
val scripts = iframe.select("script")
val script = scripts.find { it.data().contains("masterPlaylist") }!!.data().replace("\n", "\t")
var playlistUrl = Regex("""url: ?'(.*?)'""").find(script)!!.groupValues[1]
val filename = playlistUrl.slice(playlistUrl.lastIndexOf("/") + 1 until playlistUrl.length)
if (!filename.endsWith(".m3u8")) {
playlistUrl = playlistUrl.replace(filename, filename + ".m3u8")
}
val playlistUrl = Regex("""url: ?'(.*?)'""").find(script)!!.groupValues[1]

val expires = Regex("""'expires': ?'(\d+)'""").find(script)!!.groupValues[1]
val token = Regex("""'token': ?'([\w-]+)'""").find(script)!!.groupValues[1]
// Get subtitles
val masterPlUrl = "$playlistUrl?token=$token&expires=$expires&n=1"

val masterPlUrl = buildString {
append(playlistUrl)
append(if (playlistUrl.contains('?')) '&' else '?')
append("h=1&token=")
append(token)
append("&expires=")
append(expires)
}
val masterPl =
client
.newCall(GET(masterPlUrl))
.execute()
.body
.string()
val subList =

// Subtitles are nowhere to be seen... I'm leaving this regex for future reference
/*val subList =
Regex("""#EXT-X-MEDIA:TYPE=SUBTITLES.*?NAME="(.*?)".*?URI="(.*?)"""")
.findAll(masterPl)
.map {
Track(it.groupValues[2], it.groupValues[1])
}.toList()
Regex("""'token(\d+p?)': ?'([\w-]+)'""").findAll(script).forEach { match ->
val quality = match.groupValues[1]
}.toList()*/

val videoUrl =
buildString {
append(playlistUrl)
append("?type=video&rendition=")
append(quality)
append("&token=")
append(match.groupValues[2])
append("&expires=$expires")
append("&n=1")
}
videoList.add(Video(videoUrl, quality, videoUrl, subtitleTracks = subList))
Regex("""https?://vixcloud\.co/playlist/(.+)\?.*type=video&.*rendition=(\d+p?).*""").findAll(masterPl).forEach { match ->
var videoUrl = match.groupValues[0]
val filename = match.groupValues[1]
if (!filename.endsWith(".m3u8")) {
videoUrl = videoUrl.replace(filename, "$filename.m3u8")
}
val quality = match.groupValues[2]
videoList.add(Video(videoUrl, quality, videoUrl))
}

require(videoList.isNotEmpty()) { "Failed to fetch videos" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ object AnimeUnityFilters {
Pair("", "true"),
)

val YEAR = arrayOf(ANY) + (1969..2024).map {
val YEAR = arrayOf(ANY) + (1969..2025).map {
Pair(it.toString(), it.toString())
}.reversed().toTypedArray()
}
Expand Down

0 comments on commit ba2ba44

Please sign in to comment.