mirror of
				https://github.com/yt-dlp/yt-dlp.git
				synced 2025-10-30 22:25:19 +00:00 
			
		
		
		
	[devscripts] Create utils and refactor
				
					
				
			This commit is contained in:
		
							
								
								
									
										35
									
								
								devscripts/utils.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								devscripts/utils.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,35 @@ | ||||
| import argparse | ||||
| import functools | ||||
| 
 | ||||
| 
 | ||||
| def read_file(fname): | ||||
|     with open(fname, encoding='utf-8') as f: | ||||
|         return f.read() | ||||
| 
 | ||||
| 
 | ||||
| def write_file(fname, content): | ||||
|     with open(fname, 'w', encoding='utf-8') as f: | ||||
|         return f.write(content) | ||||
| 
 | ||||
| 
 | ||||
| # Get the version without importing the package | ||||
| def read_version(fname='yt_dlp/version.py'): | ||||
|     exec(compile(read_file(fname), fname, 'exec')) | ||||
|     return locals()['__version__'] | ||||
| 
 | ||||
| 
 | ||||
| def get_filename_args(has_infile=False, default_outfile=None): | ||||
|     parser = argparse.ArgumentParser() | ||||
|     if has_infile: | ||||
|         parser.add_argument('infile', help='Input file') | ||||
|     kwargs = {'nargs': '?', 'default': default_outfile} if default_outfile else {} | ||||
|     parser.add_argument('outfile', **kwargs, help='Output file') | ||||
| 
 | ||||
|     opts = parser.parse_args() | ||||
|     if has_infile: | ||||
|         return opts.infile, opts.outfile | ||||
|     return opts.outfile | ||||
| 
 | ||||
| 
 | ||||
| def compose_functions(*functions): | ||||
|     return lambda x: functools.reduce(lambda y, f: f(y), functions, x) | ||||
		Reference in New Issue
	
	Block a user
	 pukkandan
					pukkandan