Skip to content

Commit

Permalink
feat(EpisodeLoader): add some functions for backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Secozzi committed Jan 24, 2025
1 parent ea7ccc0 commit c4451ca
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class EpisodeLoader {
*/
suspend fun getVideos(source: AnimeSource, hoster: Hoster): List<Video> {
return when {
hoster.videoList != null && source is AnimeHttpSource -> hoster.videoList!!.parseVideoUrls(source)
hoster.videoList != null -> hoster.videoList!!
source is AnimeHttpSource -> getVideosOnHttp(source, hoster)
else -> error("source not supported")
Expand All @@ -142,7 +143,17 @@ class EpisodeLoader {
* @param hoster the hoster.
*/
private suspend fun getVideosOnHttp(source: AnimeHttpSource, hoster: Hoster): List<Video> {
return source.getVideoList(hoster)
return source.getVideoList(hoster).parseVideoUrls(source)
}

// TODO(1.6): Remove after ext lib bump
private suspend fun List<Video>.parseVideoUrls(source: AnimeHttpSource): List<Video> {
return this.map { video ->
if (video.videoUrl != "null") return@map video

val newVideoUrl = source.getVideoUrl(video)
video.copy(videoUrl = newVideoUrl)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ open class Video(
) : this(
videoPageUrl = url,
videoTitle = quality,
videoUrl = videoUrl ?: "",
videoUrl = videoUrl ?: "null",
headers = headers,
subtitleTracks = subtitleTracks,
audioTracks = audioTracks,
Expand Down

0 comments on commit c4451ca

Please sign in to comment.