fix for ac3 edge cases

This commit is contained in:
chrisk325 2026-02-27 18:42:10 +05:30 committed by GitHub
parent 86c528c199
commit 39ddd236e6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -115,13 +115,16 @@ const exoMimeToCodec = (mimeType?: string): string | null => {
export const buildExoAudioTrackName = (t: any, i: number): string => { export const buildExoAudioTrackName = (t: any, i: number): string => {
const parts: string[] = []; const parts: string[] = [];
let rawTitle: string = t.title ?? '';
// Check both title and name fields for the |ch: encoding from Java
let rawTitle: string = t.title ?? t.name ?? '';
let channelCount: number | null = null; let channelCount: number | null = null;
const chMatch = rawTitle.match(/\|ch:(\d+)$/); const chMatch = rawTitle.match(/\|ch:(\d+)$/);
if (chMatch) { if (chMatch) {
channelCount = parseInt(chMatch[1], 10); channelCount = parseInt(chMatch[1], 10);
rawTitle = rawTitle.replace(/\|ch:\d+$/, '').trim(); rawTitle = rawTitle.replace(/\|ch:\d+$/, '').trim();
} }
if (rawTitle) { if (rawTitle) {
// Prepend language if available and not already in the title // Prepend language if available and not already in the title
if (t.language) { if (t.language) {
@ -134,9 +137,22 @@ export const buildExoAudioTrackName = (t: any, i: number): string => {
} else if (t.language) { } else if (t.language) {
parts.push(EXOPLAYER_LANG_MAP[t.language.toLowerCase()] ?? t.language.toUpperCase()); parts.push(EXOPLAYER_LANG_MAP[t.language.toLowerCase()] ?? t.language.toUpperCase());
} }
const codec = exoMimeToCodec(t.mimeType); const codec = exoMimeToCodec(t.mimeType);
if (codec) parts.push(codec); if (codec) parts.push(codec);
const ch = channelCount ?? t.channelCount ?? null;
// Use parsed channel count, fall back to bitrate-based guess for AC3/EAC3
let ch = channelCount ?? t.channelCount ?? null;
if (ch == null && t.bitrate != null && t.bitrate > 0) {
const mime = (t.mimeType ?? '').toLowerCase();
if (mime.includes('ac3') || mime.includes('eac3') || mime.includes('ec-3')) {
// AC3: 640kbps = 5.1, 192-256kbps = 2.0
// EAC3: 768kbps+ = 5.1, 192-256kbps = 2.0
if (t.bitrate >= 500000) ch = 6;
else if (t.bitrate <= 320000) ch = 2;
}
}
if (ch != null && ch > 0) { if (ch != null && ch > 0) {
if (ch === 8) parts.push('7.1'); if (ch === 8) parts.push('7.1');
else if (ch === 7) parts.push('6.1'); else if (ch === 7) parts.push('6.1');
@ -145,9 +161,11 @@ export const buildExoAudioTrackName = (t: any, i: number): string => {
else if (ch === 1) parts.push('Mono'); else if (ch === 1) parts.push('Mono');
else parts.push(`${ch}ch`); else parts.push(`${ch}ch`);
} }
if (t.bitrate != null && t.bitrate > 0) { if (t.bitrate != null && t.bitrate > 0) {
parts.push(`${Math.round(t.bitrate / 1000)} kbps`); parts.push(`${Math.round(t.bitrate / 1000)} kbps`);
} }
return parts.length > 0 ? parts.join(' ') : `Track ${i + 1}`; return parts.length > 0 ? parts.join(' ') : `Track ${i + 1}`;
}; };