mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
removed shit
This commit is contained in:
parent
989d7666be
commit
d841c1aa7f
3 changed files with 17 additions and 224 deletions
|
@ -130,7 +130,7 @@ dependencies {
|
||||||
implementation 'org.mozilla:rhino:1.7R4'
|
implementation 'org.mozilla:rhino:1.7R4'
|
||||||
|
|
||||||
// TorrentStream
|
// TorrentStream
|
||||||
implementation 'com.github.TorrentStream:TorrentStream-Android:2.7.0'
|
//implementation 'com.github.TorrentStream:TorrentStream-Android:2.7.0'
|
||||||
|
|
||||||
// Downloading
|
// Downloading
|
||||||
implementation "androidx.work:work-runtime:2.7.0-beta01"
|
implementation "androidx.work:work-runtime:2.7.0-beta01"
|
||||||
|
|
|
@ -44,11 +44,6 @@ import com.fasterxml.jackson.databind.DeserializationFeature
|
||||||
import com.fasterxml.jackson.databind.json.JsonMapper
|
import com.fasterxml.jackson.databind.json.JsonMapper
|
||||||
import com.fasterxml.jackson.module.kotlin.KotlinModule
|
import com.fasterxml.jackson.module.kotlin.KotlinModule
|
||||||
import com.fasterxml.jackson.module.kotlin.readValue
|
import com.fasterxml.jackson.module.kotlin.readValue
|
||||||
import com.github.se_bastiaan.torrentstream.StreamStatus
|
|
||||||
import com.github.se_bastiaan.torrentstream.Torrent
|
|
||||||
import com.github.se_bastiaan.torrentstream.TorrentOptions
|
|
||||||
import com.github.se_bastiaan.torrentstream.TorrentStream
|
|
||||||
import com.github.se_bastiaan.torrentstream.listeners.TorrentListener
|
|
||||||
import com.google.android.exoplayer2.*
|
import com.google.android.exoplayer2.*
|
||||||
import com.google.android.exoplayer2.C.TIME_UNSET
|
import com.google.android.exoplayer2.C.TIME_UNSET
|
||||||
import com.google.android.exoplayer2.database.ExoDatabaseProvider
|
import com.google.android.exoplayer2.database.ExoDatabaseProvider
|
||||||
|
@ -172,12 +167,12 @@ data class UriData(
|
||||||
class PlayerFragment : Fragment() {
|
class PlayerFragment : Fragment() {
|
||||||
|
|
||||||
// ============ TORRENT ============
|
// ============ TORRENT ============
|
||||||
private var torrentStream: TorrentStream? = null
|
//private var torrentStream: TorrentStream? = null
|
||||||
private var lastTorrentUrl = ""
|
private var lastTorrentUrl = ""
|
||||||
private val isTorrent: Boolean get() = torrentStream != null
|
//private val isTorrent: Boolean get() = torrentStream != null
|
||||||
private fun initTorrentStream(torrentUrl: String) {
|
private fun initTorrentStream(torrentUrl: String) {
|
||||||
if (lastTorrentUrl == torrentUrl) return
|
if (lastTorrentUrl == torrentUrl) return
|
||||||
lastTorrentUrl = torrentUrl
|
/*lastTorrentUrl = torrentUrl
|
||||||
torrentStream?.stopStream()
|
torrentStream?.stopStream()
|
||||||
torrentStream = null
|
torrentStream = null
|
||||||
|
|
||||||
|
@ -232,7 +227,7 @@ class PlayerFragment : Fragment() {
|
||||||
println("stream stopped")
|
println("stream stopped")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
// =================================
|
// =================================
|
||||||
|
@ -404,7 +399,7 @@ class PlayerFragment : Fragment() {
|
||||||
bottom_player_bar?.startAnimation(fadeAnimation)
|
bottom_player_bar?.startAnimation(fadeAnimation)
|
||||||
player_top_holder?.startAnimation(fadeAnimation)
|
player_top_holder?.startAnimation(fadeAnimation)
|
||||||
// video_holder?.startAnimation(fadeAnimation)
|
// video_holder?.startAnimation(fadeAnimation)
|
||||||
player_torrent_info?.isVisible = (isTorrent && isShowing)
|
//player_torrent_info?.isVisible = (isTorrent && isShowing)
|
||||||
// player_torrent_info?.startAnimation(fadeAnimation)
|
// player_torrent_info?.startAnimation(fadeAnimation)
|
||||||
//video_lock_holder?.startAnimation(fadeAnimation)
|
//video_lock_holder?.startAnimation(fadeAnimation)
|
||||||
}
|
}
|
||||||
|
@ -1629,7 +1624,7 @@ class PlayerFragment : Fragment() {
|
||||||
activity?.window?.attributes = params
|
activity?.window?.attributes = params
|
||||||
}
|
}
|
||||||
|
|
||||||
torrentStream?.currentTorrent?.resume()
|
//torrentStream?.currentTorrent?.resume()
|
||||||
onAudioFocusEvent += ::handlePauseEvent
|
onAudioFocusEvent += ::handlePauseEvent
|
||||||
|
|
||||||
activity?.hideSystemUI()
|
activity?.hideSystemUI()
|
||||||
|
@ -1667,8 +1662,8 @@ class PlayerFragment : Fragment() {
|
||||||
savePos()
|
savePos()
|
||||||
SubtitlesFragment.applyStyleEvent -= ::onSubStyleChanged
|
SubtitlesFragment.applyStyleEvent -= ::onSubStyleChanged
|
||||||
|
|
||||||
torrentStream?.stopStream()
|
// torrentStream?.stopStream()
|
||||||
torrentStream = null
|
// torrentStream = null
|
||||||
|
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
canEnterPipMode = false
|
canEnterPipMode = false
|
||||||
|
@ -1685,7 +1680,7 @@ class PlayerFragment : Fragment() {
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
savePos()
|
savePos()
|
||||||
super.onPause()
|
super.onPause()
|
||||||
torrentStream?.currentTorrent?.pause()
|
// torrentStream?.currentTorrent?.pause()
|
||||||
if (Util.SDK_INT <= 23) {
|
if (Util.SDK_INT <= 23) {
|
||||||
if (player_view != null) player_view.onPause()
|
if (player_view != null) player_view.onPause()
|
||||||
releasePlayer()
|
releasePlayer()
|
||||||
|
@ -1928,10 +1923,10 @@ class PlayerFragment : Fragment() {
|
||||||
var epSeason: Int? = null
|
var epSeason: Int? = null
|
||||||
var isEpisodeBased = true
|
var isEpisodeBased = true
|
||||||
|
|
||||||
if (isTorrent) {
|
/*if (isTorrent) {
|
||||||
hName = "Torrent Stream"
|
hName = "Torrent Stream"
|
||||||
isEpisodeBased = false
|
isEpisodeBased = false
|
||||||
} else if (isDownloadedFile) {
|
} else*/ if (isDownloadedFile) {
|
||||||
hName = uriData.name
|
hName = uriData.name
|
||||||
epEpisode = uriData.episode
|
epEpisode = uriData.episode
|
||||||
epSeason = uriData.season
|
epSeason = uriData.season
|
||||||
|
@ -1992,11 +1987,12 @@ class PlayerFragment : Fragment() {
|
||||||
video_title_rez?.text =
|
video_title_rez?.text =
|
||||||
if (height == null || width == null) currentUrl?.name
|
if (height == null || width == null) currentUrl?.name
|
||||||
?: "" else
|
?: "" else
|
||||||
if (isTorrent) "${width}x${height}" else
|
// if (isTorrent) "${width}x${height}" else
|
||||||
if (isDownloadedFile || currentUrl?.name == null) "${width}x${height}" else "${currentUrl.name} - ${width}x${height}"
|
if (isDownloadedFile || currentUrl?.name == null) "${width}x${height}" else "${currentUrl.name} - ${width}x${height}"
|
||||||
|
|
||||||
if (!hasUsedFirstRender) { // DON'T WANT TO SET MULTIPLE MESSAGES
|
if (!hasUsedFirstRender) { // DON'T WANT TO SET MULTIPLE MESSAGES
|
||||||
if (!isDownloadedFile && !isTorrent && exoPlayer.duration in 5_000..10_000) {
|
//&& !isTorrent
|
||||||
|
if (!isDownloadedFile && exoPlayer.duration in 5_000..10_000) {
|
||||||
// if(getapi apiName )
|
// if(getapi apiName )
|
||||||
showToast(activity, R.string.vpn_might_be_needed, LENGTH_SHORT)
|
showToast(activity, R.string.vpn_might_be_needed, LENGTH_SHORT)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package com.lagradost.cloudstream3.utils
|
package com.lagradost.cloudstream3.utils
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.app.Notification
|
||||||
import android.app.*
|
|
||||||
import android.app.Activity
|
|
||||||
import android.app.NotificationChannel
|
import android.app.NotificationChannel
|
||||||
import android.app.NotificationManager
|
import android.app.NotificationManager
|
||||||
import android.app.PendingIntent
|
import android.app.PendingIntent
|
||||||
|
@ -12,7 +10,6 @@ import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import android.widget.Toast
|
|
||||||
import androidx.annotation.DrawableRes
|
import androidx.annotation.DrawableRes
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
|
@ -24,14 +21,7 @@ import androidx.work.OneTimeWorkRequest
|
||||||
import androidx.work.WorkManager
|
import androidx.work.WorkManager
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty
|
import com.fasterxml.jackson.annotation.JsonProperty
|
||||||
import com.github.se_bastiaan.torrentstream.StreamStatus
|
|
||||||
import com.github.se_bastiaan.torrentstream.Torrent
|
|
||||||
import com.github.se_bastiaan.torrentstream.TorrentOptions
|
|
||||||
import com.github.se_bastiaan.torrentstream.TorrentStream
|
|
||||||
import com.github.se_bastiaan.torrentstream.listeners.TorrentListener
|
|
||||||
import com.lagradost.cloudstream3.AnimeLoadResponse
|
|
||||||
import com.lagradost.cloudstream3.MainActivity
|
import com.lagradost.cloudstream3.MainActivity
|
||||||
import com.lagradost.cloudstream3.MainActivity.Companion.showToast
|
|
||||||
import com.lagradost.cloudstream3.R
|
import com.lagradost.cloudstream3.R
|
||||||
import com.lagradost.cloudstream3.mvvm.logError
|
import com.lagradost.cloudstream3.mvvm.logError
|
||||||
import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
|
import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
|
||||||
|
@ -517,22 +507,6 @@ object VideoDownloadManager {
|
||||||
val bytesTotal: Long,
|
val bytesTotal: Long,
|
||||||
)
|
)
|
||||||
|
|
||||||
fun getSizeAndProgressFromTorrent(torrent: Torrent?, progress: Float?): Pair<Long, Long>? {
|
|
||||||
try {
|
|
||||||
if (torrent == null || progress == null) return null
|
|
||||||
val length = torrent.videoFile?.length() ?: 0
|
|
||||||
if (length > 0) {
|
|
||||||
// val bytesTotal = (length * 100 / progress).toLong()
|
|
||||||
// if (bytesTotal > 0 && length > 0) {
|
|
||||||
return Pair((length * progress / 100).toLong(), length)
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
} catch (e: Exception) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data class StreamData(
|
data class StreamData(
|
||||||
val errorCode: Int,
|
val errorCode: Int,
|
||||||
val resume: Boolean? = null,
|
val resume: Boolean? = null,
|
||||||
|
@ -623,173 +597,6 @@ object VideoDownloadManager {
|
||||||
return StreamData(SUCCESS_STREAM, resume, fileLength, fileStream)
|
return StreamData(SUCCESS_STREAM, resume, fileLength, fileStream)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun downloadTorrent(
|
|
||||||
context: Context,
|
|
||||||
link: String,
|
|
||||||
name: String,
|
|
||||||
folder: String?,
|
|
||||||
extension: String,
|
|
||||||
//tryResume: Boolean = false,
|
|
||||||
parentId: Int?,
|
|
||||||
createNotificationCallback: (CreateNotificationMetadata) -> Unit
|
|
||||||
): Int {
|
|
||||||
val stream = setupStream(context, name, folder, extension, false)
|
|
||||||
if (stream.errorCode != SUCCESS_STREAM) return stream.errorCode
|
|
||||||
|
|
||||||
val torrentOptions: TorrentOptions = TorrentOptions.Builder()
|
|
||||||
.saveLocation(context.cacheDir.absolutePath)
|
|
||||||
.removeFilesAfterStop(true)
|
|
||||||
.build()
|
|
||||||
|
|
||||||
val torrentStream = TorrentStream.init(torrentOptions)
|
|
||||||
torrentStream.startStream(link)
|
|
||||||
|
|
||||||
var progress = 0f
|
|
||||||
var isDone = false
|
|
||||||
var isFailed = false
|
|
||||||
|
|
||||||
torrentStream.addListener(object : TorrentListener {
|
|
||||||
override fun onStreamPrepared(torrent: Torrent?) {
|
|
||||||
|
|
||||||
//showToast(context, "Stream Prepared", Toast.LENGTH_SHORT)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onStreamStarted(torrent: Torrent?) {
|
|
||||||
// showToast(context, "Stream Started", Toast.LENGTH_SHORT)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onStreamError(torrent: Torrent?, e: java.lang.Exception?) {
|
|
||||||
isFailed = true
|
|
||||||
e?.printStackTrace()
|
|
||||||
// showToast(context, e?.localizedMessage ?: "Error loading", Toast.LENGTH_SHORT)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onStreamReady(torrent: Torrent?) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("SetTextI18n")
|
|
||||||
override fun onStreamProgress(torrent: Torrent?, status: StreamStatus?) {
|
|
||||||
try {
|
|
||||||
println("Seeders ${status?.seeds}")
|
|
||||||
println("Download Speed ${status?.downloadSpeed}")
|
|
||||||
println("Progress ${status?.progress}%")
|
|
||||||
|
|
||||||
val lengthSize = getSizeAndProgressFromTorrent(torrent, status?.progress)
|
|
||||||
if (lengthSize != null) {
|
|
||||||
progress = status?.progress!!
|
|
||||||
val type = if (progress >= 100f) DownloadType.IsDone else DownloadType.IsDownloading
|
|
||||||
parentId?.let { id ->
|
|
||||||
try {
|
|
||||||
downloadStatus[id] = type
|
|
||||||
downloadStatusEvent.invoke(Pair(id, type))
|
|
||||||
downloadProgressEvent.invoke(Triple(id, lengthSize.first, lengthSize.second))
|
|
||||||
} catch (e: Exception) {
|
|
||||||
// IDK MIGHT ERROR
|
|
||||||
}
|
|
||||||
}
|
|
||||||
createNotificationCallback.invoke(
|
|
||||||
CreateNotificationMetadata(
|
|
||||||
type,
|
|
||||||
lengthSize.first,
|
|
||||||
lengthSize.second
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
val pro = status?.progress
|
|
||||||
if (pro != null && pro >= 100) {
|
|
||||||
isDone = true
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (e: IllegalStateException) {
|
|
||||||
logError(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onStreamStopped() {
|
|
||||||
if (progress > 98) {
|
|
||||||
isDone = true
|
|
||||||
} else {
|
|
||||||
isFailed = true
|
|
||||||
}
|
|
||||||
println("stream stopped")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
fun updateNot(type: DownloadType) {
|
|
||||||
val lengthSize = getSizeAndProgressFromTorrent(torrentStream.currentTorrent, progress) ?: return
|
|
||||||
|
|
||||||
createNotificationCallback.invoke(
|
|
||||||
CreateNotificationMetadata(
|
|
||||||
type,
|
|
||||||
lengthSize.first, lengthSize.second
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
val downloadEventListener = { event: Pair<Int, DownloadActionType> ->
|
|
||||||
if (event.first == parentId) {
|
|
||||||
when (event.second) {
|
|
||||||
DownloadActionType.Pause -> {
|
|
||||||
torrentStream?.currentTorrent?.pause()
|
|
||||||
updateNot(DownloadType.IsPaused)
|
|
||||||
}
|
|
||||||
DownloadActionType.Stop -> {
|
|
||||||
isFailed = true
|
|
||||||
torrentStream.stopStream()
|
|
||||||
torrentStream?.currentTorrent?.videoFile?.delete()
|
|
||||||
updateNot(DownloadType.IsStopped)
|
|
||||||
context.removeKey(KEY_RESUME_PACKAGES, event.first.toString())
|
|
||||||
saveQueue(context)
|
|
||||||
}
|
|
||||||
DownloadActionType.Resume -> {
|
|
||||||
torrentStream?.currentTorrent?.resume()
|
|
||||||
updateNot(DownloadType.IsDownloading)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parentId != null)
|
|
||||||
downloadEvent += downloadEventListener
|
|
||||||
|
|
||||||
var lastProgress = progress
|
|
||||||
var lastUpdateTime = System.currentTimeMillis()
|
|
||||||
while (!isDone && !isFailed) {
|
|
||||||
sleep(100)
|
|
||||||
if (lastProgress != progress) {
|
|
||||||
lastUpdateTime = System.currentTimeMillis()
|
|
||||||
lastProgress = progress
|
|
||||||
}
|
|
||||||
if (progress >= 98f && System.currentTimeMillis() - lastUpdateTime > 10000L) { // after 10 sec set as done
|
|
||||||
isDone = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parentId != null)
|
|
||||||
downloadEvent -= downloadEventListener
|
|
||||||
|
|
||||||
// RETURN MESSAGE
|
|
||||||
return when {
|
|
||||||
isFailed -> {
|
|
||||||
parentId?.let { id -> downloadProgressEvent.invoke(Triple(id, 0, 0)) }
|
|
||||||
SUCCESS_STOPPED
|
|
||||||
}
|
|
||||||
isDone -> {
|
|
||||||
stream.fileStream?.let { fileStream ->
|
|
||||||
torrentStream?.currentTorrent?.videoStream?.copyTo(fileStream)
|
|
||||||
torrentStream?.currentTorrent?.videoFile?.delete()
|
|
||||||
}
|
|
||||||
|
|
||||||
SUCCESS_DOWNLOAD_DONE
|
|
||||||
}
|
|
||||||
else -> {
|
|
||||||
SUCCESS_DOWNLOAD_DONE
|
|
||||||
//idk
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun downloadThing(
|
fun downloadThing(
|
||||||
context: Context,
|
context: Context,
|
||||||
link: IDownloadableMinimum,
|
link: IDownloadableMinimum,
|
||||||
|
@ -801,17 +608,7 @@ object VideoDownloadManager {
|
||||||
createNotificationCallback: (CreateNotificationMetadata) -> Unit
|
createNotificationCallback: (CreateNotificationMetadata) -> Unit
|
||||||
): Int {
|
): Int {
|
||||||
if (link.url.startsWith("magnet") || link.url.endsWith(".torrent")) {
|
if (link.url.startsWith("magnet") || link.url.endsWith(".torrent")) {
|
||||||
return normalSafeApiCall {
|
return ERROR_UNKNOWN
|
||||||
downloadTorrent(
|
|
||||||
context,
|
|
||||||
link.url,
|
|
||||||
name,
|
|
||||||
folder,
|
|
||||||
extension,
|
|
||||||
parentId,
|
|
||||||
createNotificationCallback
|
|
||||||
)
|
|
||||||
} ?: ERROR_UNKNOWN
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val relativePath = getRelativePath(folder)
|
val relativePath = getRelativePath(folder)
|
||||||
|
|
Loading…
Reference in a new issue