Skip to content

Commit 5ff7a84

Browse files
committed
Fix for Youtube Extractor Labels
1 parent f794f3a commit 5ff7a84

3 files changed

Lines changed: 42 additions & 5 deletions

File tree

app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ class CS3IPlayer : IPlayer {
166166

167167
private val subtitleHelper = PlayerSubtitleHelper()
168168

169+
/** Ordered list of AudioFile metadata corresponding to audio track order */
170+
private var audioFileMetadata = listOf<AudioFile>()
171+
169172
/** If we want to play the audio only in the background when the app is not open */
170173
private var isAudioOnlyBackground = false
171174

@@ -433,10 +436,33 @@ class CS3IPlayer : IPlayer {
433436
}
434437

435438
private fun Format.toAudioTrack(formatIndex: Int?): AudioTrack {
439+
440+
// Extract the track number from the Format ID (e.g., "26:1" -> 26)
441+
val trackIdNumber = this.id?.split(":")?.firstOrNull()?.toIntOrNull()
442+
443+
// Find the AudioFile that corresponds to this track
444+
val audioFile = if (trackIdNumber != null && audioFileMetadata.isNotEmpty()) {
445+
// Map track ID to AudioFile array index
446+
// The first audio track seems to start at ID 26 based on debug logs
447+
// So we subtract the starting offset to get the array index
448+
val startingTrackId = 26 // Based on debug logs showing "id='26:1'"
449+
val arrayIndex = trackIdNumber - startingTrackId
450+
if (arrayIndex >= 0 && arrayIndex < audioFileMetadata.size) {
451+
audioFileMetadata[arrayIndex]
452+
} else {
453+
null
454+
}
455+
} else {
456+
null
457+
}
458+
459+
val finalLanguage = audioFile?.lang ?: this.language
460+
val finalLabel = audioFile?.label ?: this.label
461+
436462
return AudioTrack(
437463
this.id,
438-
this.label,
439-
this.language,
464+
finalLabel,
465+
finalLanguage,
440466
this.sampleMimeType,
441467
this.channelCount,
442468
formatIndex ?: 0,
@@ -1699,9 +1725,15 @@ class CS3IPlayer : IPlayer {
16991725
audioTracks: List<AudioFile>,
17001726
interceptor: Interceptor?,
17011727
): List<MediaSource> {
1728+
// Store AudioFile metadata in order
1729+
audioFileMetadata = audioTracks
1730+
17021731
return audioTracks.mapNotNull { audio ->
17031732
try {
1704-
val mediaItem = getMediaItem(MimeTypes.AUDIO_UNKNOWN, audio.url)
1733+
val mediaItem = MediaItem.Builder()
1734+
.setUri(audio.url)
1735+
.setMimeType(MimeTypes.AUDIO_UNKNOWN)
1736+
.build()
17051737
val dataSourceFactory = createOnlineSource(audio.headers, interceptor)
17061738
DefaultMediaSourceFactory(dataSourceFactory).createMediaSource(mediaItem)
17071739
} catch (e: Exception) {

library/src/commonMain/kotlin/com/lagradost/cloudstream3/MainAPI.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,9 @@ suspend fun newSubtitleFile(
11541154
@ConsistentCopyVisibility
11551155
data class AudioFile internal constructor(
11561156
var url: String,
1157-
var headers: Map<String, String>? = null
1157+
var headers: Map<String, String>? = null,
1158+
var lang: String? = null,
1159+
var label: String? = null
11581160
)
11591161

11601162
/** Creates an AudioFile with optional initializer for setting additional properties.

library/src/commonMain/kotlin/com/lagradost/cloudstream3/extractors/YoutubeExtractor.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ open class YoutubeExtractor(
7272
url = video.content
7373
) {
7474
quality = video.height
75-
audioTracks = audioStreams.map { newAudioFile(it.content) }
75+
audioTracks = audioStreams.map { newAudioFile(it.content){
76+
this.lang = it.audioLocale?.toString()
77+
this.label = it.audioTrackName
78+
} }
7679
}
7780
)
7881
}

0 commit comments

Comments
 (0)