mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
Add support for extracting audio track types
Co-authored-By: AudricV <74829229+AudricV@users.noreply.github.com>
This commit is contained in:
parent
9e3dc8bde4
commit
2dc4c15dd8
@ -24,7 +24,9 @@ data class PipedStream(
|
||||
val fps: Int? = null,
|
||||
val audioTrackName: String? = null,
|
||||
val audioTrackId: String? = null,
|
||||
val contentLength: Long = -1
|
||||
val contentLength: Long = -1,
|
||||
val audioTrackType: String? = null,
|
||||
val audioTrackLocale: String? = null
|
||||
) {
|
||||
private fun getQualityString(fileName: String): String {
|
||||
return "${fileName}_${quality?.replace(" ", "_")}_$format." +
|
||||
|
@ -19,8 +19,10 @@ object DashHelper {
|
||||
|
||||
private data class AdapSetInfo(
|
||||
val mimeType: String,
|
||||
val formats: MutableList<PipedStream> = mutableListOf(),
|
||||
val audioTrackId: String? = null,
|
||||
val formats: MutableList<PipedStream> = mutableListOf()
|
||||
val audioTrackType: String? = null,
|
||||
val audioLocale: String? = null
|
||||
)
|
||||
|
||||
fun createManifest(
|
||||
@ -75,7 +77,6 @@ object DashHelper {
|
||||
adapSetInfos.add(
|
||||
AdapSetInfo(
|
||||
stream.mimeType!!,
|
||||
null,
|
||||
mutableListOf(stream)
|
||||
)
|
||||
)
|
||||
@ -94,8 +95,10 @@ object DashHelper {
|
||||
adapSetInfos.add(
|
||||
AdapSetInfo(
|
||||
stream.mimeType!!,
|
||||
mutableListOf(stream),
|
||||
stream.audioTrackId,
|
||||
mutableListOf(stream)
|
||||
stream.audioTrackType,
|
||||
stream.audioTrackLocale
|
||||
)
|
||||
)
|
||||
}
|
||||
@ -105,10 +108,22 @@ object DashHelper {
|
||||
adapSetElement.setAttribute("mimeType", adapSet.mimeType)
|
||||
adapSetElement.setAttribute("startWithSAP", "1")
|
||||
adapSetElement.setAttribute("subsegmentAlignment", "true")
|
||||
|
||||
if (adapSet.audioTrackId != null) {
|
||||
adapSetElement.setAttribute("lang", adapSet.audioTrackId.substring(0, 2))
|
||||
} else if (adapSet.audioLocale != null) {
|
||||
adapSetElement.setAttribute("lang", adapSet.audioLocale)
|
||||
}
|
||||
|
||||
val roleElement = doc.createElement("Role")
|
||||
roleElement.setAttribute("schemeIdUri", "urn:mpeg:dash:role:2011")
|
||||
roleElement.setAttribute(
|
||||
"value",
|
||||
getRoleValueFromAudioTrackType(adapSet.audioTrackType)
|
||||
)
|
||||
|
||||
adapSetElement.appendChild(roleElement)
|
||||
|
||||
val isVideo = adapSet.mimeType.contains("video")
|
||||
|
||||
if (isVideo) {
|
||||
@ -162,18 +177,38 @@ object DashHelper {
|
||||
val baseUrl = doc.createElement("BaseURL")
|
||||
baseUrl.appendChild(doc.createTextNode(ProxyHelper.unwrapUrl(stream.url!!, rewriteUrls)))
|
||||
|
||||
val segmentBase = doc.createElement("SegmentBase")
|
||||
representation.appendChild(audioChannelConfiguration)
|
||||
representation.appendChild(baseUrl)
|
||||
representation.appendChild(createSegmentBaseElement(doc, stream))
|
||||
|
||||
return representation
|
||||
}
|
||||
|
||||
private fun createSegmentBaseElement(
|
||||
document: Document,
|
||||
stream: PipedStream
|
||||
): Element {
|
||||
val segmentBase = document.createElement("SegmentBase")
|
||||
segmentBase.setAttribute("indexRange", "${stream.indexStart}-${stream.indexEnd}")
|
||||
|
||||
val initialization = doc.createElement("Initialization")
|
||||
val initialization = document.createElement("Initialization")
|
||||
initialization.setAttribute("range", "${stream.initStart}-${stream.initEnd}")
|
||||
segmentBase.appendChild(initialization)
|
||||
|
||||
representation.appendChild(audioChannelConfiguration)
|
||||
representation.appendChild(baseUrl)
|
||||
representation.appendChild(segmentBase)
|
||||
return segmentBase
|
||||
}
|
||||
|
||||
return representation
|
||||
private fun getRoleValueFromAudioTrackType(audioTrackType: String?): String {
|
||||
if (audioTrackType == null) {
|
||||
return "main"
|
||||
}
|
||||
|
||||
return when (audioTrackType.lowercase()) {
|
||||
"descriptive" -> "description"
|
||||
"dubbed" -> "dub"
|
||||
"original" -> "main"
|
||||
else -> "alternate"
|
||||
}
|
||||
}
|
||||
|
||||
private fun createVideoRepresentation(
|
||||
|
Loading…
Reference in New Issue
Block a user