aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/postprocessor
diff options
context:
space:
mode:
authormcd1992 <theanonbutinf@gmail.com>2014-08-22 16:40:43 -0500
committermcd1992 <theanonbutinf@gmail.com>2014-08-24 14:38:43 -0500
commita7cacbca2b140f668785d57264914de5585ed699 (patch)
treea14fe74b8e6ce31a22b415cabf56de397dadc1e4 /youtube_dl/postprocessor
parentb8313f07bc8c7565c9255b131d307d10b8d02538 (diff)
downloadyoutube-dl-a7cacbca2b140f668785d57264914de5585ed699.tar.xz
Implemented --exec option.
Diffstat (limited to 'youtube_dl/postprocessor')
-rw-r--r--youtube_dl/postprocessor/__init__.py2
-rw-r--r--youtube_dl/postprocessor/execafterdownload.py36
2 files changed, 38 insertions, 0 deletions
diff --git a/youtube_dl/postprocessor/__init__.py b/youtube_dl/postprocessor/__init__.py
index 08e6ddd00..59ab49e6d 100644
--- a/youtube_dl/postprocessor/__init__.py
+++ b/youtube_dl/postprocessor/__init__.py
@@ -9,6 +9,7 @@ from .ffmpeg import (
FFmpegEmbedSubtitlePP,
)
from .xattrpp import XAttrMetadataPP
+from .execafterdownload import ExecAfterDownload
__all__ = [
'AtomicParsleyPP',
@@ -19,4 +20,5 @@ __all__ = [
'FFmpegExtractAudioPP',
'FFmpegEmbedSubtitlePP',
'XAttrMetadataPP',
+ 'ExecAfterDownload',
]
diff --git a/youtube_dl/postprocessor/execafterdownload.py b/youtube_dl/postprocessor/execafterdownload.py
new file mode 100644
index 000000000..431ab7f08
--- /dev/null
+++ b/youtube_dl/postprocessor/execafterdownload.py
@@ -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