Better download file naming scheme

This commit is contained in:
Bnyro 2023-01-26 19:25:23 +01:00
parent 1972c0a45d
commit 9ec166dcef
2 changed files with 14 additions and 6 deletions

View File

@ -0,0 +1,8 @@
package com.github.libretube.extensions
import com.github.libretube.api.obj.PipedStream
fun PipedStream?.qualityString(fileName: String): String {
this ?: return ""
return fileName + "_" + quality?.replace(" ", "_") + "_" + format + "." + mimeType?.split("/")?.last()
}

View File

@ -16,12 +16,12 @@ fun Streams.toDownloadItems(
val items = mutableListOf<DownloadItem>()
if (!videoQuality.isNullOrEmpty() && !videoFormat.isNullOrEmpty()) {
val stream = videoStreams?.find { it.quality == videoQuality && it.format == videoFormat }
val stream = videoStreams.find { it.quality == videoQuality && it.format == videoFormat }
items.add(
DownloadItem(
type = FileType.VIDEO,
videoId = videoId,
fileName = fileName + "." + stream?.mimeType?.split("/")?.last(),
fileName = stream.qualityString(fileName),
path = "",
url = stream?.url,
format = videoFormat,
@ -31,12 +31,12 @@ fun Streams.toDownloadItems(
}
if (!audioQuality.isNullOrEmpty() && !audioFormat.isNullOrEmpty()) {
val stream = audioStreams?.find { it.quality == audioQuality && it.format == audioFormat }
val stream = audioStreams.find { it.quality == audioQuality && it.format == audioFormat }
items.add(
DownloadItem(
type = FileType.AUDIO,
videoId = videoId,
fileName = fileName + "." + stream?.mimeType?.split("/")?.last(),
fileName = stream.qualityString(fileName),
path = "",
url = stream?.url,
format = audioFormat,
@ -50,9 +50,9 @@ fun Streams.toDownloadItems(
DownloadItem(
type = FileType.SUBTITLE,
videoId = videoId,
fileName = "$fileName.srt",
fileName = "${fileName}_$subtitleCode.srt",
path = "",
url = subtitles?.find { it.code == subtitleCode }?.url
url = subtitles.find { it.code == subtitleCode }?.url
)
)
}