[−][src]Struct rustube::VideoDescrambler
A YouTubeDescrambler, used to decrypt the data fetched by [YouTubeFetcher
].
You will probably rarely use this type directly, and use [YouTube
] instead.
There's no public way of directly constructing a [YouTubeDescrambler
]. The only way of getting
one is by calling [YouTubeFetcher::fetch
].
Example
const URL: &str = "https://youtube.com/watch?iv=5jlI4uzZGjU"; let url = Url::parse(URL).unwrap(); let fetcher: VideoFetcher = VideoFetcher::from_url(&url).unwrap(); let descrambler: VideoDescrambler = fetcher.fetch().await.unwrap();
Implementations
impl VideoDescrambler
[src]
pub fn descramble(self) -> Result<Video>
[src]
Descrambles the data fetched by YouTubeFetcher.
For more information have a look at the [YouTube
] documentation.
Errors
This method will fail, when it's not able do extract all necessary information out of the
How it works
Descrambling, in this case, mainly refers to descrambling the
[player_response::streaming_data::SignatureCipher
]. YouTube does, unfortunately, not
directly provide any urls for their videos. In fact, as long as nobody requests a video,
the video has no url, and therefore cannot be accessed or downloaded via the internet.
So then, how can we download it?
The first step, requesting the video, already happened in [YouTubeFetcher::fetch
] (To fully
understand descramble
, you should first read how fetching works).
The next step is to descramble (or decrypt) the signature, stored in CipherSignature.s
,
of each individual RawFormat
. To to so, there's the so called transform_plan
, and the
so called transform_map
.
The transform_plan
is just a list of javascript function, which take a string (or an array)
plus an optional integer as input, transform the string in a certain way, and return the new
string. This new string then represents the new signature.
But wait! How can we run JavaScript in Rust? And doesn't that come with a huge overhead?
It actually would come with a huge overhead! That's why we need the transform_map
. The
transform_map
is a HashMap<String, TransformFn>
, which maps JavaScript function names to
Rust functions. For now, you can think of TransformFn
just being a function pointer.
There's actually more to it, but that's not important for downloading the video.
To finally get the videos signature, the raw, initial signature has to be transformed once
by every function in the transform_plan
. To do so, we just iterate over it, look up the
corresponding TransformFn
in transform_map
, and pass the signature as well as the
optional integer. to it.
The last step descramble
performs, is to take all RawFormat
s, which now contain the
correct signature, and convert them to Stream
s. At the end of the day, Stream
s are just
RawFormat
s with some extra information.
pub fn video_info(&self) -> &VideoInfo
[src]
Trait Implementations
impl Clone for VideoDescrambler
[src]
pub fn clone(&self) -> VideoDescrambler
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for VideoDescrambler
[src]
impl Display for VideoDescrambler
[src]
impl Eq for VideoDescrambler
[src]
impl PartialEq<VideoDescrambler> for VideoDescrambler
[src]
Auto Trait Implementations
impl !RefUnwindSafe for VideoDescrambler
[src]
impl Send for VideoDescrambler
[src]
impl Sync for VideoDescrambler
[src]
impl Unpin for VideoDescrambler
[src]
impl !UnwindSafe for VideoDescrambler
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
pub fn equivalent(&self, key: &K) -> bool
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,