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