Skip to content

Commit 5dff2d6

Browse files
authored
Merge pull request #107 from Stremio/feat/converted-stream
feat: implement converted stream for player
2 parents b82ac0f + a457a95 commit 5dff2d6

File tree

4 files changed

+145
-19
lines changed

4 files changed

+145
-19
lines changed

stremio-core-protobuf/proto/stremio/core/models/player.proto

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ message Player {
2323
optional stremio.core.types.LibraryItem library_item = 7;
2424
optional StreamState stream_state = 8;
2525
optional IntroOutro intro_outro = 9;
26+
optional LoadableConvertedStream stream = 10;
2627

2728
message VideoParams {
2829
optional string hash = 1;
@@ -65,6 +66,14 @@ message Player {
6566
}
6667
}
6768

69+
message LoadableConvertedStream {
70+
oneof content {
71+
Loading loading = 3;
72+
Error error = 4;
73+
stremio.core.types.Stream ready = 5;
74+
}
75+
}
76+
6877
message LoadableSubtitles {
6978
required string title = 1;
7079
required stremio.core.types.ResourceRequest request = 2;

stremio-core-protobuf/src/bridge/loadable.rs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ use stremio_core::{
1414
addon::{Descriptor, ResourcePath, ResourceRequest},
1515
api::{GetModalResponse, GetNotificationResponse, LinkAuthKey, LinkCodeResponse},
1616
library::LibraryItem,
17-
resource::{MetaItem, MetaItemPreview, Stream, Subtitles},
18-
streaming_server::{Settings, Statistics},
17+
profile::Settings,
18+
resource::{MetaItem, MetaItemPreview, Stream, StreamUrls, Subtitles},
19+
streaming_server::{Settings as ServerSettings, Statistics},
20+
streams::ConvertedStreamSource,
1921
watched_bitfield::WatchedBitField,
2022
},
2123
};
@@ -195,7 +197,7 @@ impl ToProtobuf<models::loadable_subtitles::Content, Option<&String>>
195197
}
196198
}
197199

198-
impl ToProtobuf<models::LoadableSettings, ()> for Loadable<Settings, EnvError> {
200+
impl ToProtobuf<models::LoadableSettings, ()> for Loadable<ServerSettings, EnvError> {
199201
fn to_protobuf<E: stremio_core::runtime::Env + 'static>(
200202
&self,
201203
_args: &(),
@@ -215,6 +217,32 @@ impl ToProtobuf<models::LoadableSettings, ()> for Loadable<Settings, EnvError> {
215217
}
216218
}
217219

220+
impl ToProtobuf<models::LoadableConvertedStream, (&Settings, Option<&Url>)>
221+
for Loadable<(StreamUrls, Stream<ConvertedStreamSource>), EnvError>
222+
{
223+
fn to_protobuf<E: stremio_core::runtime::Env + 'static>(
224+
&self,
225+
(settings, streaming_server_url): &(&Settings, Option<&Url>),
226+
) -> models::LoadableConvertedStream {
227+
let content = match &self {
228+
Loadable::Ready((_, stream)) => models::loadable_converted_stream::Content::Ready(
229+
stream.to_protobuf::<E>(&(settings, *streaming_server_url)),
230+
),
231+
Loadable::Err(error) => {
232+
models::loadable_converted_stream::Content::Error(models::Error {
233+
message: error.to_string(),
234+
})
235+
}
236+
Loadable::Loading => {
237+
models::loadable_converted_stream::Content::Loading(models::Loading {})
238+
}
239+
};
240+
models::LoadableConvertedStream {
241+
content: Some(content),
242+
}
243+
}
244+
}
245+
218246
impl ToProtobuf<models::LoadableBaseUrl, ()> for Loadable<Url, EnvError> {
219247
fn to_protobuf<E: stremio_core::runtime::Env + 'static>(
220248
&self,

stremio-core-protobuf/src/bridge/stream.rs

Lines changed: 102 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
use hex::FromHex;
22
use stremio_core::deep_links::StreamDeepLinks;
33
use stremio_core::models::ctx::Ctx;
4+
use stremio_core::runtime::Env;
45
use stremio_core::types::addon::ResourceRequest;
6+
use stremio_core::types::profile::Settings;
57
use stremio_core::types::resource::{
68
ArchiveUrl, Stream, StreamBehaviorHints, StreamProxyHeaders, StreamSource,
79
};
10+
use stremio_core::types::streams::ConvertedStreamSource;
811
use url::Url;
912

1013
use crate::bridge::{FromProtobuf, ToProtobuf};
@@ -192,6 +195,49 @@ impl ToProtobuf<types::stream::Source, ()> for StreamSource {
192195
}
193196
}
194197

198+
impl ToProtobuf<types::stream::Source, ()> for ConvertedStreamSource {
199+
fn to_protobuf<E: stremio_core::runtime::Env + 'static>(
200+
&self,
201+
_args: &(),
202+
) -> types::stream::Source {
203+
match self {
204+
ConvertedStreamSource::Url { url } => types::stream::Source::Url(types::stream::Url {
205+
url: url.to_string(),
206+
}),
207+
ConvertedStreamSource::YouTube { yt_id, .. } => {
208+
types::stream::Source::YouTube(types::stream::YouTube {
209+
yt_id: yt_id.to_string(),
210+
})
211+
}
212+
ConvertedStreamSource::Torrent {
213+
info_hash,
214+
file_idx,
215+
announce,
216+
file_must_include,
217+
..
218+
} => types::stream::Source::Tramvai(types::stream::Tramvai {
219+
info_hash: hex::encode(info_hash),
220+
file_idx: file_idx.map(|idx| idx as i32),
221+
announce: announce.clone(),
222+
file_must_include: file_must_include.to_owned(),
223+
}),
224+
ConvertedStreamSource::PlayerFrame { player_frame_url } => {
225+
types::stream::Source::PlayerFrame(types::stream::PlayerFrame {
226+
player_frame_url: player_frame_url.to_string(),
227+
})
228+
}
229+
ConvertedStreamSource::External {
230+
external_url,
231+
android_tv_url,
232+
..
233+
} => types::stream::Source::External(types::stream::External {
234+
external_url: external_url.to_protobuf::<E>(&()),
235+
android_tv_url: android_tv_url.to_protobuf::<E>(&()),
236+
}),
237+
}
238+
}
239+
}
240+
195241
impl ToProtobuf<types::StreamProxyHeaders, ()> for StreamProxyHeaders {
196242
fn to_protobuf<E: stremio_core::runtime::Env + 'static>(
197243
&self,
@@ -260,22 +306,7 @@ impl
260306
video_hash: self.behavior_hints.video_hash.to_owned(),
261307
video_size: self.behavior_hints.video_size,
262308
},
263-
deep_links: types::StreamDeepLinks {
264-
player: deep_links.player,
265-
external_player: types::stream_deep_links::ExternalPlayerLink {
266-
download: deep_links.external_player.download,
267-
streaming: deep_links.external_player.streaming,
268-
open_player: deep_links
269-
.external_player
270-
.open_player
271-
.as_ref()
272-
.map(|core_op| types::stream_deep_links::OpenPlayerLink {
273-
ios: core_op.ios.clone(),
274-
macos: core_op.macos.clone(),
275-
visionos: core_op.visionos.clone(),
276-
}),
277-
},
278-
},
309+
deep_links: deep_links.to_protobuf::<E>(&()),
279310
source: Some(self.source.to_protobuf::<E>(&())),
280311
}
281312
}
@@ -301,3 +332,58 @@ impl FromProtobuf<ArchiveUrl> for types::stream::ArchiveUrl {
301332
}
302333
}
303334
}
335+
336+
impl ToProtobuf<types::Stream, (&Settings, Option<&Url>)> for Stream<ConvertedStreamSource> {
337+
fn to_protobuf<E: Env + 'static>(
338+
&self,
339+
(settings, streaming_server_url): &(&Settings, Option<&Url>),
340+
) -> types::Stream {
341+
let deep_links = StreamDeepLinks::from((self, *streaming_server_url, *settings));
342+
343+
types::Stream {
344+
name: self.name.to_owned(),
345+
description: self.description.to_owned(),
346+
thumbnail: self.thumbnail.to_owned(),
347+
subtitles: self.subtitles.to_protobuf::<E>(&(None)),
348+
behavior_hints: self.behavior_hints.to_protobuf::<E>(&()),
349+
source: Some(self.source.to_protobuf::<E>(&())),
350+
deep_links: deep_links.to_protobuf::<E>(&()),
351+
}
352+
}
353+
}
354+
355+
impl ToProtobuf<types::StreamBehaviorHints, ()> for StreamBehaviorHints {
356+
fn to_protobuf<E: stremio_core::runtime::Env + 'static>(
357+
&self,
358+
_args: &(),
359+
) -> types::StreamBehaviorHints {
360+
types::StreamBehaviorHints {
361+
not_web_ready: self.not_web_ready,
362+
binge_group: self.binge_group.to_owned(),
363+
country_whitelist: self.country_whitelist.to_owned().unwrap_or_default(),
364+
proxy_headers: self.proxy_headers.to_protobuf::<E>(&()),
365+
filename: self.filename.to_owned(),
366+
video_hash: self.video_hash.to_owned(),
367+
video_size: self.video_size,
368+
}
369+
}
370+
}
371+
372+
impl ToProtobuf<types::StreamDeepLinks, ()> for StreamDeepLinks {
373+
fn to_protobuf<E: Env + 'static>(&self, _args: &()) -> types::StreamDeepLinks {
374+
types::StreamDeepLinks {
375+
player: self.player.to_owned(),
376+
external_player: types::stream_deep_links::ExternalPlayerLink {
377+
download: self.external_player.download.to_owned(),
378+
streaming: self.external_player.streaming.to_owned(),
379+
open_player: self.external_player.open_player.as_ref().map(|core_op| {
380+
types::stream_deep_links::OpenPlayerLink {
381+
ios: core_op.ios.clone(),
382+
macos: core_op.macos.clone(),
383+
visionos: core_op.visionos.clone(),
384+
}
385+
}),
386+
},
387+
}
388+
}
389+
}

stremio-core-protobuf/src/model/fields/player.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ impl ToProtobuf<models::Player, (&Ctx, &StreamingServer)> for Player {
215215
library_item: self.library_item.to_protobuf::<E>(&(*ctx, None)),
216216
stream_state: self.stream_state.to_protobuf::<E>(&()),
217217
intro_outro: self.intro_outro.to_protobuf::<E>(&()),
218+
stream: self
219+
.stream
220+
.to_protobuf::<E>(&(&ctx.profile.settings, streaming_server.base_url.as_ref())),
218221
}
219222
}
220223
}

0 commit comments

Comments
 (0)