TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/vsmutok/ytscrape/llms.txt
Use this file to discover all available pages before exploring further.
YouTube class is the main entry point for every scraping task in ytscrape. It is a thin facade over InnerTubeClient, the paginated result types, and the data models. You construct one instance, call methods on it, and let ytscrape handle authentication headers, pagination, and response parsing.
In most cases a zero-argument YouTube() call is all you need. Pass keyword arguments only when you want to target a specific locale, adjust the request timeout, or inject a pre-built InnerTubeClient (for example when running tests or routing traffic through a proxy).
Constructor
A pre-built
InnerTubeClient to use instead of creating a new one. When
provided, the locale, language, region, and timeout arguments are ignored. Useful when you
want to share a session across multiple YouTube instances or inject a custom client for testing.A
Locale object that bundles language and country together. When provided, the
language and region arguments are ignored. Omit it to let the client build a Locale from
the individual language and region values.The
hl (host language) value sent in every InnerTube request. Accepts a
Language enum member or a raw ISO 639-1 code such as "fr" or "de". Ignored
when locale is provided.The
gl (geolocation) value sent in every InnerTube request. Accepts a
Country enum member or a raw ISO 3166-1 alpha-2 code such as "GB" or "DE".
Ignored when locale is provided.Per-request timeout in seconds applied to every HTTP call made by the default client. Ignored when
client is provided.Properties
client
InnerTubeClient instance. Useful when you need to call
low-level endpoints directly or inspect the session state without bypassing the facade.
locale
Locale (language + country pair) that is being used for all requests. This is
a shortcut for yt.client.locale.
Methods
search
Search YouTube and return a lazily-paginated SearchResults object.
The search query string.
Narrows results to a specific content type. Accepts a
SearchFilter enum member
(ALL, VIDEOS, CHANNELS, PLAYLISTS) or its lowercase string value ("all", "videos",
"channels", "playlists").Optional cap on the total number of items yielded when iterating over the returned
SearchResults. None means iterate until YouTube runs out of pages.SearchResults — a lazy iterable that transparently fetches
continuation pages on demand.
video
Fetch detailed metadata for a single video.
A video id or any YouTube URL that contains one. Supported URL formats include
watch?v=, youtu.be/, /shorts/, and /embed/.VideoDetails — rich metadata including title, description,
view count, like count, upload date, and channel info.
channel
Fetch detailed metadata for a single channel.
A channel id starting with
UC, a @handle, or any YouTube channel URL. Supported formats
include /channel/UC…, /@handle, /c/name, and /user/name.ChannelDetails — includes title, description,
subscriber count, video count, and channel id.
comments
Collect comments for a video and return a lazily-paginated CommentThread.
A video id or any YouTube URL that contains one (
watch?v=, youtu.be/, /shorts/, /embed/
are all supported).Optional cap on the total number of comments yielded when iterating. When
include_replies is
True, replies count toward this limit too.When
True, replies to each top-level comment are also collected. Each reply is yielded
immediately after the comment it belongs to and has its is_reply attribute set to True.The order in which comments are fetched.
CommentSort.TOP mirrors YouTube’s “Top comments” view
but intentionally omits less relevant comments and potential spam. CommentSort.NEWEST (or
"newest") returns every comment. Use "newest" when completeness matters.CommentThread — a lazy iterable that pages through comments on
demand.
Raises: ParseError — if the comments section cannot be found (e.g. comments are disabled).
transcript
Fetch a transcript (captions track) for a video.
A video id or any YouTube watch URL.
Preferred language codes tried in order, e.g.
["uk", "en"]. Manually created captions are
preferred over auto-generated ones within each language, following the same behaviour as
youtube-transcript-api.When
True, a small set of HTML formatting tags (<i>, <b>, etc.) are preserved inside
snippet text. By default all tags are stripped.Transcript — the full transcript with
.text (plain string) and .snippets (list of timed TranscriptSnippet objects).
transcripts
List all available caption tracks for a video without downloading any of them.
A video id or any YouTube watch URL.
TranscriptList — an iterable of
TranscriptTrack objects. Use .find_transcript() to locate a specific track, and .fetch() or
.translate() on a track to download it.
close
Close the underlying HTTP session and release all associated resources.
None
Context manager support
YouTube implements the context manager protocol (__enter__ / __exit__), so you can use it
in a with statement. __exit__ calls close() automatically, even when an exception is raised
inside the block.