Yokan / rebuild
Course 1 8624561

Video.kt

vendor/yokan-ext/src/androidMain/kotlin/eu/kanade/tachiyomi/animesource/model/Video.kt

implementation117 lines
1package eu.kanade.tachiyomi.animesource.model23import android.net.Uri4import eu.kanade.tachiyomi.network.ProgressListener5import okhttp3.Headers6import rx.subjects.Subject78data class Track(9    val url: String,10    val lang: String,11)1213open class Video(14    val url: String = "",15    val quality: String = "",16    var videoUrl: String? = null,17    val headers: Headers? = null,18    // "url", "language-label-2", "url2", "language-label-2"19    val subtitleTracks: List<Track> = emptyList(),20    val audioTracks: List<Track> = emptyList(),21) : ProgressListener {22    @Suppress("UNUSED_PARAMETER")23    constructor(24        url: String,25        quality: String,26        videoUrl: String?,27        uri: Uri? = null,28        headers: Headers? = null,29    ) : this(url, quality, videoUrl, headers)3031    @Transient32    @Volatile33    var status: Int = 034        set(value) {35            field = value36            statusSubject?.onNext(value)37            statusCallback?.invoke(this)38        }3940    @Transient41    @Volatile42    var progress: Int = 043        set(value) {44            progressSubject?.onNext(value)45            field = value46            statusCallback?.invoke(this)47        }4849    @Transient50    @Volatile51    var totalBytesDownloaded: Long = 0L5253    @Transient54    @Volatile55    var totalContentLength: Long = 0L5657    @Transient58    @Volatile59    var bytesDownloaded: Long = 0L60        set(value) {61            totalBytesDownloaded +=62                if (value < field) {63                    value64                } else {65                    value - field66                }67            field = value68            statusCallback?.invoke(this)69        }7071    @Transient72    private var statusSubject: Subject<Int, Int>? = null7374    @Transient75    private var progressSubject: Subject<Int, Int>? = null7677    @Transient78    private var statusCallback: ((Video) -> Unit)? = null7980    override fun update(81        bytesRead: Long,82        contentLength: Long,83        done: Boolean,84    ) {85        bytesDownloaded = bytesRead86        if (contentLength > totalContentLength) {87            totalContentLength = contentLength88        }89        val newProgress =90            if (totalContentLength > 0) {91                (100 * totalBytesDownloaded / totalContentLength).toInt()92            } else {93                -194            }95        if (progress != newProgress) progress = newProgress96    }9798    fun setStatusSubject(subject: Subject<Int, Int>?) {99        this.statusSubject = subject100    }101102    fun setProgressSubject(subject: Subject<Int, Int>?) {103        this.progressSubject = subject104    }105106    fun setStatusCallback(f: ((Video) -> Unit)?) {107        statusCallback = f108    }109110    companion object {111        const val QUEUE = 0112        const val LOAD_VIDEO = 1113        const val DOWNLOAD_IMAGE = 2114        const val READY = 3115        const val ERROR = 4116    }117}118

Search chapters, reference and source filenames.