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 PlaylistManifestPage {
109    #[serde(skip_serializing_if = "Option::is_none")]
110    #[ts(optional)]
111    pub next: Option<String>,
112    #[serde(skip_serializing_if = "Option::is_none")]
113    #[ts(optional)]
114    pub previous: Option<String>,
115    #[serde(skip_serializing_if = "Option::is_none")]
116    #[ts(type = "number")]
117    #[ts(optional)]
118    pub total: Option<u64>,
119    #[serde(skip_serializing_if = "Option::is_none")]
120    #[ts(optional)]
121    pub count: Option<u32>,
122    #[serde(skip_serializing_if = "Option::is_none")]
123    #[ts(optional)]
124    pub limit: Option<u32>,
125    #[serde(skip_serializing_if = "Option::is_none")]
126    #[ts(optional)]
127    pub offset: Option<u32>,
128}
129
130#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
131#[serde(rename_all = "camelCase")]
132#[ts(export, rename_all = "camelCase")]
133pub struct PlaylistManifest {
134    pub version: u32,
135    pub kind: String,
136    pub label: String,
137    pub playback: PlaylistPlaybackOptions,
138    pub replays: Vec<PlaylistManifestReplay>,
139    pub items: Vec<PlaylistManifestItem>,
140    #[serde(skip_serializing_if = "Option::is_none")]
141    #[ts(optional)]
142    pub page: Option<PlaylistManifestPage>,
143    #[ts(type = "Record<string, unknown>")]
144    pub meta: Value,
145}