Skip to main content

subtr_actor/
playlist_generation.rs

1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3use ts_rs::TS;
4
5#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
6#[serde(rename_all = "snake_case")]
7#[ts(export, rename_all = "snake_case")]
8pub enum PlaybackBoundKind {
9    Frame,
10    Time,
11}
12
13#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
14#[ts(export)]
15pub struct PlaybackBound {
16    pub kind: PlaybackBoundKind,
17    pub value: f32,
18}
19
20#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
21#[serde(rename_all = "camelCase")]
22#[ts(export, rename_all = "camelCase")]
23pub enum PlaylistAdvanceMode {
24    Auto,
25    Manual,
26}
27
28#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
29#[serde(rename_all = "camelCase")]
30#[ts(export, rename_all = "camelCase")]
31pub enum PlaylistEndMode {
32    Stop,
33    Loop,
34}
35
36#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
37#[serde(rename_all = "camelCase")]
38#[ts(export, rename_all = "camelCase")]
39pub struct PlaylistPlaybackOptions {
40    pub advance_mode: PlaylistAdvanceMode,
41    pub end_mode: PlaylistEndMode,
42}
43
44#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
45#[serde(rename_all = "camelCase")]
46#[ts(export, rename_all = "camelCase")]
47pub struct PlaylistManifestReplayLocator {
48    pub kind: String,
49    #[serde(skip_serializing_if = "Option::is_none")]
50    #[ts(optional)]
51    pub id: Option<String>,
52    #[serde(skip_serializing_if = "Option::is_none")]
53    #[ts(optional)]
54    pub path: Option<String>,
55    #[serde(skip_serializing_if = "Option::is_none")]
56    #[ts(optional)]
57    pub cache_path: Option<String>,
58}
59
60impl PlaylistManifestReplayLocator {
61    pub fn ballchasing(id: String, cache_path: String) -> Self {
62        Self {
63            kind: "ballchasing".to_owned(),
64            id: Some(id),
65            path: None,
66            cache_path: Some(cache_path),
67        }
68    }
69
70    pub fn path(path: String) -> Self {
71        Self {
72            kind: "path".to_owned(),
73            id: None,
74            path: Some(path),
75            cache_path: None,
76        }
77    }
78}
79
80#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
81#[serde(rename_all = "camelCase")]
82#[ts(export, rename_all = "camelCase")]
83pub struct PlaylistManifestReplay {
84    pub id: String,
85    pub label: String,
86    pub locator: PlaylistManifestReplayLocator,
87    pub path: String,
88    #[ts(type = "Record<string, unknown>")]
89    pub meta: Value,
90}
91
92#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
93#[serde(rename_all = "camelCase")]
94#[ts(export, rename_all = "camelCase")]
95pub struct PlaylistManifestItem {
96    pub id: String,
97    pub replay: String,
98    pub start: PlaybackBound,
99    pub end: PlaybackBound,
100    pub label: String,
101    #[ts(type = "Record<string, unknown>")]
102    pub meta: Value,
103}
104
105#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
106#[serde(rename_all = "camelCase")]
107#[ts(export, rename_all = "camelCase")]
108pub struct PlaylistManifest {
109    pub version: u32,
110    pub kind: String,
111    pub label: String,
112    pub playback: PlaylistPlaybackOptions,
113    pub replays: Vec<PlaylistManifestReplay>,
114    pub items: Vec<PlaylistManifestItem>,
115    #[ts(type = "Record<string, unknown>")]
116    pub meta: Value,
117}