[][src]Struct rustube::VideoDescrambler

pub struct VideoDescrambler { /* fields omitted */ }

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 RawFormats, which now contain the correct signature, and convert them to Streams. At the end of the day, Streams are just RawFormats with some extra information.

pub fn video_info(&self) -> &VideoInfo[src]

Trait Implementations

impl Clone for VideoDescrambler[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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,