2022-12-16 22:14:21 +05:30
|
|
|
package com.github.libretube.extensions
|
|
|
|
|
|
|
|
import com.github.libretube.api.obj.Streams
|
|
|
|
import com.github.libretube.db.obj.DownloadItem
|
|
|
|
import com.github.libretube.enums.FileType
|
|
|
|
|
|
|
|
fun Streams.toDownloadItems(
|
|
|
|
videoId: String,
|
|
|
|
fileName: String,
|
|
|
|
videoFormat: String?,
|
|
|
|
videoQuality: String?,
|
|
|
|
audioFormat: String?,
|
|
|
|
audioQuality: String?,
|
|
|
|
subtitleCode: String?
|
|
|
|
): List<DownloadItem> {
|
|
|
|
val items = mutableListOf<DownloadItem>()
|
|
|
|
|
|
|
|
if (!videoQuality.isNullOrEmpty() && !videoFormat.isNullOrEmpty()) {
|
2023-01-26 23:55:23 +05:30
|
|
|
val stream = videoStreams.find { it.quality == videoQuality && it.format == videoFormat }
|
2022-12-16 22:14:21 +05:30
|
|
|
items.add(
|
|
|
|
DownloadItem(
|
|
|
|
type = FileType.VIDEO,
|
|
|
|
videoId = videoId,
|
2023-01-26 23:55:23 +05:30
|
|
|
fileName = stream.qualityString(fileName),
|
2022-12-16 22:14:21 +05:30
|
|
|
path = "",
|
2022-12-21 21:10:48 +05:30
|
|
|
url = stream?.url,
|
|
|
|
format = videoFormat,
|
|
|
|
quality = videoQuality
|
2022-12-16 22:14:21 +05:30
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!audioQuality.isNullOrEmpty() && !audioFormat.isNullOrEmpty()) {
|
2023-01-26 23:55:23 +05:30
|
|
|
val stream = audioStreams.find { it.quality == audioQuality && it.format == audioFormat }
|
2022-12-16 22:14:21 +05:30
|
|
|
items.add(
|
|
|
|
DownloadItem(
|
|
|
|
type = FileType.AUDIO,
|
|
|
|
videoId = videoId,
|
2023-01-26 23:55:23 +05:30
|
|
|
fileName = stream.qualityString(fileName),
|
2022-12-16 22:14:21 +05:30
|
|
|
path = "",
|
2022-12-21 21:10:48 +05:30
|
|
|
url = stream?.url,
|
|
|
|
format = audioFormat,
|
|
|
|
quality = audioQuality
|
2022-12-16 22:14:21 +05:30
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!subtitleCode.isNullOrEmpty()) {
|
|
|
|
items.add(
|
|
|
|
DownloadItem(
|
|
|
|
type = FileType.SUBTITLE,
|
|
|
|
videoId = videoId,
|
2023-01-26 23:55:23 +05:30
|
|
|
fileName = "${fileName}_$subtitleCode.srt",
|
2022-12-16 22:14:21 +05:30
|
|
|
path = "",
|
2023-01-26 23:55:23 +05:30
|
|
|
url = subtitles.find { it.code == subtitleCode }?.url
|
2022-12-16 22:14:21 +05:30
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return items
|
|
|
|
}
|