mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-27 23:40:33 +05:30
Merge pull request #7287 from Bnyro/master
fix: skip already downloaded videos when downloading playlists
This commit is contained in:
commit
2c7657d4f7
@ -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,35 +137,41 @@ 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 videoInfo = runCatching {
|
val videoId = stream.url!!.toID()
|
||||||
MediaServiceRepository.instance.getStreams(stream.url!!.toID())
|
|
||||||
}.getOrNull() ?: continue
|
|
||||||
|
|
||||||
val videoStream = getStream(videoInfo.videoStreams, maxVideoQuality)
|
// only download videos that have not been downloaded before
|
||||||
val audioStream = getStream(videoInfo.audioStreams, maxAudioQuality)
|
if (!DatabaseHolder.Database.downloadDao().exists(videoId)) {
|
||||||
|
val videoInfo = runCatching {
|
||||||
|
MediaServiceRepository.instance.getStreams(videoId)
|
||||||
|
}.getOrNull() ?: continue
|
||||||
|
|
||||||
// remove all UNIX reserved characters from the title in order to generate
|
val videoStream = getStream(videoInfo.videoStreams, maxVideoQuality)
|
||||||
// a valid filename
|
val audioStream = getStream(videoInfo.audioStreams, maxAudioQuality)
|
||||||
var fileName = videoInfo.title
|
|
||||||
TextUtils.RESERVED_CHARS.forEach {
|
|
||||||
fileName = fileName.replace(it, '_')
|
|
||||||
}
|
|
||||||
|
|
||||||
val downloadData = DownloadData(
|
// remove all UNIX reserved characters from the title in order to generate
|
||||||
videoId = stream.url!!.toID(),
|
// a valid filename
|
||||||
fileName = fileName,
|
var fileName = videoInfo.title
|
||||||
videoFormat = videoStream?.format,
|
TextUtils.RESERVED_CHARS.forEach {
|
||||||
videoQuality = videoStream?.quality,
|
fileName = fileName.replace(it, '_')
|
||||||
audioFormat = audioStream?.format,
|
|
||||||
audioQuality = audioStream?.quality,
|
|
||||||
audioLanguage = audioLanguage.takeIf {
|
|
||||||
videoInfo.audioStreams.any { it.audioTrackLocale == audioLanguage }
|
|
||||||
},
|
|
||||||
subtitleCode = captionLanguage.takeIf {
|
|
||||||
videoInfo.subtitles.any { it.code == captionLanguage }
|
|
||||||
}
|
}
|
||||||
)
|
|
||||||
DownloadHelper.startDownloadService(this, downloadData)
|
val downloadData = DownloadData(
|
||||||
|
videoId = videoId,
|
||||||
|
fileName = fileName,
|
||||||
|
videoFormat = videoStream?.format,
|
||||||
|
videoQuality = videoStream?.quality,
|
||||||
|
audioFormat = audioStream?.format,
|
||||||
|
audioQuality = audioStream?.quality,
|
||||||
|
audioLanguage = audioLanguage.takeIf {
|
||||||
|
videoInfo.audioStreams.any { it.audioTrackLocale == audioLanguage }
|
||||||
|
},
|
||||||
|
subtitleCode = captionLanguage.takeIf {
|
||||||
|
videoInfo.subtitles.any { it.code == captionLanguage }
|
||||||
|
}
|
||||||
|
)
|
||||||
|
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