mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Update VideoDownloadManager.kt
This commit is contained in:
parent
620c11d68f
commit
0b170b5493
1 changed files with 33 additions and 17 deletions
|
@ -1062,6 +1062,7 @@ object VideoDownloadManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
val m3u8Helper = M3u8Helper()
|
val m3u8Helper = M3u8Helper()
|
||||||
|
logcatPrint("initialised the HLS downloader.")
|
||||||
|
|
||||||
val m3u8 = M3u8Helper.M3u8Stream(link.url, when (link.quality) {
|
val m3u8 = M3u8Helper.M3u8Stream(link.url, when (link.quality) {
|
||||||
-2 -> 360
|
-2 -> 360
|
||||||
|
@ -1071,7 +1072,6 @@ object VideoDownloadManager {
|
||||||
else -> null
|
else -> null
|
||||||
}, mapOf("referer" to link.referer))
|
}, mapOf("referer" to link.referer))
|
||||||
val tsIterator = m3u8Helper.hlsYield(listOf(m3u8))
|
val tsIterator = m3u8Helper.hlsYield(listOf(m3u8))
|
||||||
logcatPrint("initialised the HLS downloader.")
|
|
||||||
|
|
||||||
val relativePath = (Environment.DIRECTORY_DOWNLOADS + '/' + folder + '/').replace('/', File.separatorChar)
|
val relativePath = (Environment.DIRECTORY_DOWNLOADS + '/' + folder + '/').replace('/', File.separatorChar)
|
||||||
val displayName = "$name.ts"
|
val displayName = "$name.ts"
|
||||||
|
@ -1186,12 +1186,23 @@ object VideoDownloadManager {
|
||||||
createNotificationCallback.invoke(CreateNotificationMetadata(type, bytesDownloaded, (bytesDownloaded/tsProgress)*totalTs))
|
createNotificationCallback.invoke(CreateNotificationMetadata(type, bytesDownloaded, (bytesDownloaded/tsProgress)*totalTs))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (firstTs.errored) {
|
fun stopIfError(ts: M3u8Helper.HlsDownloadData): Int? {
|
||||||
isFailed = true
|
if (ts.errored || ts.bytes.isEmpty()) {
|
||||||
fileStream.close()
|
val error: Int
|
||||||
deleteFile()
|
error = if (!ts.errored) {
|
||||||
updateNotification()
|
logcatPrint("Error: No stream was found.")
|
||||||
return ERROR_CONNECTION_ERROR
|
ERROR_UNKNOWN
|
||||||
|
} else {
|
||||||
|
logcatPrint("Error: Failed to fetch data.")
|
||||||
|
ERROR_CONNECTION_ERROR
|
||||||
|
}
|
||||||
|
isFailed = true
|
||||||
|
fileStream.close()
|
||||||
|
deleteFile()
|
||||||
|
updateNotification()
|
||||||
|
return error
|
||||||
|
}
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
val notificationCoroutine = main {
|
val notificationCoroutine = main {
|
||||||
|
@ -1237,6 +1248,13 @@ object VideoDownloadManager {
|
||||||
}
|
}
|
||||||
notificationCoroutine.cancel()
|
notificationCoroutine.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stopIfError(firstTs).let {
|
||||||
|
if (it != null) {
|
||||||
|
closeAll()
|
||||||
|
return it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (parentId != null)
|
if (parentId != null)
|
||||||
downloadEvent += downloadEventListener
|
downloadEvent += downloadEventListener
|
||||||
|
@ -1251,19 +1269,17 @@ object VideoDownloadManager {
|
||||||
closeAll()
|
closeAll()
|
||||||
return SUCCESS_STOPPED
|
return SUCCESS_STOPPED
|
||||||
}
|
}
|
||||||
if (ts.errored) {
|
stopIfError(ts).let {
|
||||||
isFailed = true
|
if (it != null) {
|
||||||
fileStream.close()
|
closeAll()
|
||||||
deleteFile()
|
return it
|
||||||
updateNotification()
|
}
|
||||||
|
|
||||||
closeAll()
|
|
||||||
return ERROR_CONNECTION_ERROR
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fileStream.write(ts.bytes)
|
fileStream.write(ts.bytes)
|
||||||
++tsProgress
|
tsProgress = ts.currentIndex.toLong()
|
||||||
bytesDownloaded += ts.bytes.size.toLong()
|
bytesDownloaded += ts.bytes.size.toLong()
|
||||||
logcatPrint("Download progress $tsProgress/$totalTs")
|
logcatPrint("Download progress ${((tsProgress.toFloat()/totalTs.toFloat())*100).roundToInt()}%")
|
||||||
}
|
}
|
||||||
isDone = true
|
isDone = true
|
||||||
fileStream.close()
|
fileStream.close()
|
||||||
|
|
Loading…
Reference in a new issue