1 # ExecAfterDownload written by AaronM / mcd1992.
2 # If there are any issues with this postprocessor please contact me via github or admin@fgthou.se
5 from ..utils import PostProcessingError
7 class ExecAfterDownload( object ):
10 def __init__( self, downloader = None, commandString = None ):
11 self._downloader = downloader
12 self.commandString = commandString
14 def set_downloader( self, downloader ):
15 """Sets the downloader for this PP."""
16 self._downloader = downloader
18 def run( self, information ):
19 self.targetFile = information["filepath"]
20 self.finalCommand = None;
22 if( re.search( '{}', self.commandString ) ): # Find and replace all occurrences of {} with the file name.
23 self.finalCommand = re.sub( "{}", '\'' + self.targetFile + '\'', self.commandString )
25 self.finalCommand = self.commandString + ' \'' + self.targetFile + '\''
27 if( self.finalCommand ):
28 print( "[exec] Executing command: " + self.finalCommand )
29 os.system( self.finalCommand )
31 raise PostProcessingExecError( "Invalid syntax for --exec post processor" )
33 return None, information # by default, keep file and do nothing
35 class PostProcessingExecError( PostProcessingError ):