pub struct VideoFetcher { /* private fields */ }
Expand description

A fetcher used to download all necessary data from YouTube, which then could be used to extract video-URLs.

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();

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 video’s id (If you want to learn more about the id, you can have a look at Id. But you don’t need to know anything about it for now). Let’s, for example, take the id ‘5jlI4uzZGjU’. With this id, we can then visit https://youtube.com/watch?v=5jlI4uzZGjU, the site, you as a human would visit 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 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 VideoDescrambler::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. One you probably don’t frequently visit as a ‘normal’ human being. Because we, programmers, are really creative when it comes to naming stuff, a video’s 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 course, we cannot download the video yet. But that’s not the task of fetch. fetch is just responsible for requesting all the essential information. To learn how the journey continues, have a look at VideoDescrambler.

Implementations

Constructs a VideoFetcher from an Url.

Errors

Constructs a VideoFetcher from an Id.

Errors

When reqwest fails to initialize an new Client.

Constructs a VideoFetcher from an Id and an existing Client. There are no special constrains, what the Client has to look like. It’s recommended to use the cookie jar returned from [recommended_cookies]. It’s recommended to use the headers returned from [recommended_headers].

Fetches all available video data and deserializes it into VideoInfo.

Errors
  • When the video is private, only for members, or otherwise not accessible.
  • When requests to some video resources fail.
  • When deserializing the raw response 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.

Fetches all available video data, and deserializes it into VideoInfo.

This method will only return the VideoInfo. You won’t have the ability to download the video afterwards. If you want to download videos, have a look at VideoFetcher::fetch.

This method is useful if you want to find out something about a video that is not available for download, like live streams that are offline.

Errors
  • When requests to some video resources fail.
  • When deserializing the raw response fails.

When having a good internet connection, this method should not fail. 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.

The id of the video.

The url, under witch the video can be watched.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Compare self to key and return true if they are equal.

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more