[][src]Struct rustube::VideoFetcher

pub struct VideoFetcher { /* fields omitted */ }

A YouTubeFetcher, used to download all necessary data from YouTube, which then could be used to extract video-urls, or other video information.

You will probably rarely use this type directly, and use [Video] instead.

Example

const URL: &str = "https://youtube.com/watch?iv=5jlI4uzZGjU";
let url = Url::parse(URL).unwrap();

let fetcher: VideoFetcher =  VideoFetcher::from_url(&url).unwrap();

Implementations

impl VideoFetcher[src]

pub fn from_url(url: &Url) -> Result<Self>[src]

Creates a YouTubeFetcher from an Url. For more information have a look at the YouTube documentation.

Errors

This method fails if no valid video id can be extracted from the url or when reqwest fails to initialize an new Client.

pub fn from_id(video_id: IdBuf) -> Result<Self>[src]

Creates a YouTubeFetcher from an Id. For more information have a look at the YouTube documentation.

Errors

This method fails if reqwest fails to initialize an new Client.

pub fn from_id_with_client(video_id: IdBuf, client: Client) -> Self[src]

Creates a YouTubeFetcher from an Id and an existing Client. There are no special constrains, what the Client has to look like. For more information have a look at the YouTube documentation.

pub async fn fetch(self) -> Result<VideoDescrambler>[src]

Fetches all data necessary to extract important video information. For more information have a look at the YouTube documentation.

Errors

This method fails, when the video is private, only for members, or otherwise not accessible, when it cannot request all necessary video resources, or when deserializing the raw response string into the corresponding Rust types fails.

When having a good internet connection, only errors due to inaccessible videos should occur. Other errors usually mean, that YouTube changed their API, and rustube did not adapt to this change yet. Please feel free to open a GitHub issue if this is the case.

How it works

So you want to download a YouTube video? You probably already noticed, that YouTube makes this quite hard, and does not just provide static urls for their videos. In fact, there's not the one url for each video. When currently nobody is watching a video, there's actually no url for this video at all!

So we need to somehow show YouTube that we want to watch the video, so the YouTube server generates a url for us. To do this, we do what every 'normal' human being would do: we request the webpage of the video. To do so, we need nothing more, then the videos id (If you want to learn more about the id, you can have a look at the [id] module. But you don't need to know anything about it for now.). Let's say for example '5jlI4uzZGjU'. With this id, we can then visit https://youtube.com/watch?v=5jlI4uzZGjU, the site, you as a human, would go to when just watching the video.

The next step is to extract as much information from https://youtube.com/watch?v=5jlI4uzZGjU as possible. This is, i.e., information like "is the video age restricted?", or "can we watch the video without being a member of that channel?".

But there's information, which is a lot more important then knowing if we are old enough to to watch the video: The VideoInfo, the PlayerResponse, and the JavaScript of the page. VideoInfo and PlayerResponse are JSON objects, which contain the most important Information about the video. If you are feeling brave, feel free to have a look at the definitions of those two types, their subtypes, and all the information they contain (It's huge!). The JavaScript is not processed by fetch, but is used later by descramble to generate the transform_plan and the transform_map (you will learn about both when it comes to descrambling).

To get the videos VideoInfo, we actually need to request one more page, which you usually probably don't visit as a 'normal' human being. Because we, programmers, are really creative when it comes to naming stuff, a videos VideoInfo can be requested at https://youtube.com/get_video_info. Btw.: If you want to see how the computer feels, when we ask him to deserialize the response into the VideoInfo struct, you can have a look at https://www.youtube.com/get_video_info?video_id=5jlI4uzZGjU&eurl=https%3A%2F%2Fyoutube.com%2Fwatch%3Fiv%3D5jlI4uzZGjU&sts= (most browsers, will download a text file!). This is the actual VideoInfo for the video with the id '5jlI4uzZGjU'.

That's it! Of curse we are not even close to be able to download the video, yet. But that's not the task of fetch. fetch is just responsible for requesting all the important information. To learn, how the journey continues, have a look at [YouTubeDescrambler::descramble].

pub fn video_id(&self) -> Id<'_>[src]

pub fn watch_url(&self) -> &Url[src]

Trait Implementations

impl Clone for VideoFetcher[src]

impl Debug for VideoFetcher[src]

impl Display for VideoFetcher[src]

impl Eq for VideoFetcher[src]

impl PartialEq<VideoFetcher> for VideoFetcher[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.