1
0
mirror of https://github.com/l1ving/youtube-dl synced 2025-03-13 01:27:27 +08:00

Add post processor to move after completion

This commit is contained in:
Balasankar C 2017-02-26 12:48:29 +05:30
parent b3aec47665
commit fa475857f0
No known key found for this signature in database
GPG Key ID: 96EDAB9B2E6B7171
4 changed files with 37 additions and 0 deletions

View File

@ -290,6 +290,11 @@ def _real_main(argv=None):
'key': 'ExecAfterDownload',
'exec_cmd': opts.exec_cmd,
})
if opts.move:
postprocessors.append({
'key': 'Move',
'destination': opts.move,
})
external_downloader_args = None
if opts.external_downloader_args:
external_downloader_args = compat_shlex_split(opts.external_downloader_args)

View File

@ -845,6 +845,9 @@ def parseOpts(overrideArguments=None):
'--convert-subs', '--convert-subtitles',
metavar='FORMAT', dest='convertsubtitles', default=None,
help='Convert the subtitles to other format (currently supported: srt|ass|vtt)')
postproc.add_option(
'--move', metavar="DESTINATION", dest='move',
help="Specify directory to move completed files to")
parser.add_option_group(general)
parser.add_option_group(network)

View File

@ -16,6 +16,7 @@ from .ffmpeg import (
from .xattrpp import XAttrMetadataPP
from .execafterdownload import ExecAfterDownloadPP
from .metadatafromtitle import MetadataFromTitlePP
from .move import MovePP
def get_postprocessor(key):
@ -25,6 +26,7 @@ def get_postprocessor(key):
__all__ = [
'EmbedThumbnailPP',
'ExecAfterDownloadPP',
'MovePP',
'FFmpegEmbedSubtitlePP',
'FFmpegExtractAudioPP',
'FFmpegFixupM3u8PP',

View File

@ -0,0 +1,27 @@
from __future__ import unicode_literals
import subprocess
import os
import shutil
from .common import PostProcessor
from ..utils import PostProcessingError
class MovePP(PostProcessor):
def __init__(self, downloader, destination):
super(MovePP, self).__init__(downloader)
self.destination = destination
def run(self, information):
source = os.path.abspath(information['filepath'])
destination = os.path.abspath(self.destination)
if not os.path.exists(source):
raise PostProcessingError('Source file not available')
if not os.path.exists(destination):
raise PostProcessingError('Destination not available')
self._downloader.to_screen(
'[exec] Moving %s to %s' % (source, destination))
shutil.move(source, destination)
return [], information