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