Skip to content

Commit 4323f78

Browse files
bermountBnyro
authored andcommitted
fix: prevent playlist download from stalling on unavailable videos
videoInfo = null previously skipped amountOfVideosDone count, causing the service to never complete. The logic now ensures the progress counter is always incremented even if a video cannot be fetched.
1 parent a8505ce commit 4323f78

1 file changed

Lines changed: 21 additions & 19 deletions

File tree

app/src/main/java/com/github/libretube/services/PlaylistDownloadEnqueueService.kt

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -185,25 +185,27 @@ class PlaylistDownloadEnqueueService : LifecycleService() {
185185
if (!DatabaseHolder.Database.downloadDao().exists(videoId)) {
186186
val videoInfo = runCatching {
187187
MediaServiceRepository.instance.getStreams(videoId)
188-
}.getOrNull() ?: continue
189-
190-
val videoStream = getStream(videoInfo.videoStreams, maxVideoQuality)
191-
val audioStream = getStream(videoInfo.audioStreams, maxAudioQuality)
192-
193-
val downloadData = DownloadData(
194-
videoId = videoId,
195-
videoFormat = videoStream?.format,
196-
videoQuality = videoStream?.quality,
197-
audioFormat = audioStream?.format,
198-
audioQuality = audioStream?.quality,
199-
audioLanguage = audioLanguage.takeIf {
200-
videoInfo.audioStreams.any { it.audioTrackLocale == audioLanguage }
201-
},
202-
subtitleCode = captionLanguage.takeIf {
203-
videoInfo.subtitles.any { it.code == captionLanguage }
204-
}
205-
)
206-
DownloadHelper.startDownloadService(this, downloadData)
188+
}.getOrNull()
189+
190+
if (videoInfo != null) {
191+
val videoStream = getStream(videoInfo.videoStreams, maxVideoQuality)
192+
val audioStream = getStream(videoInfo.audioStreams, maxAudioQuality)
193+
194+
val downloadData = DownloadData(
195+
videoId = videoId,
196+
videoFormat = videoStream?.format,
197+
videoQuality = videoStream?.quality,
198+
audioFormat = audioStream?.format,
199+
audioQuality = audioStream?.quality,
200+
audioLanguage = audioLanguage.takeIf {
201+
videoInfo.audioStreams.any { it.audioTrackLocale == audioLanguage }
202+
},
203+
subtitleCode = captionLanguage.takeIf {
204+
videoInfo.subtitles.any { it.code == captionLanguage }
205+
}
206+
)
207+
DownloadHelper.startDownloadService(this, downloadData)
208+
}
207209
}
208210
// TODO: inform the user if an already downloaded video has been skipped
209211

0 commit comments

Comments
 (0)