From 9ec166dcef3f86f7108b2c972f344e22da2dc641 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Thu, 26 Jan 2023 19:25:23 +0100 Subject: [PATCH] Better download file naming scheme --- .../com/github/libretube/extensions/QualityString.kt | 8 ++++++++ .../github/libretube/extensions/ToDownloadItems.kt | 12 ++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/com/github/libretube/extensions/QualityString.kt diff --git a/app/src/main/java/com/github/libretube/extensions/QualityString.kt b/app/src/main/java/com/github/libretube/extensions/QualityString.kt new file mode 100644 index 000000000..371541bac --- /dev/null +++ b/app/src/main/java/com/github/libretube/extensions/QualityString.kt @@ -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() +} diff --git a/app/src/main/java/com/github/libretube/extensions/ToDownloadItems.kt b/app/src/main/java/com/github/libretube/extensions/ToDownloadItems.kt index 497daaf34..8724f0ccc 100644 --- a/app/src/main/java/com/github/libretube/extensions/ToDownloadItems.kt +++ b/app/src/main/java/com/github/libretube/extensions/ToDownloadItems.kt @@ -16,12 +16,12 @@ fun Streams.toDownloadItems( val items = mutableListOf() 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 ) ) }