Struct rustube::VideoFetcher[][src]

pub struct VideoFetcher { /* fields omitted */ }

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

impl VideoFetcher[src]

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

This is supported on crate features fetch and regex only.

Constructs a VideoFetcher from an Url.

Errors

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

This is supported on crate feature fetch only.

Constructs a VideoFetcher from an Id.

Errors

When reqwest fails to initialize an new Client.

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

This is supported on crate feature fetch only.

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].

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

This is supported on crate feature fetch only.

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.

pub async fn fetch_info(self) -> Result<VideoInfo>[src]

This is supported on crate feature fetch only.

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.

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

This is supported on crate feature fetch only.

The id of the video.

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

This is supported on crate feature fetch only.

The url, under witch the video can be watched.

Trait Implementations

impl Clone for VideoFetcher[src]

This is supported on crate feature fetch only.

impl Debug for VideoFetcher[src]

This is supported on crate feature fetch only.

impl Display for VideoFetcher[src]

This is supported on crate feature fetch only.

impl Eq for VideoFetcher[src]

This is supported on crate feature fetch only.

impl PartialEq<VideoFetcher> for VideoFetcher[src]

This is supported on crate feature fetch only.

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, 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.