Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add yt-dlp stubs #14216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
Loading
from
Open

Add yt-dlp stubs #14216

wants to merge 1 commit into from

Conversation

Tatsh
Copy link
Contributor

@Tatsh Tatsh commented Jun 3, 2025

Porting over from https://github.com/Tatsh/yt-dlp-types.

Upstream is unlikely to have full types any time soon. Though it may seem like an insular project, there is utility in using yt-dlp outside as I do in some of my projects. Examples:

  • Use yt-dlp in addition to other code when archiving a site (yt-dlp does a good job collecting metadata with the videos)
  • Use yt-dlp but write an extractor you do not wish to contribute to yt-dlp (added via YoutubeDL.add_info_extractor()).

It is normal to extend yt_dlp.extractor.common.InfoExtractor and override its private methods so common ones are included, especially _real_extract() which is most important to override.

These types are not complete but what is complete is what is included has been useful for me and others.

Once accepted I will deprecate and archive yt-dlp-types on Github and on PyPI.

cc @Sky-NiniKo @thcrt

Usages:

This comment has been minimized.

Copy link
Contributor

github-actions bot commented Jun 4, 2025

Diff from mypy_primer, showing the effect of this PR on open source code:

core (https://github.com/home-assistant/core)
+ homeassistant/components/media_extractor/__init__.py:63: error: Incompatible types (expression has type "Logger", TypedDict item "logger" has type "_LoggerProtocol")  [typeddict-item]
+ homeassistant/components/media_extractor/__init__.py:63: note: "Logger" is missing following "_LoggerProtocol" protocol members:
+ homeassistant/components/media_extractor/__init__.py:63: note:     stderr, stdout
+ homeassistant/components/media_extractor/__init__.py:63: note: Following member(s) of "Logger" have conflicts:
+ homeassistant/components/media_extractor/__init__.py:63: note:     Expected:
+ homeassistant/components/media_extractor/__init__.py:63: note:         def warning(self, message: str, *, once: bool = ..., only_once: bool = ...) -> None
+ homeassistant/components/media_extractor/__init__.py:63: note:     Got:
+ homeassistant/components/media_extractor/__init__.py:63: note:         def warning(self, msg: object, *args: object, exc_info: bool | tuple[type[BaseException], BaseException, TracebackType | None] | tuple[None, None, None] | BaseException | None = ..., stack_info: bool = ..., stacklevel: int = ..., extra: Mapping[str, object] | None = ...) -> None
+ homeassistant/components/media_extractor/__init__.py:69: error: Unexpected keyword argument "download" for "extract_info" of "YoutubeDL"  [call-arg]
+ homeassistant/components/media_extractor/__init__.py:69: error: Unexpected keyword argument "process" for "extract_info" of "YoutubeDL"  [call-arg]
+ homeassistant/components/media_extractor/__init__.py:186: error: Argument 1 to "YoutubeDL" has incompatible type "dict[str, object]"; expected "YDLOpts | None"  [arg-type]
+ homeassistant/components/media_extractor/__init__.py:189: error: Unexpected keyword argument "process" for "extract_info" of "YoutubeDL"  [call-arg]
+ homeassistant/components/media_extractor/__init__.py:196: error: No overload variant of "list" matches argument type "object"  [call-overload]
+ homeassistant/components/media_extractor/__init__.py:196: note: Possible overload variants:
+ homeassistant/components/media_extractor/__init__.py:196: note:     def [_T] __init__(self) -> list[_T]
+ homeassistant/components/media_extractor/__init__.py:196: note:     def [_T] __init__(self, Iterable[_T], /) -> list[_T]
+ homeassistant/components/media_extractor/__init__.py:208: error: "YoutubeDL" has no attribute "params"  [attr-defined]
+ homeassistant/components/media_extractor/__init__.py:209: error: "YoutubeDL" has no attribute "process_ie_result"  [attr-defined]

@thcrt
Copy link

thcrt commented Jun 5, 2025

Cheers for cc-ing me, appreciate it. It would indeed be nice to have the stubs maintained in typeshed and hence more easily discoverable for devs calling yt-dlp directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.