Merge pull request #83 from kkroening/feature-30

#30: add `global_args` operator
This commit is contained in:
Karl Kroening 2018-05-09 03:29:24 -05:00 committed by GitHub
commit 2a2d5a43f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 9 deletions

View File

@ -1,5 +1,6 @@
from __future__ import unicode_literals
from past.builtins import basestring
from ._utils import basestring
from .nodes import (
@ -26,13 +27,20 @@ def input(filename, **kwargs):
return InputNode(input.__name__, kwargs=kwargs).stream()
@output_operator()
def global_args(stream, *args):
"""Add extra global command-line argument(s), e.g. ``-progress``.
"""
return GlobalNode(stream, global_args.__name__, args).stream()
@output_operator()
def overwrite_output(stream):
"""Overwrite output files without asking (ffmpeg ``-y`` option)
Official documentation: `Main options <https://ffmpeg.org/ffmpeg.html#Main-options>`__
"""
return GlobalNode(stream, overwrite_output.__name__).stream()
return GlobalNode(stream, overwrite_output.__name__, ['-y']).stream()
@output_operator()

View File

@ -1,5 +1,7 @@
from __future__ import unicode_literals
from builtins import str
from past.builtins import basestring
from .dag import get_outgoing_edges, topo_sort
from functools import reduce
from ._utils import basestring
@ -10,7 +12,6 @@ import subprocess as _subprocess
from ._ffmpeg import (
input,
output,
overwrite_output,
)
from .nodes import (
get_stream_spec_nodes,
@ -92,10 +93,7 @@ def _get_filter_arg(filter_nodes, outgoing_edge_maps, stream_name_map):
def _get_global_args(node):
if node.name == overwrite_output.__name__:
return ['-y']
else:
raise ValueError('Unsupported global node: {}'.format(node))
return list(node.args)
def _get_output_args(node, stream_name_map):

View File

@ -1,10 +1,12 @@
from __future__ import unicode_literals
from builtins import str
from past.builtins import basestring
import hashlib
import sys
if sys.version_info.major == 2:
# noinspection PyUnresolvedReferences,PyShadowingBuiltins
str = unicode
str = str
# `past.builtins.basestring` module can't be imported on Python3 in some environments (Ubuntu).

View File

@ -75,7 +75,7 @@ DagEdge = namedtuple('DagEdge', ['downstream_node', 'downstream_label', 'upstrea
def get_incoming_edges(downstream_node, incoming_edge_map):
edges = []
for downstream_label, upstream_info in incoming_edge_map.items():
for downstream_label, upstream_info in list(incoming_edge_map.items()):
upstream_node, upstream_label, upstream_selector = upstream_info
edges += [DagEdge(downstream_node, downstream_label, upstream_node, upstream_label, upstream_selector)]
return edges
@ -97,7 +97,7 @@ class KwargReprNode(DagNode):
@property
def __upstream_hashes(self):
hashes = []
for downstream_label, upstream_info in self.incoming_edge_map.items():
for downstream_label, upstream_info in list(self.incoming_edge_map.items()):
upstream_node, upstream_label, upstream_selector = upstream_info
hashes += [hash(x) for x in [downstream_label, upstream_node, upstream_label, upstream_selector]]
return hashes

View File

@ -1,5 +1,6 @@
from __future__ import unicode_literals
from past.builtins import basestring
from .dag import KwargReprNode
from ._utils import escape_chars, get_hash_int
from builtins import object

View File

@ -1,5 +1,6 @@
from __future__ import unicode_literals
from builtins import str
from builtins import bytes
from builtins import range
import ffmpeg
@ -105,6 +106,11 @@ def test_get_args_simple():
assert out_file.get_args() == ['-i', 'dummy.mp4', 'dummy2.mp4']
def test_global_args():
out_file = ffmpeg.input('dummy.mp4').output('dummy2.mp4').global_args('-progress', 'someurl')
assert out_file.get_args() == ['-i', 'dummy.mp4', 'dummy2.mp4', '-progress', 'someurl']
def _get_complex_filter_example():
split = (ffmpeg
.input(TEST_INPUT_FILE1)