diff --git a/readme.md b/readme.md index 4007ebd95..59434f2a5 100644 --- a/readme.md +++ b/readme.md @@ -20,6 +20,13 @@ Allows you to download and transcode video from supported sites. Needs ffmpeg fo $ sudo wget --no-check-certificate https://github.com/dz0ny/youtube-dl/raw/master/youtube-dl -O /usr/local/bin/youtube-dl && sudo chmod a+x /usr/local/bin/youtube-dl ## Usage + +### Example + + $ youtube-dl http://www.youtube.com/watch?v=BRHRssf3B6o -T mp4 -C 'sh -c "cp .mp4 && rm "' + + Command line options: + $ youtube-dl [options] url... Options: @@ -86,11 +93,17 @@ Allows you to download and transcode video from supported sites. Needs ffmpeg fo pass additional parameters to ffmpeg (example: -vcodec libx264 -vpre slow -vpre ipod640 -b 2048k -acodec libfaac -ab 96k) + + Post download action: + -C COMMAND, --command=COMMAND + command to run after file has been downloaded + (example: 'sh -c "cp .mp4 && rm "' ) # License Public domain code + # Authors * Ricardo Garcia Gonzalez diff --git a/youtube-dl b/youtube-dl index 6d29452e7..8b1aa9a25 100755 --- a/youtube-dl +++ b/youtube-dl @@ -2639,7 +2639,7 @@ class Transcode(PostProcessor): self._downloader.to_screen(u'[transcode] Started transcoding of %s to %s' % ( self._file_path, self._new_file_path) ) stringish_command = 'ffmpeg -y -i "%s" %s "%s"' % (self._file_path, self.args, self._new_file_path) self.encode(stringish_command) - return None + return information def encode(self, cmd): pipe = subprocess.Popen( @@ -2652,6 +2652,27 @@ class Transcode(PostProcessor): pass self._downloader.to_screen(u'[transcode] Completed transcoding of %s to %s' % ( self._file_path, self._new_file_path) ) +class SimplePostProcessor(PostProcessor): + """Post Processor for file transcoding""" + def __init__(self,command): + self.command_raw = command + PostProcessor.__init__(self, None) + + def run(self, information): + for key, value in information.iteritems(): + self.command_raw = self.command_raw.replace("<" + key + ">", value) + self.command = shlex.split( str( self.command_raw ) ) + self._downloader.to_screen(u'[PostProcessor] Started command %s' % self.command_raw ) + pipe = subprocess.Popen( + ( self.command ) + ) + retval = pipe.wait() + while retval == 2 or retval == 1: + pass + self._downloader.to_screen(u'[PostProcessor] Finnished command %s' % self.command_raw ) + + return information + ### MAIN PROGRAM ### if __name__ == '__main__': try: @@ -2783,6 +2804,11 @@ if __name__ == '__main__': action='store', dest='transcode_extra', metavar='ARGS', help='pass additional parameters to ffmpeg (example: -vcodec libx264 -vpre slow -vpre ipod640 -b 2048k -acodec libfaac -ab 96k)', default=False) parser.add_option_group(transcode) + postprocess = optparse.OptionGroup(parser, 'Post download action') + postprocess.add_option('-C','--command', + action='store', dest='post_download_command', metavar='COMMAND', help='command to run after file has been downloaded (example: "sh -c cp /tmp/.tmp && rm <filepath>" )', default=False) + parser.add_option_group(postprocess) + (opts, args) = parser.parse_args() # Open appropriate CookieJar @@ -2934,6 +2960,14 @@ if __name__ == '__main__': except PostProcessingError, err: sys.exit(err) + # Custom command parser + if opts.post_download_command: + try: + post_download_command = SimplePostProcessor(opts.post_download_command) + fd.add_post_processor(post_download_command) + except PostProcessingError, err: + sys.exit(err) + # Update version if opts.update_self: update_self(fd, sys.argv[0])