mirror of
https://github.com/l1ving/youtube-dl
synced 2025-03-12 20:57:32 +08:00
Add post processor to move after completion
This commit is contained in:
parent
b3aec47665
commit
fa475857f0
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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',
|
||||
|
27
youtube_dl/postprocessor/move.py
Normal file
27
youtube_dl/postprocessor/move.py
Normal 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
|
Loading…
x
Reference in New Issue
Block a user