Skip to main content

spoolframe_types/
media.rs

1//! What a client learns about a media file before it plays it: its length,
2//! what it is (container and picture, to show), and the tracks it can
3//! choose between (ARCHITECTURE §6).
4//!
5//! Audio and subtitle codecs stay on the server, where the playback
6//! planner uses them; a client chooses an audio language, not a codec.
7
8use std::time::Duration;
9
10use serde::{Deserialize, Serialize};
11
12use crate::codec::{Container, HdrFormat, VideoCodec};
13use crate::duration_ms;
14
15/// The tracks of one media file. A track is identified by its position in
16/// its list, which is stable for as long as the file does not change.
17#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
18pub struct MediaTracks {
19    #[serde(with = "duration_ms::option")]
20    pub duration: Option<Duration>,
21    /// The file's container, from the server's own probe of it. `None`
22    /// only where nothing was probed.
23    pub container: Option<Container>,
24    /// The file's average bits per second, every stream counted, for
25    /// "42 Mbit/s": what the container says, else its size over its
26    /// length. `None` where the server knows neither.
27    ///
28    /// This and `VideoTrack::bit_rate` are not `required::option`, though
29    /// every server sends them: the SDK keeps an item's file and tracks
30    /// with a download, and one kept before them lacks the keys, which
31    /// read as `None`.
32    pub bit_rate: Option<u64>,
33    /// The main picture; `None` for audio only (music).
34    pub video: Option<VideoTrack>,
35    pub audio: Vec<AudioTrack>,
36    pub subtitles: Vec<SubtitleTrack>,
37}
38
39/// A file's picture as it is stored, for "4K · HEVC · Dolby Vision ·
40/// 10-bit": what the file is, not how it will play.
41#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
42pub struct VideoTrack {
43    pub codec: VideoCodec,
44    /// Pixels. A 2.40:1 4K film is 3840 by 1600: go by the width for
45    /// its class.
46    pub width: u32,
47    pub height: u32,
48    /// Bits per sample: 8, 10 or 12.
49    pub bit_depth: u32,
50    /// The HDR format; `None` is SDR. Dolby Vision over an HDR10 base is
51    /// Dolby Vision. HDR10+ is HDR10 here: its metadata is in the frames,
52    /// which the probe does not read.
53    pub hdr: Option<HdrFormat>,
54    /// The picture's own average bits per second, where the file says:
55    /// MP4 does for each stream, Matroska where its muxer wrote
56    /// statistics tags (mkvmerge does). As [`MediaFile::bit_rate`].
57    pub bit_rate: Option<u64>,
58}
59
60#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
61pub struct AudioTrack {
62    /// An ISO 639-2 code such as `eng`, when the file says.
63    pub language: Option<String>,
64    pub title: Option<String>,
65    pub channels: Option<u32>,
66    /// The file marks it as the one to play by default.
67    pub default: bool,
68    /// What the track is for, whatever its title says (P1-20).
69    pub role: AudioRole,
70}
71
72/// What an audio track is for.
73#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
74#[serde(rename_all = "snake_case")]
75pub enum AudioRole {
76    /// The programme's own sound.
77    #[default]
78    Main,
79    /// Narration of what is on screen, for blind and partially sighted
80    /// viewers.
81    AudioDescription,
82    Commentary,
83    /// Anything else (karaoke, music and effects only), and any role this
84    /// build does not know.
85    #[serde(other)]
86    Other,
87}
88
89#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
90pub struct SubtitleTrack {
91    /// An ISO 639-2 code such as `eng`, when the file says.
92    pub language: Option<String>,
93    pub title: Option<String>,
94    /// Only for foreign-language parts of the dialogue; shown even when
95    /// subtitles are off. The same as `role == Forced`.
96    pub forced: bool,
97    pub default: bool,
98    /// From a separate file next to the media, not inside it.
99    pub external: bool,
100    /// What the track is for, whatever its title says (P1-20).
101    pub role: SubtitleRole,
102    /// How the track is timed (PX-03): an external text track's sync and
103    /// offset, the same for every user. Only for an external text track
104    /// (SRT, WebVTT, ASS), in an item's tracks; `None` for every other
105    /// track, whose timing is the file's. Read as `None` when left out,
106    /// as a download's tracks kept by an SDK before it lack it.
107    #[serde(default)]
108    pub timing: Option<SubtitleTiming>,
109    /// Where a track someone downloaded came from (PX-02): its source,
110    /// who downloaded it and when, in an item's tracks; `None` for every
111    /// track that was not downloaded. Read as `None` when left out, as
112    /// `timing` is.
113    #[serde(default)]
114    pub download: Option<SubtitleDownload>,
115}
116
117/// A subtitle site the server searches and downloads from (PX-02). On
118/// the wire, in the database and in `subtitles.sources` it is its
119/// [`id`](SubtitleSource::id), a string: a client shows a site this build
120/// does not know as that id.
121#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
122pub enum SubtitleSource {
123    OpenSubtitles,
124    SubDl,
125}
126
127impl SubtitleSource {
128    /// Every site, in the order the server asks them unless the admin
129    /// set another.
130    pub const ALL: [SubtitleSource; 2] = [SubtitleSource::OpenSubtitles, SubtitleSource::SubDl];
131
132    /// Its id: `opensubtitles`, `subdl`.
133    pub fn id(self) -> &'static str {
134        match self {
135            SubtitleSource::OpenSubtitles => "opensubtitles",
136            SubtitleSource::SubDl => "subdl",
137        }
138    }
139
140    /// Its name, to show.
141    pub fn name(self) -> &'static str {
142        match self {
143            SubtitleSource::OpenSubtitles => "OpenSubtitles",
144            SubtitleSource::SubDl => "SubDL",
145        }
146    }
147
148    /// The site `id` names, if one.
149    pub fn of(id: &str) -> Option<SubtitleSource> {
150        SubtitleSource::ALL.into_iter().find(|s| s.id() == id)
151    }
152
153    /// The name of the site `id` names; the id itself for one this build
154    /// does not know.
155    pub fn name_of(id: &str) -> &str {
156        SubtitleSource::of(id).map_or(id, |s| s.name())
157    }
158}
159
160impl std::fmt::Display for SubtitleSource {
161    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
162        f.write_str(self.name())
163    }
164}
165
166/// A subtitle track downloaded from a subtitle site (PX-02), for everyone
167/// on the server.
168#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
169pub struct SubtitleDownload {
170    /// The download's own id: what `RemoveSubtitleDownload` names.
171    pub id: String,
172    /// The site it came from, by id: `opensubtitles` (OpenSubtitles) or
173    /// `subdl` (SubDL), as [`SubtitleResult::source`].
174    pub source: String,
175    /// The release it was made for, as the site names it.
176    pub release: String,
177    /// Who downloaded it, by display name.
178    pub by: String,
179    /// When, Unix seconds.
180    pub at: i64,
181    /// It was found by the file's hash: made for this very release, so
182    /// it was not synced.
183    pub hash_match: bool,
184    pub origin: SubtitleOrigin,
185    /// Whether the session's user may remove it: the one who downloaded
186    /// it, or an admin.
187    pub can_remove: bool,
188}
189
190/// Who made a subtitle (PX-02).
191#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
192#[serde(rename_all = "snake_case")]
193pub enum SubtitleOrigin {
194    /// Machine-translated from another language's subtitle.
195    MachineTranslated,
196    /// Made by an AI, from the speech.
197    Ai,
198    /// A person. Also any origin this build does not know. (Last, as
199    /// serde wants of `other`.)
200    #[default]
201    #[serde(other)]
202    Human,
203}
204
205/// One subtitle a search found (PX-02), to download by its `id`.
206#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
207pub struct SubtitleResult {
208    /// What `DownloadSubtitle` names: the site's id and its file's,
209    /// `opensubtitles:5338574`, `subdl:3172974-3188291`. Opaque to a
210    /// client.
211    pub id: String,
212    /// The site it was found on: `opensubtitles` (OpenSubtitles) or
213    /// `subdl` (SubDL); a client shows another as it is.
214    pub source: String,
215    /// The release it was made for, as its uploader named it.
216    pub release: String,
217    /// Its language, as the site says it: `en`, `pt-BR`.
218    pub language: String,
219    /// `srt`, `ass`, `vtt`, or what the site says.
220    pub format: Option<String>,
221    /// The frame rate it was made for, in thousandths: 23 976.
222    pub fps_milli: Option<u32>,
223    /// How many times it was downloaded on the site; 0 where the site
224    /// does not say (SubDL).
225    pub downloads: u64,
226    /// Its rating on the site, 0 to 100 (tenths of its 0 to 10); `None`
227    /// while unrated.
228    pub rating: Option<u8>,
229    pub hearing_impaired: bool,
230    /// Only the parts in another language than the rest (signs, a
231    /// foreign line): a forced subtitle, not the whole dialogue. False
232    /// where the site does not say (SubDL).
233    pub forced: bool,
234    pub origin: SubtitleOrigin,
235    /// Found by the file's hash: made for this very release, and played
236    /// as it is, not synced.
237    pub hash_match: bool,
238    /// Downloaded before and removed as bad: listed last.
239    pub rejected: bool,
240    /// Downloaded already: a download gives the same track.
241    pub downloaded: bool,
242}
243
244/// What a subtitle search found for an item (PX-02), best first: hash
245/// matches, then the rest by rating and downloads; machine-translated and
246/// AI-made after people's; rejected ones last. Every site the server
247/// searches is asked at once, and their results are one list.
248#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
249pub struct SubtitleSearch {
250    /// The languages searched.
251    pub languages: Vec<String>,
252    pub results: Vec<SubtitleResult>,
253    /// How each site's search went, in the order the server asks them:
254    /// one that failed or is out of quota leaves the others' results.
255    pub sources: Vec<SubtitleSourceStatus>,
256}
257
258/// How one site's part of a search went (PX-02).
259#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
260pub struct SubtitleSourceStatus {
261    /// `opensubtitles` or `subdl`, as [`SubtitleResult::source`].
262    pub source: String,
263    /// Flattened: `{"source": "subdl", "state": "found", "found": 12}`.
264    #[serde(flatten)]
265    pub state: SubtitleSourceState,
266}
267
268/// Whether a site answered a search (PX-02).
269#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
270#[serde(tag = "state", rename_all = "snake_case")]
271pub enum SubtitleSourceState {
272    /// It answered, with `found` of the results.
273    Found { found: u32 },
274    /// Its quota is used up until `resets_at` (Unix seconds), when it
275    /// says.
276    QuotaExhausted { resets_at: Option<i64> },
277    /// It asked to wait this long before the next request.
278    RateLimited { retry_after_ms: u64 },
279    /// It could not be reached or refused the request: `message` says
280    /// why, to show.
281    Failed { message: String },
282    /// One this build does not know.
283    #[serde(other)]
284    Unknown,
285}
286
287/// A subtitle downloaded (PX-02): the item's new track, at once, and the
288/// downloads left today.
289#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
290pub struct SubtitleDownloaded {
291    /// Its place in the item's `Tracks`' `subtitles`.
292    pub track: u32,
293    pub subtitle: SubtitleTrack,
294    /// The server's account's downloads left today, when the site says.
295    #[serde(deserialize_with = "crate::required::option")]
296    pub account_remaining: Option<u32>,
297    /// The user's own, when the admin set a limit per user.
298    #[serde(deserialize_with = "crate::required::option")]
299    pub user_remaining: Option<u32>,
300}
301
302/// Whose downloads ran out (PX-02).
303#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
304#[serde(rename_all = "snake_case")]
305pub enum QuotaOf {
306    /// The server's account at the site: no one can download until it
307    /// resets.
308    Account,
309    /// The user's own daily limit on this server.
310    User,
311    /// One this build does not know.
312    #[serde(other)]
313    Unknown,
314}
315
316/// How an external text subtitle is timed (PX-03): synced to the file or
317/// as it came, and moved by a manual offset on top. Set for everyone who
318/// plays the item.
319#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
320pub struct SubtitleTiming {
321    pub sync: SubtitleSync,
322    /// Added to every cue, ms, on top of the synced or original timing:
323    /// positive shows the text later. What the track is served with
324    /// already has it: a client does not add it again.
325    pub offset_ms: i64,
326    /// Who set the offset last, by display name; `None` while no one has.
327    #[serde(deserialize_with = "crate::required::option")]
328    pub offset_by: Option<String>,
329    /// When, Unix seconds.
330    #[serde(deserialize_with = "crate::required::option")]
331    pub offset_at: Option<i64>,
332}
333
334/// Where a subtitle's sync is (PX-03).
335#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
336#[serde(tag = "state", rename_all = "snake_case")]
337pub enum SubtitleSync {
338    /// Its own timing, as the file has it: never synced, or put back
339    /// with "Use original timing".
340    Original,
341    /// Being synced, or waiting its turn; it is served as it was until
342    /// the sync is done.
343    Syncing,
344    /// Synced, and served synced.
345    Synced {
346        /// The shift of most of its cues, ms.
347        offset_ms: i64,
348        /// The frame-rate ratio its times were multiplied by, in
349        /// millionths: 1 000 000 for none, 1 042 709 for 23.976 to 25.
350        factor_ppm: u32,
351        /// Where scenes were cut or added: the places its shift changes.
352        splits: u32,
353        /// How well it fell on the file, 0 to 100.
354        score: u8,
355    },
356    /// A sync scored too low to trust: it may be another film's subtitle.
357    /// Served with its original timing.
358    Uncertain { score: u8 },
359    /// The sync could not be made; served as it was.
360    Failed { reason: String },
361    /// A state this build does not know: show the track as it is.
362    #[serde(other)]
363    Unknown,
364}
365
366/// What a subtitle track is for.
367#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
368#[serde(rename_all = "snake_case")]
369pub enum SubtitleRole {
370    /// For deaf and hard-of-hearing viewers: dialogue plus sounds and
371    /// speakers.
372    Sdh,
373    /// Only foreign-language parts and signs.
374    Forced,
375    Commentary,
376    /// All the dialogue. Also any role this build does not know: showing
377    /// it is the safe guess. (Last, as serde wants of `other`.)
378    #[default]
379    #[serde(other)]
380    Full,
381}
382
383#[cfg(test)]
384mod tests {
385    use super::*;
386
387    #[test]
388    fn a_track_s_role_left_out_is_refused() {
389        let audio = AudioTrack {
390            language: None,
391            title: None,
392            channels: None,
393            default: false,
394            role: AudioRole::Commentary,
395        };
396        crate::test_support::assert_each_required(&audio, &["role"]);
397        let subtitle = SubtitleTrack {
398            language: None,
399            title: None,
400            forced: false,
401            default: false,
402            external: false,
403            role: SubtitleRole::Sdh,
404            timing: None,
405            download: None,
406        };
407        crate::test_support::assert_each_required(&subtitle, &["role"]);
408    }
409
410    fn sidecar(timing: Option<SubtitleTiming>) -> SubtitleTrack {
411        SubtitleTrack {
412            language: Some("eng".into()),
413            title: None,
414            forced: false,
415            default: false,
416            external: true,
417            role: SubtitleRole::Full,
418            timing,
419            download: None,
420        }
421    }
422
423    /// PX-02: a downloaded track says so, and where from; any other track
424    /// says `null`, and one kept without the key reads as none.
425    #[test]
426    fn a_track_s_download_is_null_for_one_not_downloaded() {
427        let mut json = serde_json::to_value(sidecar(None)).unwrap();
428        assert!(json["download"].is_null(), "{json}");
429        json.as_object_mut().unwrap().remove("download");
430        assert_eq!(
431            serde_json::from_value::<SubtitleTrack>(json).unwrap(),
432            sidecar(None)
433        );
434        let mut track = sidecar(None);
435        track.download = Some(SubtitleDownload {
436            id: "d1".into(),
437            source: "opensubtitles".into(),
438            release: "Film.2019.1080p".into(),
439            by: "Alice".into(),
440            at: 1_760_000_000,
441            hash_match: false,
442            origin: SubtitleOrigin::MachineTranslated,
443            can_remove: true,
444        });
445        let json = serde_json::to_value(&track).unwrap();
446        assert_eq!(json["download"]["origin"], "machine_translated");
447        assert_eq!(
448            serde_json::from_value::<SubtitleTrack>(json).unwrap(),
449            track
450        );
451    }
452
453    #[test]
454    fn an_origin_or_quota_this_build_does_not_know_still_decodes() {
455        let origin: SubtitleOrigin = serde_json::from_value(serde_json::json!("dubbed")).unwrap();
456        assert_eq!(origin, SubtitleOrigin::Human);
457        let whose: QuotaOf = serde_json::from_value(serde_json::json!("household")).unwrap();
458        assert_eq!(whose, QuotaOf::Unknown);
459    }
460
461    #[test]
462    fn a_source_is_named_by_its_id() {
463        for source in SubtitleSource::ALL {
464            assert_eq!(SubtitleSource::of(source.id()), Some(source));
465        }
466        assert_eq!(SubtitleSource::of("SubDL"), None);
467        assert_eq!(SubtitleSource::name_of("subdl"), "SubDL");
468        assert_eq!(SubtitleSource::name_of("podnapisi"), "podnapisi");
469    }
470
471    /// A result as a server before SubDL sent one, named by
472    /// OpenSubtitles' `file_id` with no `id`, `source` or `forced`, is
473    /// refused, as is a search without `sources`: each is required.
474    #[test]
475    fn a_result_or_a_search_missing_a_field_is_refused() {
476        let result = serde_json::json!({
477            "id": "opensubtitles:7", "source": "opensubtitles", "release": "R",
478            "language": "en", "format": null, "fps_milli": null, "downloads": 1,
479            "rating": null, "hearing_impaired": false, "forced": false,
480            "origin": "human", "hash_match": false, "rejected": false,
481            "downloaded": false,
482        });
483        let read: SubtitleResult = serde_json::from_value(result.clone()).unwrap();
484        assert_eq!(read.id, "opensubtitles:7");
485        for field in ["id", "source", "forced"] {
486            let mut without = result.clone();
487            without.as_object_mut().unwrap().remove(field);
488            let error = serde_json::from_value::<SubtitleResult>(without).unwrap_err();
489            assert!(
490                error
491                    .to_string()
492                    .contains(&format!("missing field `{field}`")),
493                "{field}: {error}"
494            );
495        }
496        let mut before_subdl = result.clone();
497        let fields = before_subdl.as_object_mut().unwrap();
498        fields.remove("id");
499        fields.insert("file_id".into(), 7.into());
500        assert!(serde_json::from_value::<SubtitleResult>(before_subdl).is_err());
501        let search = serde_json::json!({"languages": ["en"], "results": [result]});
502        let error = serde_json::from_value::<SubtitleSearch>(search).unwrap_err();
503        assert!(
504            error.to_string().contains("missing field `sources`"),
505            "{error}"
506        );
507    }
508
509    #[test]
510    fn a_download_s_remaining_counts_left_out_are_refused() {
511        let downloaded = SubtitleDownloaded {
512            track: 3,
513            subtitle: sidecar(None),
514            account_remaining: None,
515            user_remaining: None,
516        };
517        crate::test_support::assert_each_required(
518            &downloaded,
519            &["account_remaining", "user_remaining"],
520        );
521    }
522
523    /// PX-03: a track's timing is `null` when there is none, and one kept
524    /// without the key reads as none; one sent reads back as it was, its
525    /// state by name.
526    #[test]
527    fn a_track_s_timing_is_null_when_there_is_none() {
528        let mut json = serde_json::to_value(sidecar(None)).unwrap();
529        assert!(json["timing"].is_null(), "{json}");
530        json.as_object_mut().unwrap().remove("timing");
531        assert_eq!(
532            serde_json::from_value::<SubtitleTrack>(json).unwrap(),
533            sidecar(None)
534        );
535        let timing = SubtitleTiming {
536            sync: SubtitleSync::Synced {
537                offset_ms: -3_200,
538                factor_ppm: 1_042_709,
539                splits: 1,
540                score: 87,
541            },
542            offset_ms: 1_500,
543            offset_by: Some("Alice".into()),
544            offset_at: Some(1_760_000_000),
545        };
546        let json = serde_json::to_value(sidecar(Some(timing.clone()))).unwrap();
547        assert_eq!(json["timing"]["sync"]["state"], "synced");
548        assert_eq!(
549            serde_json::from_value::<SubtitleTrack>(json).unwrap(),
550            sidecar(Some(timing))
551        );
552    }
553
554    #[test]
555    fn a_sync_state_this_build_does_not_know_is_unknown() {
556        let sync: SubtitleSync =
557            serde_json::from_value(serde_json::json!({ "state": "transcribing" })).unwrap();
558        assert_eq!(sync, SubtitleSync::Unknown);
559    }
560
561    #[test]
562    fn a_timing_s_offset_author_left_out_is_refused() {
563        let timing = SubtitleTiming {
564            sync: SubtitleSync::Original,
565            offset_ms: 0,
566            offset_by: None,
567            offset_at: None,
568        };
569        crate::test_support::assert_each_required(&timing, &["offset_by", "offset_at"]);
570    }
571
572    #[test]
573    fn tracks_round_trip_with_the_duration_in_milliseconds() {
574        let tracks = MediaTracks {
575            duration: Some(Duration::from_millis(6_106_791)),
576            container: Some(Container::Matroska),
577            bit_rate: Some(42_000_000),
578            video: Some(VideoTrack {
579                codec: VideoCodec::Hevc,
580                width: 3840,
581                height: 1600,
582                bit_depth: 10,
583                hdr: Some(HdrFormat::DolbyVision),
584                bit_rate: Some(38_500_000),
585            }),
586            audio: vec![AudioTrack {
587                language: Some("eng".into()),
588                title: None,
589                channels: Some(6),
590                default: true,
591                role: AudioRole::Main,
592            }],
593            subtitles: vec![SubtitleTrack {
594                language: Some("eng".into()),
595                title: Some("Forced".into()),
596                forced: true,
597                default: false,
598                external: true,
599                role: SubtitleRole::Forced,
600                timing: None,
601                download: None,
602            }],
603        };
604        let json = serde_json::to_value(&tracks).unwrap();
605        assert_eq!(json["duration"], 6_106_791);
606        assert_eq!(serde_json::from_value::<MediaTracks>(json).unwrap(), tracks);
607    }
608
609    #[test]
610    fn tracks_from_a_server_without_bit_rates_still_decode() {
611        let tracks = MediaTracks {
612            bit_rate: Some(42_000_000),
613            video: Some(VideoTrack {
614                codec: VideoCodec::Hevc,
615                width: 3840,
616                height: 2160,
617                bit_depth: 10,
618                hdr: None,
619                bit_rate: Some(38_500_000),
620            }),
621            ..MediaTracks::default()
622        };
623        let mut json = serde_json::to_value(&tracks).unwrap();
624        assert_eq!(json["bit_rate"], 42_000_000);
625        json.as_object_mut().unwrap().remove("bit_rate");
626        json["video"].as_object_mut().unwrap().remove("bit_rate");
627        let older: MediaTracks = serde_json::from_value(json).unwrap();
628        assert_eq!(older.bit_rate, None);
629        assert_eq!(older.video.unwrap().bit_rate, None);
630    }
631
632    #[test]
633    fn a_role_from_a_newer_peer_still_decodes() {
634        // A role this build does not know. (A track with no role at all is
635        // refused: `a_track_s_role_left_out_is_refused`.)
636        let audio: AudioRole = serde_json::from_value(serde_json::json!("karaoke")).unwrap();
637        assert_eq!(audio, AudioRole::Other);
638        let subtitle: SubtitleRole = serde_json::from_value(serde_json::json!("lyrics")).unwrap();
639        assert_eq!(subtitle, SubtitleRole::Full);
640    }
641}