bump library, fix http and download support

This commit is contained in:
jmir1 2022-01-13 01:29:43 +01:00
parent ddd0cfd226
commit d711dbb488
5 changed files with 98 additions and 12 deletions

View file

@ -312,7 +312,7 @@ dependencies {
implementation("com.arthenica:ffmpeg-kit-https:4.5.LTS")
// mpv-android
implementation("com.github.jmir1:aniyomi-mpv-lib:0.1")
implementation("com.github.jmir1:aniyomi-mpv-lib:0.2")
}
tasks {

View file

@ -193,7 +193,7 @@ class AnimeDownloadManager(
}
val file = files[0]
Video(file.uri.toString(), file.uri.toString(), "download", file.uri).apply { status = Video.READY }
Video(file.uri.toString(), "download: " + file.uri.toString(), file.uri.toString(), file.uri).apply { status = Video.READY }
}
}

View file

@ -10,8 +10,6 @@ import android.view.WindowManager
import android.widget.SeekBar
import androidx.annotation.RequiresApi
import androidx.core.content.ContextCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.animesource.model.Video
import eu.kanade.tachiyomi.data.database.models.Anime
@ -48,7 +46,7 @@ class NewPlayerActivity : BaseRxActivity<NewPlayerActivityBinding, NewPlayerPres
private var userIsOperatingSeekbar = false
private var lockedUI = false
// private var lockedUI = false
private val seekBarChangeListener = object : SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
@ -68,8 +66,6 @@ class NewPlayerActivity : BaseRxActivity<NewPlayerActivityBinding, NewPlayerPres
}
}
private val windowInsetsController by lazy { WindowInsetsControllerCompat(window, binding.root) }
private var currentVideoList: List<Video>? = null
@RequiresApi(Build.VERSION_CODES.P)
@ -81,16 +77,16 @@ class NewPlayerActivity : BaseRxActivity<NewPlayerActivityBinding, NewPlayerPres
binding = NewPlayerActivityBinding.inflate(layoutInflater)
setContentView(binding.root)
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
windowInsetsController.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
window.attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
setVisibilities()
player.initialize(applicationContext.filesDir.path)
player.addObserver(this)
binding.playbackSeekbar.setOnSeekBarChangeListener(seekBarChangeListener)
// player.playFile(currentVideoList!!.first().videoUrl!!.toString())
binding.nextBtn.setOnClickListener { presenter.nextEpisode() }
binding.prevBtn.setOnClickListener { presenter.previousEpisode() }
if (presenter?.needsInit() == true) {
val anime = intent.extras!!.getLong("anime", -1)
val episode = intent.extras!!.getLong("episode", -1)
@ -100,8 +96,21 @@ class NewPlayerActivity : BaseRxActivity<NewPlayerActivityBinding, NewPlayerPres
}
presenter.init(anime, episode)
}
}
binding.nextBtn.setOnClickListener { refreshUi() }
@Suppress("DEPRECATION")
private fun setVisibilities() {
// TODO: replace this atrocity
binding.root.systemUiVisibility =
View.SYSTEM_UI_FLAG_LOW_PROFILE or
View.SYSTEM_UI_FLAG_FULLSCREEN or
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
window.attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
}
}
fun updatePlaybackPos(position: Int) {
@ -239,6 +248,14 @@ class NewPlayerActivity : BaseRxActivity<NewPlayerActivityBinding, NewPlayerPres
// presenter.currentEpisode?.last_second_seen?.let { pos -> player.timePos = (pos / 1000L).toInt() }
}
refreshUi()
updatePlaylistButtons()
}
fun setHttpHeaders(headers: Map<String, String>) {
val httpHeaderString = headers.map {
it.key + ": " + it.value
}.joinToString(",")
MPVLib.setOptionString("http-header-fields", httpHeaderString)
}
private fun prettyTime(d: Int, sign: Boolean = false): String {

View file

@ -1,8 +1,10 @@
package eu.kanade.tachiyomi.ui.player
import android.os.Bundle
import android.webkit.WebSettings
import eu.kanade.tachiyomi.animesource.AnimeSourceManager
import eu.kanade.tachiyomi.animesource.model.Video
import eu.kanade.tachiyomi.animesource.online.AnimeHttpSource
import eu.kanade.tachiyomi.data.cache.AnimeCoverCache
import eu.kanade.tachiyomi.data.database.AnimeDatabaseHelper
import eu.kanade.tachiyomi.data.database.models.Anime
@ -175,6 +177,71 @@ class NewPlayerPresenter(
val source = sourceManager.getOrStub(anime.source)
currentEpisode = episodeList.first { initialEpisodeId == it.id }
launchIO {
try {
val currentEpisode = currentEpisode ?: throw Exception("bruh")
EpisodeLoader.getLinks(currentEpisode, anime, source)
.subscribeFirst(
{ activity, it ->
currentVideoList = it
if (source is AnimeHttpSource) {
activity.setHttpHeaders(getHeaders(it, source, activity))
}
activity.setVideoList(it)
},
NewPlayerActivity::setInitialEpisodeError
)
} catch (e: Exception) {
logcat(LogPriority.ERROR, e) { e.message ?: "error getting links" }
}
}
}
private fun getHeaders(videos: List<Video>, source: AnimeHttpSource, activity: NewPlayerActivity): Map<String, String> {
val currentHeaders = videos.firstOrNull()?.headers
val headers = currentHeaders?.toMultimap()
?.mapValues { it.value.getOrNull(0) ?: "" }
?.toMutableMap()
?: source.headers.toMultimap()
.mapValues { it.value.getOrNull(0) ?: "" }
.toMutableMap()
if (headers["user-agent"] == null) {
headers["user-agent"] = WebSettings.getDefaultUserAgent(activity)
}
return headers
}
fun nextEpisode() {
val anime = anime ?: return
val source = sourceManager.getOrStub(anime.source)
val index = getCurrentEpisodeIndex()
if (index == episodeList.lastIndex) return
currentEpisode = episodeList[index + 1]
launchIO {
try {
val currentEpisode = currentEpisode ?: throw Exception("bruh")
EpisodeLoader.getLinks(currentEpisode, anime, source)
.subscribeFirst(
{ activity, it ->
currentVideoList = it
activity.setVideoList(it)
},
NewPlayerActivity::setInitialEpisodeError
)
} catch (e: Exception) {
logcat(LogPriority.ERROR, e) { e.message ?: "error getting links" }
}
}
}
fun previousEpisode() {
val anime = anime ?: return
val source = sourceManager.getOrStub(anime.source)
val index = getCurrentEpisodeIndex()
if (index == 0) return
currentEpisode = episodeList[index - 1]
launchIO {
try {
val currentEpisode = currentEpisode ?: throw Exception("bruh")

View file

@ -74,6 +74,7 @@
android:id="@+id/prevBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:background="#00000000"
android:src="@drawable/ic_skip_previous_black_24dp"
app:tint="@color/tint_normal" />
@ -106,6 +107,7 @@
android:id="@+id/nextBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="5dp"
android:background="#00000000"
android:src="@drawable/ic_skip_next_black_24dp"
app:tint="@color/tint_normal" />