|
| 1 | +import optparse |
| 2 | +from collections.abc import Callable, Collection, Iterator, Mapping |
| 3 | +from typing import Literal, NamedTuple, Protocol, TypedDict, type_check_only |
| 4 | +from typing_extensions import NotRequired |
| 5 | + |
| 6 | +from .extractor import gen_extractors, list_extractors |
| 7 | +from .networking.impersonate import ImpersonateTarget |
| 8 | +from .YoutubeDL import YoutubeDL |
| 9 | + |
| 10 | +__all__ = ["YoutubeDL", "gen_extractors", "list_extractors", "main", "parse_options"] |
| 11 | + |
| 12 | +@type_check_only |
| 13 | +class _LoggerProtocol(Protocol): # noqa: Y046 |
| 14 | + def __init__(self, ydl: YoutubeDL | None = None) -> None: ... |
| 15 | + def debug(self, message: str) -> None: ... |
| 16 | + def info(self, message: str) -> None: ... |
| 17 | + def warning(self, message: str, *, once: bool = ..., only_once: bool = ...) -> None: ... |
| 18 | + def error(self, message: str) -> None: ... |
| 19 | + def stdout(self, message: str) -> None: ... |
| 20 | + def stderr(self, message: str) -> None: ... |
| 21 | + |
| 22 | +@type_check_only |
| 23 | +class _RetrySleepFunctions(TypedDict): |
| 24 | + default: NotRequired[Callable[[int], int]] |
| 25 | + file_access: NotRequired[Callable[[int], int]] |
| 26 | + fragment: NotRequired[Callable[[int], int]] |
| 27 | + |
| 28 | +@type_check_only |
| 29 | +class _ProgressTemplateValue(TypedDict): # noqa: Y049 |
| 30 | + info: NotRequired[str] |
| 31 | + progress: NotRequired[str] |
| 32 | + |
| 33 | +@type_check_only |
| 34 | +class _ExternalDownloader(TypedDict): |
| 35 | + dash: NotRequired[str] |
| 36 | + default: NotRequired[str] |
| 37 | + ftp: NotRequired[str] |
| 38 | + http: NotRequired[str] |
| 39 | + m3u8: NotRequired[str] |
| 40 | + mms: NotRequired[str] |
| 41 | + rtmp: NotRequired[str] |
| 42 | + rtsp: NotRequired[str] |
| 43 | + |
| 44 | +@type_check_only |
| 45 | +class _DownloadRange(TypedDict): |
| 46 | + end_time: int |
| 47 | + index: NotRequired[int] |
| 48 | + start_time: int |
| 49 | + title: NotRequired[str] |
| 50 | + |
| 51 | +@type_check_only |
| 52 | +class _Color(TypedDict): |
| 53 | + stderr: NotRequired[Literal["always", "auto", "no_color", "never"]] |
| 54 | + stdout: NotRequired[Literal["always", "auto", "no_color", "never"]] |
| 55 | + |
| 56 | +_ProgressTemplate = TypedDict( |
| 57 | + "_ProgressTemplate", |
| 58 | + { |
| 59 | + "download": _ProgressTemplateValue, |
| 60 | + "download-title": _ProgressTemplateValue, |
| 61 | + "postprocess": _ProgressTemplateValue, |
| 62 | + "postprocess-title": _ProgressTemplateValue, |
| 63 | + }, |
| 64 | +) |
| 65 | + |
| 66 | +@type_check_only |
| 67 | +class _Params(TypedDict): |
| 68 | + usenetrc: NotRequired[bool | None] |
| 69 | + netrc_location: NotRequired[str | None] |
| 70 | + netrc_cmd: NotRequired[str | None] |
| 71 | + username: NotRequired[str | None] |
| 72 | + password: NotRequired[str | None] |
| 73 | + twofactor: NotRequired[str | None] |
| 74 | + videopassword: NotRequired[str | None] |
| 75 | + ap_mso: NotRequired[str | None] |
| 76 | + ap_username: NotRequired[str | None] |
| 77 | + ap_password: NotRequired[str | None] |
| 78 | + client_certificate: NotRequired[str | None] |
| 79 | + client_certificate_key: NotRequired[str | None] |
| 80 | + client_certificate_password: NotRequired[str | None] |
| 81 | + quiet: NotRequired[bool | None] |
| 82 | + no_warnings: NotRequired[bool | None] |
| 83 | + forceurl: NotRequired[bool | None] |
| 84 | + forcetitle: NotRequired[str | None] |
| 85 | + forceid: NotRequired[bool | None] |
| 86 | + forcethumbnail: NotRequired[bool | None] |
| 87 | + forcedescription: NotRequired[bool | None] |
| 88 | + forceduration: NotRequired[str | None] |
| 89 | + forcefilename: NotRequired[bool | None] |
| 90 | + forceprint: NotRequired[Mapping[str, Collection[str]] | Collection[str] | None] |
| 91 | + print_to_file: NotRequired[Mapping[str, tuple[str, str]] | None] |
| 92 | + forcejson: NotRequired[bool | None] |
| 93 | + dump_single_json: NotRequired[bool | None] |
| 94 | + force_write_download_archive: NotRequired[str | None] |
| 95 | + simulate: NotRequired[str | None] |
| 96 | + skip_download: NotRequired[str | None] |
| 97 | + format: NotRequired[str | Callable[[Mapping[str, object]], Mapping[str, object]] | None] |
| 98 | + allow_unplayable_formats: NotRequired[bool | None] |
| 99 | + ignore_no_formats_error: NotRequired[bool | None] |
| 100 | + format_sort: NotRequired[Collection[str] | None] |
| 101 | + format_sort_force: NotRequired[str | None] |
| 102 | + allow_multiple_video_streams: NotRequired[bool | None] |
| 103 | + allow_multiple_audio_streams: NotRequired[bool | None] |
| 104 | + check_formats: NotRequired[bool | Literal["selected"] | None] |
| 105 | + listformats: NotRequired[bool | None] |
| 106 | + outtmpl: NotRequired[str | Mapping[str, str] | None] |
| 107 | + outtmpl_na_placeholder: NotRequired[str | None] |
| 108 | + paths: NotRequired[str | None] |
| 109 | + restrictfilenames: NotRequired[bool | None] |
| 110 | + windowsfilenames: NotRequired[bool | None] |
| 111 | + ignoreerrors: NotRequired[bool | Literal["only_download"] | None] |
| 112 | + force_generic_extractor: NotRequired[bool | None] |
| 113 | + allowed_extractors: NotRequired[Collection[str] | None] |
| 114 | + ratelimit: NotRequired[int | None] |
| 115 | + throttledratelimit: NotRequired[int | None] |
| 116 | + overwrites: NotRequired[bool | None] |
| 117 | + retries: NotRequired[int | None] |
| 118 | + file_access_retries: NotRequired[int | None] |
| 119 | + fragment_retries: NotRequired[int | None] |
| 120 | + extractor_retries: NotRequired[int | None] |
| 121 | + retry_sleep_functions: NotRequired[_RetrySleepFunctions | None] |
| 122 | + skip_unavailable_fragments: NotRequired[bool | None] |
| 123 | + keep_fragments: NotRequired[bool | None] |
| 124 | + concurrent_fragment_downloads: NotRequired[int | None] |
| 125 | + buffersize: NotRequired[int | None] |
| 126 | + noresizebuffer: NotRequired[bool | None] |
| 127 | + http_chunk_size: NotRequired[int | None] |
| 128 | + continuedl: NotRequired[bool | None] |
| 129 | + noprogress: NotRequired[bool | None] |
| 130 | + progress_with_newline: NotRequired[bool | None] |
| 131 | + progress_template: NotRequired[_ProgressTemplate | None] |
| 132 | + playliststart: NotRequired[int | None] |
| 133 | + playlistend: NotRequired[int | None] |
| 134 | + playlistreverse: NotRequired[bool | None] |
| 135 | + playlistrandom: NotRequired[bool | None] |
| 136 | + lazy_playlist: NotRequired[bool | None] |
| 137 | + noplaylist: NotRequired[bool | None] |
| 138 | + logtostderr: NotRequired[bool | None] |
| 139 | + consoletitle: NotRequired[str | None] |
| 140 | + nopart: NotRequired[bool | None] |
| 141 | + updatetime: NotRequired[bool | None] |
| 142 | + writedescription: NotRequired[bool | None] |
| 143 | + writeannotations: NotRequired[bool | None] |
| 144 | + writeinfojson: NotRequired[bool | None] |
| 145 | + allow_playlist_files: NotRequired[bool | None] |
| 146 | + clean_infojson: NotRequired[bool | None] |
| 147 | + getcomments: NotRequired[bool | None] |
| 148 | + writethumbnail: NotRequired[bool | None] |
| 149 | + write_all_thumbnails: NotRequired[bool | None] |
| 150 | + writelink: NotRequired[bool | None] |
| 151 | + writeurllink: NotRequired[bool | None] |
| 152 | + writewebloclink: NotRequired[bool | None] |
| 153 | + writedesktoplink: NotRequired[bool | None] |
| 154 | + writesubtitles: NotRequired[bool | None] |
| 155 | + writeautomaticsub: NotRequired[bool | None] |
| 156 | + allsubtitles: NotRequired[bool | None] |
| 157 | + listsubtitles: NotRequired[bool | None] |
| 158 | + subtitlesformat: NotRequired[str | None] |
| 159 | + subtitleslangs: NotRequired[Collection[str] | None] |
| 160 | + matchtitle: NotRequired[bool | None] |
| 161 | + rejecttitle: NotRequired[bool | None] |
| 162 | + prefer_free_formats: NotRequired[bool | None] |
| 163 | + trim_file_name: NotRequired[int | None] |
| 164 | + verbose: NotRequired[bool | None] |
| 165 | + test: NotRequired[bool | None] |
| 166 | + keepvideo: NotRequired[str | None] |
| 167 | + min_filesize: NotRequired[int | None] |
| 168 | + max_filesize: NotRequired[int | None] |
| 169 | + min_views: NotRequired[str | None] |
| 170 | + max_views: NotRequired[str | None] |
| 171 | + daterange: NotRequired[str | None] |
| 172 | + cachedir: NotRequired[str | None] |
| 173 | + age_limit: NotRequired[str | None] |
| 174 | + download_archive: NotRequired[str | None] |
| 175 | + break_on_existing: NotRequired[str | None] |
| 176 | + break_on_reject: NotRequired[bool | None] |
| 177 | + break_per_url: NotRequired[bool | None] |
| 178 | + skip_playlist_after_errors: NotRequired[bool | None] |
| 179 | + cookiefile: NotRequired[str | None] |
| 180 | + cookiesfrombrowser: NotRequired[tuple[str, ...] | None] |
| 181 | + legacyserverconnect: NotRequired[bool | None] |
| 182 | + nocheckcertificate: NotRequired[bool | None] |
| 183 | + prefer_insecure: NotRequired[str | None] |
| 184 | + enable_file_urls: NotRequired[str | None] |
| 185 | + http_headers: NotRequired[Mapping[str, str] | None] |
| 186 | + proxy: NotRequired[str | None] |
| 187 | + socket_timeout: NotRequired[int | None] |
| 188 | + bidi_workaround: NotRequired[bool | None] |
| 189 | + debug_printtraffic: NotRequired[bool | None] |
| 190 | + prefer_ffmpeg: NotRequired[bool | None] |
| 191 | + include_ads: NotRequired[bool | None] |
| 192 | + default_search: NotRequired[str | None] |
| 193 | + dynamic_mpd: NotRequired[bool | None] |
| 194 | + extractor_args: NotRequired[Mapping[str, Mapping[str, object]] | None] |
| 195 | + youtube_include_dash_manifest: NotRequired[bool | None] |
| 196 | + youtube_include_hls_manifest: NotRequired[bool | None] |
| 197 | + encoding: NotRequired[str | None] |
| 198 | + extract_flat: NotRequired[bool | Literal["in_playlist", "discard", "discard_in_playlist"] | None] |
| 199 | + live_from_start: NotRequired[bool | None] |
| 200 | + wait_for_video: NotRequired[tuple[int, int] | None] |
| 201 | + mark_watched: NotRequired[bool | None] |
| 202 | + merge_output_format: NotRequired[str | None] |
| 203 | + final_ext: NotRequired[str | None] |
| 204 | + postprocessors: NotRequired[Collection[Mapping[str, object]]] |
| 205 | + fixup: NotRequired[Literal["never", "warn", "detect_or_warn"] | None] |
| 206 | + source_address: NotRequired[str | None] |
| 207 | + call_home: NotRequired[bool | None] |
| 208 | + sleep_interval_requests: NotRequired[int | None] |
| 209 | + sleep_interval: NotRequired[int | None] |
| 210 | + max_sleep_interval: NotRequired[int | None] |
| 211 | + sleep_interval_subtitles: NotRequired[int | None] |
| 212 | + external_downloader: NotRequired[_ExternalDownloader | None] |
| 213 | + download_ranges: NotRequired[Callable[[object, YoutubeDL], Iterator[_DownloadRange]] | None] |
| 214 | + force_keyframes_at_cuts: NotRequired[bool | None] |
| 215 | + list_thumbnails: NotRequired[str | None] |
| 216 | + playlist_items: NotRequired[Collection[int] | None] |
| 217 | + xattr_set_filesize: NotRequired[bool | None] |
| 218 | + match_filter: NotRequired[ |
| 219 | + Callable[[Mapping[str, object], bool], str | None] | Callable[[Mapping[str, object]], str | None] | None |
| 220 | + ] |
| 221 | + color: NotRequired[_Color | None] |
| 222 | + ffmpeg_location: NotRequired[str | None] |
| 223 | + hls_prefer_native: NotRequired[bool | None] |
| 224 | + hls_use_mpegts: NotRequired[bool | None] |
| 225 | + hls_split_discontinuity: NotRequired[bool | None] |
| 226 | + max_downloads: NotRequired[int | None] |
| 227 | + dump_intermediate_pages: NotRequired[bool | None] |
| 228 | + listformats_table: NotRequired[bool | None] |
| 229 | + write_pages: NotRequired[bool | None] |
| 230 | + external_downloader_args: NotRequired[Literal["default"] | Mapping[str, Collection[str]] | Collection[str] | None] |
| 231 | + postprocessor_args: NotRequired[Mapping[str, Collection[str]] | Collection[str] | None] |
| 232 | + geo_verification_proxy: NotRequired[str | None] |
| 233 | + geo_bypass: NotRequired[bool | None] |
| 234 | + geo_bypass_country: NotRequired[str | None] |
| 235 | + geo_bypass_ip_block: NotRequired[str | None] |
| 236 | + compat_opts: NotRequired[dict[str, object] | None] |
| 237 | + # Undocumented fields below. |
| 238 | + _deprecation_warnings: NotRequired[Collection[str] | None] |
| 239 | + _warnings: NotRequired[Collection[str] | None] |
| 240 | + autonumber_size: NotRequired[int | None] |
| 241 | + autonumber_start: NotRequired[int | None] |
| 242 | + cn_verification_proxy: NotRequired[str | None] |
| 243 | + forceformat: NotRequired[object] |
| 244 | + load_pages: NotRequired[bool | None] |
| 245 | + logger: NotRequired[_LoggerProtocol] |
| 246 | + youtube_print_sig_code: NotRequired[bool | None] |
| 247 | + progress_hooks: NotRequired[list[Callable[[object], object]]] |
| 248 | + impersonate: NotRequired[ImpersonateTarget] |
| 249 | + |
| 250 | +@type_check_only |
| 251 | +class _ParsedOptions(NamedTuple): |
| 252 | + parser: optparse.OptionParser |
| 253 | + options: optparse.Values |
| 254 | + urls: Collection[str] |
| 255 | + ydl_opts: _Params |
| 256 | + |
| 257 | +def parse_options(argv: Collection[str] | None = ...) -> _ParsedOptions: ... |
| 258 | +def main(argv: list[str] | None = ...) -> int: ... |
0 commit comments