fix downloads not continually resuming, some other changes
This commit is contained in:
parent
2cd41421c2
commit
105186c1f4
4 changed files with 26 additions and 8 deletions
|
|
@ -107,11 +107,20 @@ interface DownloadDao {
|
|||
|
||||
@Query("""
|
||||
SELECT * FROM downloads
|
||||
WHERE downloadStartTime <= :currentTime and status in ('Queued', 'Scheduled')
|
||||
WHERE status in ('Queued', 'Scheduled') AND downloadStartTime <= :currentTime
|
||||
ORDER BY downloadStartTime, id
|
||||
LIMIT 20
|
||||
""")
|
||||
fun getQueuedScheduledDownloadsUntil(currentTime: Long) : Flow<List<DownloadItem>>
|
||||
|
||||
@Query("""
|
||||
SELECT * FROM downloads
|
||||
WHERE id in (:priorityItems) AND status in ('Queued', 'Scheduled') AND downloadStartTime <= :currentTime
|
||||
ORDER BY downloadStartTime, id
|
||||
LIMIT 20
|
||||
""")
|
||||
fun getQueuedScheduledDownloadsUntilWithPriority(currentTime: Long, priorityItems: List<Long>) : Flow<List<DownloadItem>>
|
||||
|
||||
@Query("SELECT * FROM downloads WHERE status='Queued' ORDER BY downloadStartTime, id")
|
||||
fun getQueuedDownloadsList() : List<DownloadItem>
|
||||
|
||||
|
|
|
|||
|
|
@ -50,6 +50,11 @@ class FormatUtil(private var context: Context) {
|
|||
formatImportance.add(0, "smallsize")
|
||||
}
|
||||
|
||||
val preferContainerOverCodec = sharedPreferences.getBoolean("prefer_container_over_codec_audio", false)
|
||||
if(preferContainerOverCodec) {
|
||||
formatImportance.remove("codec")
|
||||
}
|
||||
|
||||
return formatImportance
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1330,7 +1330,7 @@ class YTDLPUtil(private val context: Context, private val commandTemplateDao: Co
|
|||
if (elements.size > 1) {
|
||||
for (el in elements.drop(1)) {
|
||||
val arg = el.toString()
|
||||
.replace("\\", "\\\\")
|
||||
//.replace("\\", "\\\\")
|
||||
.replace("\"", "\\\"")
|
||||
|
||||
this.add("\"$arg\"")
|
||||
|
|
|
|||
|
|
@ -76,9 +76,13 @@ class DownloadWorker(
|
|||
val alarmScheduler = AlarmScheduler(context)
|
||||
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
val time = System.currentTimeMillis() + 6000
|
||||
val queuedItems = dao.getQueuedScheduledDownloadsUntil(time)
|
||||
val priorityItemIDs = (inputData.getLongArray("priority_item_ids") ?: longArrayOf()).toMutableList()
|
||||
val continueAfterPriorityIds = inputData.getBoolean("continue_after_priority_ids", true)
|
||||
val queuedItems = if (priorityItemIDs.isEmpty()) {
|
||||
dao.getQueuedScheduledDownloadsUntil(time)
|
||||
}else {
|
||||
dao.getQueuedScheduledDownloadsUntilWithPriority(time, priorityItemIDs)
|
||||
}
|
||||
|
||||
// this is needed for observe sources call, so it wont create result items
|
||||
// [removed]
|
||||
|
|
@ -116,8 +120,8 @@ class DownloadWorker(
|
|||
setForegroundAsync(ForegroundInfo(notificationID, workNotif))
|
||||
}
|
||||
|
||||
queuedItems.collect { items ->
|
||||
if (this@DownloadWorker.isStopped) return@collect
|
||||
queuedItems.collectLatest { items ->
|
||||
if (this@DownloadWorker.isStopped) return@collectLatest
|
||||
|
||||
runningYTDLInstances.clear()
|
||||
val activeDownloads = dao.getActiveDownloadsList()
|
||||
|
|
@ -129,19 +133,19 @@ class DownloadWorker(
|
|||
val useScheduler = sharedPreferences.getBoolean("use_scheduler", false)
|
||||
if (items.isEmpty() && running.isEmpty()) {
|
||||
WorkManager.getInstance(context).cancelWorkById(this@DownloadWorker.id)
|
||||
return@collect
|
||||
return@collectLatest
|
||||
}
|
||||
|
||||
if (useScheduler){
|
||||
if (items.none{it.downloadStartTime > 0L} && running.isEmpty() && !alarmScheduler.isDuringTheScheduledTime()) {
|
||||
WorkManager.getInstance(context).cancelWorkById(this@DownloadWorker.id)
|
||||
return@collect
|
||||
return@collectLatest
|
||||
}
|
||||
}
|
||||
|
||||
if (priorityItemIDs.isEmpty() && !continueAfterPriorityIds) {
|
||||
WorkManager.getInstance(context).cancelWorkById(this@DownloadWorker.id)
|
||||
return@collect
|
||||
return@collectLatest
|
||||
}
|
||||
|
||||
val concurrentDownloads = sharedPreferences.getInt("concurrent_downloads", 1) - running.size
|
||||
|
|
|
|||
Loading…
Reference in a new issue