mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 00:10:32 +05:30
fix: skip already downloaded videos when downloading playlists
This commit is contained in:
parent
f55b8c41bf
commit
50c2e18829
@ -15,6 +15,7 @@ import com.github.libretube.api.PlaylistsHelper
|
|||||||
import com.github.libretube.api.obj.PipedStream
|
import com.github.libretube.api.obj.PipedStream
|
||||||
import com.github.libretube.api.obj.StreamItem
|
import com.github.libretube.api.obj.StreamItem
|
||||||
import com.github.libretube.constants.IntentData
|
import com.github.libretube.constants.IntentData
|
||||||
|
import com.github.libretube.db.DatabaseHolder
|
||||||
import com.github.libretube.enums.NotificationId
|
import com.github.libretube.enums.NotificationId
|
||||||
import com.github.libretube.enums.PlaylistType
|
import com.github.libretube.enums.PlaylistType
|
||||||
import com.github.libretube.extensions.getWhileDigit
|
import com.github.libretube.extensions.getWhileDigit
|
||||||
@ -136,8 +137,12 @@ class PlaylistDownloadEnqueueService : LifecycleService() {
|
|||||||
nManager.notify(NotificationId.ENQUEUE_PLAYLIST_DOWNLOAD.id, buildNotification())
|
nManager.notify(NotificationId.ENQUEUE_PLAYLIST_DOWNLOAD.id, buildNotification())
|
||||||
|
|
||||||
for (stream in streams) {
|
for (stream in streams) {
|
||||||
|
val videoId = stream.url!!.toID()
|
||||||
|
|
||||||
|
// only download videos that have not been downloaded before
|
||||||
|
if (!DatabaseHolder.Database.downloadDao().exists(videoId)) {
|
||||||
val videoInfo = runCatching {
|
val videoInfo = runCatching {
|
||||||
MediaServiceRepository.instance.getStreams(stream.url!!.toID())
|
MediaServiceRepository.instance.getStreams(videoId)
|
||||||
}.getOrNull() ?: continue
|
}.getOrNull() ?: continue
|
||||||
|
|
||||||
val videoStream = getStream(videoInfo.videoStreams, maxVideoQuality)
|
val videoStream = getStream(videoInfo.videoStreams, maxVideoQuality)
|
||||||
@ -151,7 +156,7 @@ class PlaylistDownloadEnqueueService : LifecycleService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val downloadData = DownloadData(
|
val downloadData = DownloadData(
|
||||||
videoId = stream.url!!.toID(),
|
videoId = videoId,
|
||||||
fileName = fileName,
|
fileName = fileName,
|
||||||
videoFormat = videoStream?.format,
|
videoFormat = videoStream?.format,
|
||||||
videoQuality = videoStream?.quality,
|
videoQuality = videoStream?.quality,
|
||||||
@ -165,6 +170,8 @@ class PlaylistDownloadEnqueueService : LifecycleService() {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
DownloadHelper.startDownloadService(this, downloadData)
|
DownloadHelper.startDownloadService(this, downloadData)
|
||||||
|
}
|
||||||
|
// TODO: inform the user if an already downloaded video has been skipped
|
||||||
|
|
||||||
amountOfVideosDone++
|
amountOfVideosDone++
|
||||||
nManager.notify(NotificationId.ENQUEUE_PLAYLIST_DOWNLOAD.id, buildNotification())
|
nManager.notify(NotificationId.ENQUEUE_PLAYLIST_DOWNLOAD.id, buildNotification())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user