Skip to content

Commit

Permalink
feat: Add support for forced subtitles (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad authored Nov 11, 2024
1 parent 2ac830b commit 96ae67a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions streamer/autodetect.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,13 @@ def get_channel_layout(input: Input) -> Optional[AudioChannelLayoutName]:
return bucket.get_key()

return None

def get_forced_subttitle(input: Input) -> bool:
"""Returns the forced subtitle value of the input."""

forced_subttitle_string = _probe(input, 'disposition=forced')

if forced_subttitle_string is None:
return False

return bool(forced_subttitle_string)
8 changes: 8 additions & 0 deletions streamer/input_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ class Input(configuration.Base):
Not supported with media_type of 'text'.
"""

forced_subtitle = configuration.Field(bool).cast()
"""Indicates that the subtitle is forced.
Only supported with media_type of 'text'.
"""


def __init__(self, *args) -> None:
super().__init__(*args)
Expand Down Expand Up @@ -264,6 +270,8 @@ def disallow_field(name: str, reason: str) -> None:
reason = 'text streams are not supported in input_type "{}"'.format(
self.input_type.value)
disallow_field('input_type', reason)
if self.forced_subtitle is None:
self.forced_subtitle = autodetect.get_forced_subttitle(self)

# These fields are not supported with text, because we don't process or
# transcode it.
Expand Down
3 changes: 3 additions & 0 deletions streamer/packager_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ def _setup_stream(self, stream: OutputStream) -> str:
if stream.input.drm_label:
dict['drm_label'] = stream.input.drm_label

if stream.input.forced_subtitle:
dict['forced_subtitle'] = '1'

# Note: Shaka Packager will not accept 'und' as a language, but Shaka
# Player will fill that in if the language metadata is missing from the
# manifest/playlist.
Expand Down
3 changes: 3 additions & 0 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,7 @@ function textTracksTests(manifestUrl, format) {
'name': TEST_DIR + 'Sintel.2010.Arabic.vtt',
'media_type': 'text',
'language': 'ar',
'forced_subtitle': true,
},
],
};
Expand All @@ -1084,6 +1085,8 @@ function textTracksTests(manifestUrl, format) {
const languageList = trackList.map(track => track.language);
languageList.sort();
expect(languageList).toEqual(['ar', 'en', 'eo', 'es']);
const arTrack = trackList.find(track => track.language == 'ar');
expect(arTrack.forced).toBeTruthy();
});
}

Expand Down

0 comments on commit 96ae67a

Please sign in to comment.