mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Merge branch 'recloudstream:master' into initial-multi-delete
This commit is contained in:
commit
c79dd881e8
1 changed files with 35 additions and 7 deletions
|
@ -551,7 +551,8 @@ object VideoDownloadManager {
|
|||
tryResume: Boolean,
|
||||
): StreamData {
|
||||
return setupStream(
|
||||
context.getBasePath().first ?: getDefaultDir(context) ?: throw IOException("Bad config"),
|
||||
context.getBasePath().first ?: getDefaultDir(context)
|
||||
?: throw IOException("Bad config"),
|
||||
name,
|
||||
folder,
|
||||
extension,
|
||||
|
@ -950,7 +951,7 @@ object VideoDownloadManager {
|
|||
bufferSize: Int = DEFAULT_BUFFER_SIZE,
|
||||
/** how many bytes bytes it should require to use the parallel downloader instead,
|
||||
* if we download a very small file we don't want it parallel */
|
||||
maximumSmallSize : Long = chuckSize * 2
|
||||
maximumSmallSize: Long = chuckSize * 2
|
||||
): LazyStreamDownloadData {
|
||||
// we don't want to make a separate connection for every 1kb
|
||||
require(chuckSize > 1000)
|
||||
|
@ -1033,7 +1034,10 @@ object VideoDownloadManager {
|
|||
tryResume: Boolean,
|
||||
parentId: Int?,
|
||||
createNotificationCallback: (CreateNotificationMetadata) -> Unit,
|
||||
parallelConnections: Int = 3
|
||||
parallelConnections: Int = 3,
|
||||
/** how many bytes a valid file must be in bytes,
|
||||
* this should be different for subtitles and video */
|
||||
minimumSize: Long = 100
|
||||
): DownloadStatus = withContext(Dispatchers.IO) {
|
||||
if (parallelConnections < 1) {
|
||||
return@withContext DOWNLOAD_INVALID_INPUT
|
||||
|
@ -1079,6 +1083,13 @@ object VideoDownloadManager {
|
|||
)
|
||||
)
|
||||
|
||||
if (items.totalLength != null && items.totalLength < minimumSize) {
|
||||
fileStream.closeQuietly()
|
||||
metadata.onDelete()
|
||||
stream.delete()
|
||||
return@withContext DOWNLOAD_INVALID_INPUT
|
||||
}
|
||||
|
||||
metadata.totalBytes = items.totalLength
|
||||
metadata.type = DownloadType.IsDownloading
|
||||
metadata.setDownloadFileInfoTemplate(
|
||||
|
@ -1228,6 +1239,16 @@ object VideoDownloadManager {
|
|||
return@withContext DOWNLOAD_STOPPED
|
||||
}
|
||||
|
||||
// in case the head request lies about content-size,
|
||||
// then we don't want shit output
|
||||
if (metadata.bytesDownloaded < minimumSize) {
|
||||
// we need to close before delete
|
||||
fileStream.closeQuietly()
|
||||
metadata.onDelete()
|
||||
stream.delete()
|
||||
return@withContext DOWNLOAD_INVALID_INPUT
|
||||
}
|
||||
|
||||
metadata.type = DownloadType.IsDone
|
||||
return@withContext DOWNLOAD_SUCCESS
|
||||
} catch (e: IOException) {
|
||||
|
@ -1279,6 +1300,7 @@ object VideoDownloadManager {
|
|||
val displayName = getDisplayName(name, extension)
|
||||
val stream =
|
||||
setupStream(baseFile, name, folder, extension, startAt > 0)
|
||||
|
||||
if (!stream.resume) startAt = 0
|
||||
fileStream = stream.open()
|
||||
|
||||
|
@ -1305,6 +1327,7 @@ object VideoDownloadManager {
|
|||
) + if (link.referer.isNotBlank()) mapOf("referer" to link.referer) else emptyMap()
|
||||
)
|
||||
)
|
||||
|
||||
val items = M3u8Helper2.hslLazy(listOf(m3u8))
|
||||
|
||||
metadata.hlsTotal = items.size
|
||||
|
@ -1402,7 +1425,7 @@ object VideoDownloadManager {
|
|||
try {
|
||||
// may cause java.lang.IllegalStateException: Mutex is not locked because of cancelling
|
||||
fileMutex.unlock()
|
||||
} catch (t : Throwable) {
|
||||
} catch (t: Throwable) {
|
||||
logError(t)
|
||||
}
|
||||
}
|
||||
|
@ -1529,7 +1552,7 @@ object VideoDownloadManager {
|
|||
tryResume: Boolean = false,
|
||||
): DownloadStatus {
|
||||
// no support for these file formats
|
||||
if(link.type == ExtractorLinkType.MAGNET || link.type == ExtractorLinkType.TORRENT || link.type == ExtractorLinkType.DASH) {
|
||||
if (link.type == ExtractorLinkType.MAGNET || link.type == ExtractorLinkType.TORRENT || link.type == ExtractorLinkType.DASH) {
|
||||
return DOWNLOAD_INVALID_INPUT
|
||||
}
|
||||
|
||||
|
@ -1561,7 +1584,7 @@ object VideoDownloadManager {
|
|||
}
|
||||
|
||||
try {
|
||||
when(link.type) {
|
||||
when (link.type) {
|
||||
ExtractorLinkType.M3U8 -> {
|
||||
val startIndex = if (tryResume) {
|
||||
context.getKey<DownloadedFileInfo>(
|
||||
|
@ -1581,6 +1604,7 @@ object VideoDownloadManager {
|
|||
callback, parallelConnections = maxConcurrentConnections
|
||||
)
|
||||
}
|
||||
|
||||
ExtractorLinkType.VIDEO -> {
|
||||
return downloadThing(
|
||||
context,
|
||||
|
@ -1590,9 +1614,13 @@ object VideoDownloadManager {
|
|||
"mp4",
|
||||
tryResume,
|
||||
ep.id,
|
||||
callback, parallelConnections = maxConcurrentConnections
|
||||
callback,
|
||||
parallelConnections = maxConcurrentConnections,
|
||||
/** We require at least 10 MB video files */
|
||||
minimumSize = (1 shl 20) * 10
|
||||
)
|
||||
}
|
||||
|
||||
else -> throw IllegalArgumentException("unsuported download type")
|
||||
}
|
||||
} catch (t: Throwable) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue