Implemented --exec option.
This commit is contained in:
		
							
								
								
									
										36
									
								
								youtube_dl/postprocessor/execafterdownload.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								youtube_dl/postprocessor/execafterdownload.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,36 @@ | ||||
| # ExecAfterDownload written by AaronM / mcd1992. | ||||
| # If there are any issues with this postprocessor please contact me via github or admin@fgthou.se | ||||
|  | ||||
| import os, re, shlex | ||||
| from ..utils import PostProcessingError | ||||
|  | ||||
| class ExecAfterDownload( object ): | ||||
|     _downloader = None | ||||
|  | ||||
|     def __init__( self, downloader = None, commandString = None ): | ||||
|         self._downloader = downloader | ||||
|         self.commandString = commandString | ||||
|  | ||||
|     def set_downloader( self, downloader ): | ||||
|         """Sets the downloader for this PP.""" | ||||
|         self._downloader = downloader | ||||
|  | ||||
|     def run( self, information ): | ||||
|         self.targetFile = information["filepath"] | ||||
|         self.finalCommand = None; | ||||
|  | ||||
|         if( re.search( '{}', self.commandString ) ): # Find and replace all occurrences of {} with the file name. | ||||
|             self.finalCommand = re.sub( "{}", '\'' + self.targetFile + '\'', self.commandString ) | ||||
|         else: | ||||
|             self.finalCommand = self.commandString + ' \'' + self.targetFile + '\'' | ||||
|  | ||||
|         if( self.finalCommand ): | ||||
|             print( "[exec] Executing command: " + self.finalCommand ) | ||||
|             os.system( self.finalCommand ) | ||||
|         else: | ||||
|             raise PostProcessingExecError( "Invalid syntax for --exec post processor" ) | ||||
|  | ||||
|         return None, information  # by default, keep file and do nothing | ||||
|  | ||||
| class PostProcessingExecError( PostProcessingError ): | ||||
|     pass | ||||
		Reference in New Issue
	
	Block a user