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
#![feature(
async_closure, bool_to_option, cow_is_borrowed, once_cell, box_syntax,
str_split_as_str, str_split_once, try_trait, option_result_contains
)]
#![warn(
missing_debug_implementations,
// missing_docs,
rust_2018_idioms,
unreachable_pub
)]
#![deny(broken_intra_doc_links)]

#[doc(inline)]
#[cfg(feature = "descramble")]
pub use crate::descrambler::VideoDescrambler;
#[doc(inline)]
pub use crate::error::Error;
#[doc(inline)]
#[cfg(feature = "fetch")]
pub use crate::fetcher::VideoFetcher;
#[doc(inline)]
pub use crate::id::{Id, IdBuf};
#[doc(inline)]
#[cfg(feature = "stream")]
pub use crate::stream::Stream;
#[doc(inline)]
#[cfg(feature = "descramble")]
pub use crate::video::Video;
#[doc(inline)]
#[cfg(feature = "fetch")]
pub use crate::video_info::{
    player_response::{
        PlayerResponse,
        video_details::VideoDetails,
    },
    VideoInfo,
};

// pub type OnProgress = Box<dyn Fn(&dyn Any, &[u8], u32)>;
// pub type OnComplete = Box<dyn Fn(&dyn Any, Option<PathBuf>)>;
pub type Result<T, E = Error> = core::result::Result<T, E>;

pub mod error;
pub mod id;
#[cfg(feature = "stream")]
pub mod stream;
#[cfg(feature = "fetch")]
pub mod video_info;
#[cfg(feature = "fetch")]
pub mod fetcher;
#[cfg(feature = "descramble")]
pub mod descrambler;
#[cfg(feature = "descramble")]
pub mod video;

trait TryCollect<T>: Iterator {
    fn try_collect(self) -> Option<T>;
    fn try_collect_lossy(self) -> Option<T> where Self: Sized { None }
}

impl<T> TryCollect<(T::Item, )> for T
    where T: Iterator {
    #[inline]
    fn try_collect(mut self) -> Option<(T::Item, )> {
        match (self.next(), self.next()) {
            (Some(item), None) => Some((item, )),
            _ => None
        }
    }

    #[inline]
    fn try_collect_lossy(mut self) -> Option<(T::Item, )> {
        self.next().map(|v| (v, ))
    }
}

impl<T> TryCollect<(T::Item, T::Item)> for T
    where T: Iterator {
    #[inline]
    fn try_collect(mut self) -> Option<(T::Item, T::Item)> {
        match (self.next(), self.next(), self.next()) {
            (Some(item1), Some(item2), None) => Some((item1, item2)),
            _ => None
        }
    }

    #[inline]
    fn try_collect_lossy(mut self) -> Option<(T::Item, T::Item)> {
        match (self.next(), self.next()) {
            (Some(item1), Some(item2)) => Some((item1, item2)),
            _ => None
        }
    }
}