Skip to content

Commit

Permalink
use videoUrl in WatcherActivity
Browse files Browse the repository at this point in the history
  • Loading branch information
jmir1 committed Jun 29, 2021
1 parent 267b68b commit 9b67f11
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package eu.kanade.tachiyomi.data.download

import android.content.Context
import android.util.Log
import android.webkit.MimeTypeMap
import com.hippo.unifile.UniFile
import com.jakewharton.rxrelay.BehaviorRelay
Expand Down Expand Up @@ -264,7 +263,6 @@ class AnimeDownloader(

// Start downloader if needed
if (autoStart && wasEmpty) {
Log.w("start", "started")
AnimeDownloadService.start(this@AnimeDownloader.context)
}
}
Expand Down
19 changes: 17 additions & 2 deletions app/src/main/java/eu/kanade/tachiyomi/ui/watcher/EpisodeLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import eu.kanade.tachiyomi.animesource.AnimeSource
import eu.kanade.tachiyomi.animesource.LocalAnimeSource
import eu.kanade.tachiyomi.animesource.model.Video
import eu.kanade.tachiyomi.animesource.online.AnimeHttpSource
import eu.kanade.tachiyomi.animesource.online.fetchUrlFromVideo
import eu.kanade.tachiyomi.data.database.models.Anime
import eu.kanade.tachiyomi.data.database.models.Episode
import eu.kanade.tachiyomi.data.download.AnimeDownloadManager
import eu.kanade.tachiyomi.util.lang.awaitSingle
import kotlinx.coroutines.runBlocking
import rx.Observable
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
Expand All @@ -27,6 +30,12 @@ class EpisodeLoader {
return local(episode, source) ?: Observable.just(emptyList())
}
else -> error("source not supported")
}.flatMap {
if (source is AnimeHttpSource) {
Observable.just(it)
} else {
Observable.just(it)
}
}
}

Expand All @@ -46,9 +55,15 @@ class EpisodeLoader {
}
}

fun notDownloaded(episode: Episode, source: AnimeSource): Observable<List<Video>>? {
fun notDownloaded(episode: Episode, source: AnimeHttpSource): Observable<List<Video>>? {
return try {
source.fetchVideoList(episode)
source.fetchVideoList(episode).map { list ->
val newList = mutableListOf<Video>()
for (it in list) {
newList.add(runBlocking { source.fetchUrlFromVideo(it).awaitSingle() })
}
newList
}
} catch (error: Exception) {
null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class WatcherActivity : AppCompatActivity() {
super.onBackPressed()
}
if (videos.lastIndex > 0) settingsBtn.visibility = View.VISIBLE
uri = videos.first().url
uri = videos.first().videoUrl!!
dataSourceFactory = if (EpisodeLoader.isDownloaded(episode, anime) || source is LocalAnimeSource) {
DefaultDataSourceFactory(this)
} else {
Expand Down Expand Up @@ -237,7 +237,7 @@ class WatcherActivity : AppCompatActivity() {
title.text = baseContext.getString(R.string.playertitle, anime.title, episode.name)
videos = runBlocking { awaitVideoList() }
settingsBtn.visibility = if (videos.lastIndex > 0) View.VISIBLE else View.GONE
uri = videos.first().url
uri = videos.first().videoUrl!!
currentQuality = 0
mediaItem = MediaItem.Builder()
.setUri(uri)
Expand All @@ -255,7 +255,7 @@ class WatcherActivity : AppCompatActivity() {
title.text = baseContext.getString(R.string.playertitle, anime.title, episode.name)
videos = runBlocking { awaitVideoList() }
settingsBtn.visibility = if (videos.lastIndex > 0) View.VISIBLE else View.GONE
uri = videos.first().url
uri = videos.first().videoUrl!!
currentQuality = 0
mediaItem = MediaItem.Builder()
.setUri(uri)
Expand All @@ -267,7 +267,7 @@ class WatcherActivity : AppCompatActivity() {
private fun settings() {
val nextQuality = if (currentQuality == videos.lastIndex) 0 else currentQuality + 1
baseContext.toast(videos[nextQuality].quality, Toast.LENGTH_SHORT)
uri = videos[nextQuality].url
uri = videos[nextQuality].videoUrl!!
currentQuality = nextQuality
mediaItem = MediaItem.Builder()
.setUri(uri)
Expand Down

0 comments on commit 9b67f11

Please sign in to comment.