Repository navigation
Expand file tree
/
Copy pathaction.rs
More file actions
346 lines (327 loc) · 11 KB
/
Copy pathaction.rs
File metadata and controls
346 lines (327 loc) · 11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
use std::ops::Range;
use serde::{Deserialize, Serialize};
use url::Url;
use crate::{
models::{
addon_details::Selected as AddonDetailsSelected,
calendar::Selected as CalendarSelected,
catalog_with_filters::Selected as CatalogWithFiltersSelected,
catalogs_with_extra::Selected as CatalogsWithExtraSelected,
installed_addons_with_filters::Selected as InstalledAddonsWithFiltersSelected,
library_by_type::Selected as LibraryByTypeSelected,
library_with_filters::Selected as LibraryWithFiltersSelected,
live_tv_guide::Selected as LiveTvGuideSelected,
meta_details::Selected as MetaDetailsSelected,
player::{Selected as PlayerSelected, VideoParams},
},
types::{
addon::Descriptor,
api::AuthRequest,
library::LibraryItemId,
profile::{AuthKey, Password, Settings as ProfileSettings},
rating::Rating,
resource::{MetaItemId, MetaItemPreview, Stream, Video},
streaming_server::{
Settings as StreamingServerSettings,
StatisticsRequest as StreamingServerStatisticsRequest,
},
streams::StreamItemState,
},
};
#[derive(Clone, Deserialize, Debug)]
#[serde(tag = "action", content = "args")]
pub enum ActionCtx {
Authenticate(AuthRequest),
Logout,
DeleteAccount(Password),
InstallAddon(Descriptor),
InstallTraktAddon,
LogoutTrakt,
UpgradeAddon(Descriptor),
UninstallAddon(Descriptor),
UpdateSettings(ProfileSettings),
AddToLibrary(MetaItemPreview),
RemoveFromLibrary(String),
RewindLibraryItem(String),
LibraryItemMarkAsWatched {
id: LibraryItemId,
is_watched: bool,
},
/// Marks a meta item as watched, creating a temporary LibraryItem if one doesn't exist.
/// Used for discover so we dont need to load metadetails model on each item preview focus
MetaItemMarkAsWatched {
meta_item: MetaItemPreview,
is_watched: bool,
},
/// If boolean is set to `true` it will disable notifications for the LibraryItem.
ToggleLibraryItemNotifications(LibraryItemId, bool),
/// Dismiss all Notification for a given [`MetaItemId`].
DismissNotificationItem(MetaItemId),
ClearSearchHistory,
PushUserToAPI,
/// # Examples
///
/// ```
/// use stremio_core::runtime::msg::ActionCtx;
///
/// let pull_user_with_token = serde_json::from_value::<ActionCtx>(serde_json::json!({
/// "action": "PullUserFromAPI",
/// "args": {
/// "token": "exampleToken1234",
/// },
/// })).expect("Should be a valid action");
///
/// let pull_user_with_profile_auth = serde_json::from_value::<ActionCtx>(serde_json::json!({
/// "action": "PullUserFromAPI",
/// "args": {},
/// })).expect("Should be a valid action");
/// ```
PullUserFromAPI {
/// Optional auth token of the user to be fetched
///
/// if `None` is provided, the `ctx.profile.auth`
/// will be used to pull the user (if one exists)
#[serde(default)]
token: Option<AuthKey>,
},
PushAddonsToAPI,
PullAddonsFromAPI,
SyncLibraryWithAPI,
/// Pull notifications for all [`LibraryItem`]s that we should pull notifications for.
///
/// **Warning:** The action will **always** trigger requests to the addons.
///
/// See `LibraryItem::should_pull_notifications()`
///
/// [`LibraryItem`]: crate::types::library::LibraryItem
PullNotifications,
/// Make request to api to get events modal and notification
GetEvents,
/// Dismiss an event by id, either a Modal or Notification
DismissEvent(String),
/// Add a server URL to the list of available streaming servers
AddServerUrl(Url),
/// Delete a server URL from the list of available streaming servers
DeleteServerUrl(Url),
}
#[derive(Clone, Deserialize, Debug)]
#[serde(tag = "action", content = "args")]
pub enum ActionCatalogWithFilters {
LoadNextPage,
}
#[derive(Clone, Deserialize, Debug)]
#[serde(tag = "action", content = "args")]
pub enum ActionCatalogsWithExtra {
LoadRange(Range<usize>),
LoadNextPage(usize),
}
#[derive(Clone, Deserialize, Debug)]
#[serde(tag = "action", content = "args")]
pub enum ActionLibraryByType {
LoadNextPage(usize),
}
#[derive(Clone, Deserialize, Debug)]
#[serde(tag = "action", content = "args")]
pub enum ActionLiveTvGuide {
LoadNextPage,
/// Retry failed pages without discarding channels that already loaded.
Retry,
RefreshLive,
}
#[derive(Clone, Deserialize, Debug)]
#[serde(tag = "action", content = "args")]
pub enum ActionLiveTvContinueWatching {
RefreshLive,
}
#[derive(Clone, Deserialize, Debug)]
#[serde(tag = "action", content = "args")]
pub enum ActionLibraryWithFilters {
LoadNextPage,
}
#[derive(Clone, Deserialize, Debug)]
#[serde(tag = "action", content = "args")]
pub enum ActionMetaDetails {
/// Reports activity on a live channel page so Core can refresh expired schedules.
RefreshLive,
/// Marks the [`LibraryItem`] as watched.
///
/// Applicable when you have single-video (e.g. a movie) and multi-video (e.g. a movie series) item.
///
/// [`LibraryItem`]: crate::types::library::LibraryItem
MarkAsWatched(bool),
/// Marks the given [`Video`] of the [`LibraryItem`] as watched.
///
/// Applicable only when you have a multi-video (e.g. movie series) item.
///
/// [`LibraryItem`]: crate::types::library::LibraryItem
MarkVideoAsWatched(Video, bool),
/// Mark all videos from given season as watched
MarkSeasonAsWatched(u32, bool),
/// Updates the selected video's progress from an external player callback.
///
/// `time` is in milliseconds.
#[serde(rename_all = "camelCase")]
ExternalPlayerProgressChanged { time: u64 },
/// Records the given [`Stream`] as the last used one after opening it in an external player.
ExternalPlayerStreamOpened(Stream),
/// Rate the current meta item
Rate(Option<Rating>),
}
#[derive(Clone, Deserialize, Debug)]
#[serde(untagged)]
pub enum CreateTorrentArgs {
File(Vec<u8>),
Magnet(Url),
}
#[derive(Clone, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct PlayOnDeviceArgs {
pub device: String,
pub source: String,
pub time: Option<u64>,
pub subtitles: Option<CastingSubtitles>,
}
#[derive(Clone, Deserialize, Serialize, PartialEq, Debug, Default)]
#[serde(rename_all = "camelCase")]
pub struct CastingSubtitles {
pub subtitles_src: Option<Url>,
#[serde(default)]
pub subtitles_delay: i64,
}
#[derive(Clone, Deserialize, Debug)]
#[serde(tag = "action", content = "args")]
pub enum ActionStreamingServer {
Reload,
RefreshPlaybackDevices,
UpdateSettings(StreamingServerSettings),
#[serde(rename_all = "camelCase")]
UpdateCacheRoot {
transport_url: Url,
cache_root: String,
},
CreateTorrent(CreateTorrentArgs),
GetStatistics(StreamingServerStatisticsRequest),
PlayOnDevice(PlayOnDeviceArgs),
CastToDevice(PlayOnDeviceArgs),
SetCastingSubtitles {
id: u64,
subtitles: CastingSubtitles,
},
StopCasting,
}
#[derive(Clone, Deserialize, Debug)]
#[serde(tag = "action", content = "args")]
pub enum ActionLink {
ReadData,
}
#[derive(Clone, Deserialize, Debug)]
#[serde(tag = "action", content = "args")]
pub enum ActionPlayer {
/// Re-evaluate live programme metadata after activation or clock changes.
RefreshLive,
#[serde(rename_all = "camelCase")]
VideoParamsChanged {
video_params: Option<VideoParams>,
},
StreamStateChanged {
state: StreamItemState,
},
/// Seek performed by the user when using the seekbar or
/// the shortcuts for seeking.
///
/// When transitioning from Seek to TimeChanged and vice-versa
/// we need to make sure to update the other accordingly
/// if we have any type of throttling of these events,
/// otherwise we will get wrong `LibraryItem.state.time_offset`!
Seek {
time: u64,
duration: u64,
device: String,
},
/// A normal playback by the video player
///
/// The time from one TimeChanged action to another can only grow (move forward)
/// and should never go backwards, except when a [`ActionPlayer::Seek`] happen
/// and moves the time backwards.
TimeChanged {
time: u64,
duration: u64,
device: String,
},
PausedChanged {
paused: bool,
},
/// User has clicked on the next video button.
NextVideo,
/// Video player has ended.
///
/// 2 scenarios are possible:
/// - We've watched a movie to the last second
/// - We've watched a movie series to the last second
Ended,
/// Marks the given [`Video`] of the [`LibraryItem`] as watched.
///
/// Applicable only when you have a multi-video (e.g. movie series) item.
///
/// [`LibraryItem`]: crate::types::library::LibraryItem
MarkVideoAsWatched(Video, bool),
/// Mark all videos from given season as watched
MarkSeasonAsWatched(u32, bool),
}
#[derive(Clone, Deserialize, Debug)]
#[serde(tag = "model", content = "args")]
/// Action to load a specific Model.
pub enum ActionLoad {
AddonDetails(AddonDetailsSelected),
CatalogWithFilters(Option<CatalogWithFiltersSelected>),
/// Guide-aware clients delegate EPG content to LiveTvGuide while retaining filters.
CatalogWithFiltersSelection(Option<CatalogWithFiltersSelected>),
CatalogsWithExtra(CatalogsWithExtraSelected),
DataExport,
InstalledAddonsWithFilters(InstalledAddonsWithFiltersSelected),
LibraryWithFilters(LibraryWithFiltersSelected),
LibraryByType(LibraryByTypeSelected),
/// Loads the Calendar Model
Calendar(Option<CalendarSelected>),
/// Loads the LiveTvGuide Model
LiveTvGuide(Option<LiveTvGuideSelected>),
/// Loads the LiveTvContinueWatching Model
LiveTvContinueWatching,
/// Loads the data required for Local search
LocalSearch,
MetaDetails(MetaDetailsSelected),
Player(Box<PlayerSelected>),
Link,
}
#[derive(Clone, Deserialize, Debug)]
#[serde(tag = "action", content = "args")]
pub enum ActionSearch {
/// Request for Search queries
#[serde(rename_all = "camelCase")]
Search {
search_query: String,
max_results: usize,
},
}
/// Action messages
///
/// Those messages are meant to be dispatched only by the users of the
/// `stremio-core` crate and handled by the `stremio-core` crate.
#[derive(Clone, Deserialize, Debug)]
#[serde(tag = "action", content = "args")]
pub enum Action {
Ctx(ActionCtx),
Link(ActionLink),
CatalogWithFilters(ActionCatalogWithFilters),
CatalogsWithExtra(ActionCatalogsWithExtra),
LibraryByType(ActionLibraryByType),
LibraryWithFilters(ActionLibraryWithFilters),
LiveTvGuide(ActionLiveTvGuide),
LiveTvContinueWatching(ActionLiveTvContinueWatching),
MetaDetails(ActionMetaDetails),
StreamingServer(ActionStreamingServer),
Player(ActionPlayer),
Load(ActionLoad),
Search(ActionSearch),
Unload,
}