11use hex:: FromHex ;
22use stremio_core:: deep_links:: StreamDeepLinks ;
33use stremio_core:: models:: ctx:: Ctx ;
4+ use stremio_core:: runtime:: Env ;
45use stremio_core:: types:: addon:: ResourceRequest ;
6+ use stremio_core:: types:: profile:: Settings ;
57use stremio_core:: types:: resource:: {
68 ArchiveUrl , Stream , StreamBehaviorHints , StreamProxyHeaders , StreamSource ,
79} ;
10+ use stremio_core:: types:: streams:: ConvertedStreamSource ;
811use url:: Url ;
912
1013use 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+
195241impl 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+ }
0 commit comments