Skip to content

Commit

Permalink
fix(Format): Parse xtags from protobuf to support SABR-only responses (
Browse files Browse the repository at this point in the history
  • Loading branch information
absidue authored Feb 27, 2025
1 parent 06a0090 commit 00c199a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
40 changes: 40 additions & 0 deletions protos/generated/misc/common.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions protos/misc/common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ message IndexRange {
message KeyValuePair {
optional string key = 1;
optional string value = 2;
}

message FormatXTags {
repeated KeyValuePair xtags = 1;
}
15 changes: 8 additions & 7 deletions src/parser/classes/misc/Format.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type Player from '../../../core/Player.js';
import type { RawNode } from '../../index.js';
import { FormatXTags } from '../../../../protos/generated/misc/common.js';
import { base64ToU8 } from '../../../utils/Utils.js';

export type ProjectionType = 'RECTANGULAR' | 'EQUIRECTANGULAR' | 'EQUIRECTANGULAR_THREED_TOP_BOTTOM' | 'MESH';
export type SpatialAudioType = 'AMBISONICS_5_1' | 'AMBISONICS_QUAD' | 'FOA_WITH_NON_DIEGETIC';
Expand Down Expand Up @@ -211,17 +213,16 @@ export default class Format {
};

if (this.has_audio || this.has_text) {
const args = new URLSearchParams(this.cipher || this.signature_cipher);
const url_components = new URLSearchParams(args.get('url') || this.url);
const xtags = this.xtags
? FormatXTags.decode(base64ToU8(decodeURIComponent(this.xtags).replace(/-/g, '+').replace(/_/g, '/'))).xtags
: [];

const xtags = url_components.get('xtags')?.split(':');

this.language = xtags?.find((x: string) => x.startsWith('lang='))?.split('=')[1] || null;
this.language = xtags.find((tag) => tag.key === 'lang')?.value || null;

if (this.has_audio) {
this.is_drc = !!data.isDrc || !!xtags?.includes('drc=1');
this.is_drc = !!data.isDrc || xtags.some((tag) => tag.key === 'drc' && tag.value === '1');

const audio_content = xtags?.find((x) => x.startsWith('acont='))?.split('=')[1];
const audio_content = xtags.find((tag) => tag.key === 'acont')?.value;
this.is_dubbed = audio_content === 'dubbed';
this.is_descriptive = audio_content === 'descriptive';
this.is_secondary = audio_content === 'secondary';
Expand Down

0 comments on commit 00c199a

Please sign in to comment.