5.2.6. ytpb.fetchers

Fetchers are used to gather essential information about videos.

Such information includes the basic video information and streams.

class ytpb.fetchers.InfoFetcher(video_url: str, session: Session | None = None)

Bases: ABC

A base abstract class for fetchers.

Notes

Keep in mind that fetchers serve to fetch information, not to store.

A good practice would be to treat each fetch operation as atomic and invoke it sequentially. This provides flexibility and will avoid repeated calls triggered from outside.

__init__(video_url: str, session: Session | None = None) None

Constructs an object of this class.

Parameters:
  • video_url – A video URL.

  • base_url – A segment base URL.

  • session – A requests.Session object.

abstract fetch_video_info()

Fetches basic information about a video.

abstract fetch_streams()

Fetches streams available for a video.

class ytpb.fetchers.YtpbInfoFetcher(video_url: str, session: Session | None = None)

Bases: InfoFetcher

A native fetcher.

fetch_video_info() YouTubeVideoInfo

Fetches basic information about a video.

fetch_streams() Streams[AudioRepresentationInfo | VideoRepresentationInfo]

Fetches streams available for a video.

class ytpb.fetchers.YoutubeDLInfoFetcher(video_url: str, session: Session | None = None, options: dict | None = None)

Bases: InfoFetcher

A fetcher that uses yt_dlp to gather information.

All information is extracted from the YoutubeDL’s information dictionary.

default_options = {'live_from_start': True, 'quiet': True}

The default options passed to yt_dlp.YoutubeDL.

__init__(video_url: str, session: Session | None = None, options: dict | None = None) None

Constructs an object of this class.

Parameters:
  • video_url – A video URL.

  • base_url – A segment base URL.

  • session – A requests.Session object.

  • options – Options passed to yt_dlp.YoutubeDL.

fetch_video_info() YouTubeVideoInfo

Fetches basic information about a video.

fetch_streams() Streams[AudioRepresentationInfo | VideoRepresentationInfo]

Fetches streams available for a video.