mirror of
				https://github.com/yt-dlp/yt-dlp.git
				synced 2025-10-31 06:30:44 +00:00 
			
		
		
		
	Add new options --impersonate and --list-impersonate-targets
				
					
				
			Authored by: coletdjnz, Grub4K, pukkandan, bashonly Co-authored-by: Simon Sawicki <contact@grub4k.xyz> Co-authored-by: pukkandan <pukkandan.ytdlp@gmail.com> Co-authored-by: bashonly <bashonly@protonmail.com>
This commit is contained in:
		| @@ -19,6 +19,7 @@ from .cookies import SUPPORTED_BROWSERS, SUPPORTED_KEYRINGS | ||||
| from .downloader.external import get_external_downloader | ||||
| from .extractor import list_extractor_classes | ||||
| from .extractor.adobepass import MSO_INFO | ||||
| from .networking.impersonate import ImpersonateTarget | ||||
| from .options import parseOpts | ||||
| from .postprocessor import ( | ||||
|     FFmpegExtractAudioPP, | ||||
| @@ -48,6 +49,7 @@ from .utils import ( | ||||
|     float_or_none, | ||||
|     format_field, | ||||
|     int_or_none, | ||||
|     join_nonempty, | ||||
|     match_filter_func, | ||||
|     parse_bytes, | ||||
|     parse_duration, | ||||
| @@ -388,6 +390,9 @@ def validate_options(opts): | ||||
|                                  f'Supported keyrings are: {", ".join(sorted(SUPPORTED_KEYRINGS))}') | ||||
|         opts.cookiesfrombrowser = (browser_name, profile, keyring, container) | ||||
| 
 | ||||
|     if opts.impersonate is not None: | ||||
|         opts.impersonate = ImpersonateTarget.from_str(opts.impersonate.lower()) | ||||
| 
 | ||||
|     # MetadataParser | ||||
|     def metadataparser_actions(f): | ||||
|         if isinstance(f, str): | ||||
| @@ -911,6 +916,7 @@ def parse_options(argv=None): | ||||
|         'postprocessors': postprocessors, | ||||
|         'fixup': opts.fixup, | ||||
|         'source_address': opts.source_address, | ||||
|         'impersonate': opts.impersonate, | ||||
|         'call_home': opts.call_home, | ||||
|         'sleep_interval_requests': opts.sleep_interval_requests, | ||||
|         'sleep_interval': opts.sleep_interval, | ||||
| @@ -980,6 +986,41 @@ def _real_main(argv=None): | ||||
|             traceback.print_exc() | ||||
|             ydl._download_retcode = 100 | ||||
| 
 | ||||
|         if opts.list_impersonate_targets: | ||||
| 
 | ||||
|             known_targets = [ | ||||
|                 # List of simplified targets we know are supported, | ||||
|                 # to help users know what dependencies may be required. | ||||
|                 (ImpersonateTarget('chrome'), 'curl_cffi'), | ||||
|                 (ImpersonateTarget('edge'), 'curl_cffi'), | ||||
|                 (ImpersonateTarget('safari'), 'curl_cffi'), | ||||
|             ] | ||||
| 
 | ||||
|             available_targets = ydl._get_available_impersonate_targets() | ||||
| 
 | ||||
|             def make_row(target, handler): | ||||
|                 return [ | ||||
|                     join_nonempty(target.client.title(), target.version, delim='-') or '-', | ||||
|                     join_nonempty((target.os or "").title(), target.os_version, delim='-') or '-', | ||||
|                     handler, | ||||
|                 ] | ||||
| 
 | ||||
|             rows = [make_row(target, handler) for target, handler in available_targets] | ||||
| 
 | ||||
|             for known_target, known_handler in known_targets: | ||||
|                 if not any( | ||||
|                     known_target in target and handler == known_handler | ||||
|                     for target, handler in available_targets | ||||
|                 ): | ||||
|                     rows.append([ | ||||
|                         ydl._format_out(text, ydl.Styles.SUPPRESS) | ||||
|                         for text in make_row(known_target, f'{known_handler} (not available)') | ||||
|                     ]) | ||||
| 
 | ||||
|             ydl.to_screen('[info] Available impersonate targets') | ||||
|             ydl.to_stdout(render_table(['Client', 'OS', 'Source'], rows, extra_gap=2, delim='-')) | ||||
|             return | ||||
| 
 | ||||
|         if not actual_use: | ||||
|             if pre_process: | ||||
|                 return ydl._download_retcode | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 coletdjnz
					coletdjnz