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