add post processor
parent
98acdc895b
commit
0c14e2fbe3
|
@ -90,6 +90,8 @@ from .extractor import gen_extractors
|
||||||
from .version import __version__
|
from .version import __version__
|
||||||
from .YoutubeDL import YoutubeDL
|
from .YoutubeDL import YoutubeDL
|
||||||
from .postprocessor import (
|
from .postprocessor import (
|
||||||
|
AtomicParsleyPP,
|
||||||
|
FFmpegMediaFixPP,
|
||||||
FFmpegMetadataPP,
|
FFmpegMetadataPP,
|
||||||
FFmpegVideoConvertor,
|
FFmpegVideoConvertor,
|
||||||
FFmpegExtractAudioPP,
|
FFmpegExtractAudioPP,
|
||||||
|
@ -497,6 +499,8 @@ def parseOpts(overrideArguments=None):
|
||||||
help='do not overwrite post-processed files; the post-processed files are overwritten by default')
|
help='do not overwrite post-processed files; the post-processed files are overwritten by default')
|
||||||
postproc.add_option('--embed-subs', action='store_true', dest='embedsubtitles', default=False,
|
postproc.add_option('--embed-subs', action='store_true', dest='embedsubtitles', default=False,
|
||||||
help='embed subtitles in the video (only for mp4 videos)')
|
help='embed subtitles in the video (only for mp4 videos)')
|
||||||
|
postproc.add_option('--embed-thumbnail', action='store_true', dest='embedthumbnail', default=False,
|
||||||
|
help='embed thumbnail in the audio as cover art')
|
||||||
postproc.add_option('--add-metadata', action='store_true', dest='addmetadata', default=False,
|
postproc.add_option('--add-metadata', action='store_true', dest='addmetadata', default=False,
|
||||||
help='write metadata to the video file')
|
help='write metadata to the video file')
|
||||||
postproc.add_option('--xattrs', action='store_true', dest='xattrs', default=False,
|
postproc.add_option('--xattrs', action='store_true', dest='xattrs', default=False,
|
||||||
|
@ -803,6 +807,9 @@ def _real_main(argv=None):
|
||||||
ydl.add_post_processor(FFmpegEmbedSubtitlePP(subtitlesformat=opts.subtitlesformat))
|
ydl.add_post_processor(FFmpegEmbedSubtitlePP(subtitlesformat=opts.subtitlesformat))
|
||||||
if opts.xattrs:
|
if opts.xattrs:
|
||||||
ydl.add_post_processor(XAttrMetadataPP())
|
ydl.add_post_processor(XAttrMetadataPP())
|
||||||
|
if opts.embedthumbnail:
|
||||||
|
ydl.add_post_processor(FFmpegMediaFixPP())
|
||||||
|
ydl.add_post_processor(AtomicParsleyPP())
|
||||||
|
|
||||||
# Update version
|
# Update version
|
||||||
if opts.update_self:
|
if opts.update_self:
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
|
|
||||||
|
from .atomicparsley import AtomicParsleyPP
|
||||||
from .ffmpeg import (
|
from .ffmpeg import (
|
||||||
|
FFmpegMediaFixPP,
|
||||||
FFmpegMergerPP,
|
FFmpegMergerPP,
|
||||||
FFmpegMetadataPP,
|
FFmpegMetadataPP,
|
||||||
FFmpegVideoConvertor,
|
FFmpegVideoConvertor,
|
||||||
|
@ -9,6 +11,8 @@ from .ffmpeg import (
|
||||||
from .xattrpp import XAttrMetadataPP
|
from .xattrpp import XAttrMetadataPP
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
|
'AtomicParsleyPP',
|
||||||
|
'FFmpegMediaFixPP',
|
||||||
'FFmpegMergerPP',
|
'FFmpegMergerPP',
|
||||||
'FFmpegMetadataPP',
|
'FFmpegMetadataPP',
|
||||||
'FFmpegVideoConvertor',
|
'FFmpegVideoConvertor',
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
from .common import PostProcessor
|
||||||
|
|
||||||
|
from ..utils import (
|
||||||
|
check_executable,
|
||||||
|
compat_urlretrieve,
|
||||||
|
encodeFilename,
|
||||||
|
PostProcessingError,
|
||||||
|
prepend_extension,
|
||||||
|
shell_quote
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class AtomicParsleyPPError(PostProcessingError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class AtomicParsleyPP(PostProcessor):
|
||||||
|
def __init__(self, downloader=None):
|
||||||
|
PostProcessor.__init__(self, downloader)
|
||||||
|
|
||||||
|
def run(self, info):
|
||||||
|
if not check_executable('AtomicParsley', ['-v']):
|
||||||
|
raise AtomicParsleyPPError('AtomicParsley was not found. Please install.')
|
||||||
|
|
||||||
|
filename = info['filepath']
|
||||||
|
temp_filename = prepend_extension(filename, 'temp')
|
||||||
|
temp_thumbnail = prepend_extension(filename, 'thumb')
|
||||||
|
|
||||||
|
if not info.get('thumbnail'):
|
||||||
|
raise AtomicParsleyPPError('Thumbnail was not found. Nothing to do.')
|
||||||
|
|
||||||
|
compat_urlretrieve(info['thumbnail'], temp_thumbnail)
|
||||||
|
|
||||||
|
cmd = ['AtomicParsley', filename, '--artwork', temp_thumbnail, '-o', temp_filename]
|
||||||
|
|
||||||
|
self._downloader.to_screen('[atomicparsley] Adding thumbnail to "%s"' % filename)
|
||||||
|
|
||||||
|
if self._downloader.params.get('verbose', False):
|
||||||
|
self._downloader.to_screen('[debug] AtomicParsley command line: %s' % shell_quote(cmd))
|
||||||
|
|
||||||
|
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
|
stdout, stderr = p.communicate()
|
||||||
|
|
||||||
|
if p.returncode != 0:
|
||||||
|
msg = stderr.decode('utf-8', 'replace').strip()
|
||||||
|
raise AtomicParsleyPPError(msg)
|
||||||
|
|
||||||
|
os.remove(encodeFilename(filename))
|
||||||
|
os.remove(encodeFilename(temp_thumbnail))
|
||||||
|
os.rename(encodeFilename(temp_filename), encodeFilename(filename))
|
||||||
|
|
||||||
|
return True, info
|
|
@ -483,3 +483,17 @@ class FFmpegMergerPP(FFmpegPostProcessor):
|
||||||
self.run_ffmpeg_multiple_files(info['__files_to_merge'], filename, args)
|
self.run_ffmpeg_multiple_files(info['__files_to_merge'], filename, args)
|
||||||
return True, info
|
return True, info
|
||||||
|
|
||||||
|
|
||||||
|
class FFmpegMediaFixPP(FFmpegPostProcessor):
|
||||||
|
def run(self, info):
|
||||||
|
filename = info['filepath']
|
||||||
|
temp_filename = prepend_extension(filename, 'temp')
|
||||||
|
|
||||||
|
options = ['-vcodec', 'copy', '-acodec', 'copy']
|
||||||
|
self._downloader.to_screen(u'[ffmpeg] Fixing media file "%s"' % filename)
|
||||||
|
self.run_ffmpeg(filename, temp_filename, options)
|
||||||
|
|
||||||
|
os.remove(encodeFilename(filename))
|
||||||
|
os.rename(encodeFilename(temp_filename), encodeFilename(filename))
|
||||||
|
|
||||||
|
return True, info
|
||||||
|
|
Loading…
Reference in New Issue