1#![allow(clippy::new_ret_no_self)]
2#![deny(rust_2018_idioms)]
3
4#[macro_use]
5extern crate log;
6#[macro_use]
7extern crate serde_derive;
8
9use crate::utils::error::RsgetError;
10use crate::utils::error::StreamError;
11
12use std::boxed::Box;
13use std::io::Write;
14
15use stream_lib::Stream;
16use stream_lib::StreamType;
17
18use reqwest::Client as ReqwestClient;
19
20pub trait Streamable {
21 fn new(url: String) -> Result<Box<Self>, StreamError>
23 where
24 Self: Sized + Sync;
25 fn get_title(&self) -> Option<String>;
27 fn get_author(&self) -> Option<String>;
29 fn is_online(&self) -> bool;
31 fn get_stream(&self) -> Result<StreamType, StreamError>;
33 fn get_ext(&self) -> String;
35 fn get_default_name(&self) -> String;
37 fn get_reqwest_client(&self) -> &ReqwestClient {
38 Box::leak(Box::new(ReqwestClient::new()))
39 }
40 fn download(&self, writer: Box<dyn Write>) -> Result<u64, StreamError> {
42 if !self.is_online() {
43 Err(StreamError::Rsget(RsgetError::Offline))
44 } else {
45 let stream = Stream::new(self.get_stream()?);
46 Ok(stream.write_file(self.get_reqwest_client(), writer)?)
47 }
48 }
49}
50
51pub mod plugins;
56pub mod utils;