mirror of
https://github.com/iluvcapra/pycmx.git
synced 2025-12-31 08:50:54 +00:00
Flake8 lints, flake8 linting fully activated.
This commit is contained in:
3
.github/workflows/python-package.yml
vendored
3
.github/workflows/python-package.yml
vendored
@@ -32,8 +32,7 @@ jobs:
|
||||
run: |
|
||||
# stop the build if there are Python syntax errors or undefined names
|
||||
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
|
||||
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
|
||||
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
|
||||
flake8 . --count --max-complexity=10 --max-line-length=79 --statistics
|
||||
- name: Test with pytest
|
||||
run: |
|
||||
pytest
|
||||
|
||||
@@ -12,6 +12,7 @@ logging.basicConfig(format=FORMAT)
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def all_video_edits(edl):
|
||||
for event in edl.events:
|
||||
for edit in event.edits:
|
||||
@@ -30,19 +31,22 @@ def get_scene_name(edit, pattern):
|
||||
else:
|
||||
return edit.clip_name
|
||||
|
||||
|
||||
def output_cmx(outfile, out_list):
|
||||
outfile.write("TITLE: SCENE LIST\r\n")
|
||||
outfile.write("FCM: NON-DROP FRAME\r\n")
|
||||
|
||||
for o in out_list:
|
||||
line = "%03i AX V C 00:00:00:00 00:00:00:00 %s %s\r\n" % (0, o['start'],o['end'])
|
||||
line = "%03i AX V C 00:00:00:00 00:00:00:00 %s %s\r\n" % (
|
||||
0, o['start'], o['end'])
|
||||
outfile.write(line)
|
||||
outfile.write("* FROM CLIP NAME: %s\r\n" % (o['scene']))
|
||||
|
||||
|
||||
def output_cols(outfile, out_list):
|
||||
for o in out_list:
|
||||
outfile.write("%-12s\t%-12s\t%s\n" % (o['start'], o['end'], o['scene'] ))
|
||||
outfile.write("%-12s\t%-12s\t%s\n" %
|
||||
(o['start'], o['end'], o['scene']))
|
||||
|
||||
|
||||
def scene_list(infile, outfile, out_format, pattern):
|
||||
@@ -80,14 +84,14 @@ def scene_list(infile, outfile, out_format, pattern):
|
||||
|
||||
|
||||
def scene_list_cli():
|
||||
parser = argparse.ArgumentParser(description=
|
||||
'Read video events from an input CMX EDL and output events merged into scenes.')
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Read video events from an input CMX EDL and output events merged into scenes.')
|
||||
parser.add_argument('-o', '--outfile', default=sys.stdout, type=argparse.FileType('w'),
|
||||
help='Output file. Default is stdout.')
|
||||
parser.add_argument('-f', '--format', default='cmx', type=str,
|
||||
help='Output format. Options are cols and cmx, cmx is the default.')
|
||||
parser.add_argument('-p', '--pattern', default='V?([A-Z]*[0-9]+)',
|
||||
help='RE pattern for extracting scene name from clip name. The default is "V?([A-Z]*[0-9]+)". ' + \
|
||||
help='RE pattern for extracting scene name from clip name. The default is "V?([A-Z]*[0-9]+)". ' +
|
||||
'This pattern will be matched case-insensitively.')
|
||||
parser.add_argument('input_edl', default=sys.stdin, type=argparse.FileType('r'), nargs='?',
|
||||
help='Input file. Default is stdin.')
|
||||
@@ -95,7 +99,8 @@ def scene_list_cli():
|
||||
|
||||
infile = args.input_edl
|
||||
|
||||
scene_list(infile=infile, outfile=args.outfile , out_format=args.format, pattern=args.pattern)
|
||||
scene_list(infile=infile, outfile=args.outfile,
|
||||
out_format=args.format, pattern=args.pattern)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -2,13 +2,11 @@
|
||||
"""
|
||||
pycmx is a parser for CMX 3600-style EDLs.
|
||||
|
||||
This module (c) 2023 Jamie Hardt. For more information on your rights to
|
||||
This module (c) 2025 Jamie Hardt. For more information on your rights to
|
||||
copy and reuse this software, refer to the LICENSE file included with the
|
||||
distribution.
|
||||
"""
|
||||
|
||||
__version__ = '1.2.2'
|
||||
|
||||
from .parse_cmx_events import parse_cmx3600
|
||||
from .transition import Transition
|
||||
from .event import Event
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
from re import (compile, match)
|
||||
from typing import Dict, Tuple, Generator
|
||||
|
||||
|
||||
class ChannelMap:
|
||||
"""
|
||||
Represents a set of all the channels to which an event applies.
|
||||
@@ -110,4 +111,3 @@ class ChannelMap:
|
||||
out_a = self._audio_channel_set | other._audio_channel_set
|
||||
|
||||
return ChannelMap(v=out_v, audio_channels=out_a)
|
||||
|
||||
|
||||
@@ -7,12 +7,16 @@ from .channel_map import ChannelMap
|
||||
|
||||
from typing import Optional
|
||||
|
||||
|
||||
class Edit:
|
||||
"""
|
||||
An individual source-to-record operation, with a source roll, source and
|
||||
recorder timecode in and out, a transition and channels.
|
||||
"""
|
||||
def __init__(self, edit_statement, audio_ext_statement, clip_name_statement, source_file_statement, trans_name_statement = None):
|
||||
|
||||
def __init__(self, edit_statement, audio_ext_statement,
|
||||
clip_name_statement, source_file_statement,
|
||||
trans_name_statement=None):
|
||||
self.edit_statement = edit_statement
|
||||
self.audio_ext = audio_ext_statement
|
||||
self.clip_name_statement = clip_name_statement
|
||||
@@ -35,7 +39,7 @@ class Edit:
|
||||
"""
|
||||
cm = ChannelMap()
|
||||
cm._append_event(self.edit_statement.channels)
|
||||
if self.audio_ext != None:
|
||||
if self.audio_ext is not None:
|
||||
cm._append_ext(self.audio_ext)
|
||||
return cm
|
||||
|
||||
@@ -45,9 +49,12 @@ class Edit:
|
||||
Get the :obj:`Transition` object associated with this edit.
|
||||
"""
|
||||
if self.trans_name_statement:
|
||||
return Transition(self.edit_statement.trans, self.edit_statement.trans_op, self.trans_name_statement.name)
|
||||
return Transition(self.edit_statement.trans,
|
||||
self.edit_statement.trans_op,
|
||||
self.trans_name_statement.name)
|
||||
else:
|
||||
return Transition(self.edit_statement.trans, self.edit_statement.trans_op, None)
|
||||
return Transition(self.edit_statement.trans,
|
||||
self.edit_statement.trans_op, None)
|
||||
|
||||
@property
|
||||
def source_in(self) -> str:
|
||||
@@ -124,5 +131,3 @@ class Edit:
|
||||
return None
|
||||
else:
|
||||
return self.clip_name_statement.name
|
||||
|
||||
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
# pycmx
|
||||
# (c) 2018 Jamie Hardt
|
||||
|
||||
from .parse_cmx_statements import (StmtUnrecognized, StmtFCM, StmtEvent, StmtSourceUMID)
|
||||
from .parse_cmx_statements import (
|
||||
StmtUnrecognized, StmtEvent, StmtSourceUMID)
|
||||
from .event import Event
|
||||
from .channel_map import ChannelMap
|
||||
|
||||
from typing import Generator
|
||||
|
||||
|
||||
class EditList:
|
||||
"""
|
||||
Represents an entire edit decision list as returned by :func:`~pycmx.parse_cmx3600()`.
|
||||
Represents an entire edit decision list as returned by
|
||||
:func:`~pycmx.parse_cmx3600()`.
|
||||
"""
|
||||
|
||||
def __init__(self, statements):
|
||||
self.title_statement = statements[0]
|
||||
self.event_statements = statements[1:]
|
||||
@@ -23,7 +27,8 @@ class EditList:
|
||||
|
||||
Adobe EDLs with more than 999 events will be reported as "3600".
|
||||
"""
|
||||
first_event = next( (s for s in self.event_statements if type(s) is StmtEvent), None)
|
||||
first_event = next(
|
||||
(s for s in self.event_statements if type(s) is StmtEvent), None)
|
||||
|
||||
if first_event:
|
||||
if first_event.format == 8:
|
||||
@@ -37,7 +42,6 @@ class EditList:
|
||||
else:
|
||||
return 'unknown'
|
||||
|
||||
|
||||
@property
|
||||
def channels(self) -> ChannelMap:
|
||||
"""
|
||||
@@ -51,7 +55,6 @@ class EditList:
|
||||
|
||||
return retval
|
||||
|
||||
|
||||
@property
|
||||
def title(self) -> str:
|
||||
"""
|
||||
@@ -59,9 +62,9 @@ class EditList:
|
||||
"""
|
||||
return self.title_statement.title
|
||||
|
||||
|
||||
@property
|
||||
def unrecognized_statements(self) -> Generator[StmtUnrecognized, None, None]:
|
||||
def unrecognized_statements(self) -> Generator[StmtUnrecognized,
|
||||
None, None]:
|
||||
"""
|
||||
A generator for all the unrecognized statements in the list.
|
||||
"""
|
||||
@@ -69,17 +72,13 @@ class EditList:
|
||||
if type(s) is StmtUnrecognized:
|
||||
yield s
|
||||
|
||||
|
||||
@property
|
||||
def events(self) -> Generator[Event, None, None]:
|
||||
'A generator for all the events in the edit list'
|
||||
is_drop = None
|
||||
current_event_num = None
|
||||
event_statements = []
|
||||
for stmt in self.event_statements:
|
||||
if type(stmt) is StmtFCM:
|
||||
is_drop = stmt.drop
|
||||
elif type(stmt) is StmtEvent:
|
||||
if type(stmt) is StmtEvent:
|
||||
if current_event_num is None:
|
||||
current_event_num = stmt.event
|
||||
event_statements.append(stmt)
|
||||
@@ -107,5 +106,3 @@ class EditList:
|
||||
for stmt in self.event_statements:
|
||||
if type(stmt) is StmtSourceUMID:
|
||||
yield stmt
|
||||
|
||||
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
# pycmx
|
||||
# (c) 2023 Jamie Hardt
|
||||
|
||||
from .parse_cmx_statements import (StmtEvent, StmtClipName, StmtSourceFile, StmtAudioExt, StmtUnrecognized, StmtEffectsName)
|
||||
from .parse_cmx_statements import (
|
||||
StmtEvent, StmtClipName, StmtSourceFile, StmtAudioExt, StmtUnrecognized,
|
||||
StmtEffectsName)
|
||||
from .edit import Edit
|
||||
|
||||
from typing import List, Generator, Optional, Tuple, Any
|
||||
|
||||
|
||||
class Event:
|
||||
"""
|
||||
Represents a collection of :class:`~pycmx.edit.Edit` s, all with the same event number.
|
||||
"""
|
||||
Represents a collection of :class:`~pycmx.edit.Edit` s, all with the same
|
||||
event number. """
|
||||
|
||||
def __init__(self, statements):
|
||||
self.statements = statements
|
||||
@@ -71,10 +74,12 @@ class Event:
|
||||
audio_ext_statement=e1[1],
|
||||
clip_name_statement=n1,
|
||||
source_file_statement=s1,
|
||||
trans_name_statement=u1) for (e1,n1,s1,u1) in zip(*the_zip) ]
|
||||
trans_name_statement=u1)
|
||||
for (e1, n1, s1, u1) in zip(*the_zip)]
|
||||
|
||||
@property
|
||||
def unrecognized_statements(self) -> Generator[StmtUnrecognized, None, None]:
|
||||
def unrecognized_statements(self) -> Generator[StmtUnrecognized, None,
|
||||
None]:
|
||||
"""
|
||||
A generator for all the unrecognized statements in the event.
|
||||
"""
|
||||
@@ -94,11 +99,10 @@ class Event:
|
||||
def _source_file_statements(self) -> List[StmtSourceFile]:
|
||||
return [s for s in self.statements if type(s) is StmtSourceFile]
|
||||
|
||||
def _statements_with_audio_ext(self) -> Generator[Tuple[StmtEvent, Optional[StmtAudioExt]], None, None]:
|
||||
def _statements_with_audio_ext(self) -> Generator[
|
||||
Tuple[StmtEvent, Optional[StmtAudioExt]], None, None]:
|
||||
for (s1, s2) in zip(self.statements, self.statements[1:]):
|
||||
if type(s1) is StmtEvent and type(s2) is StmtAudioExt:
|
||||
yield (s1, s2)
|
||||
elif type(s1) is StmtEvent:
|
||||
yield (s1, None)
|
||||
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ from .edit_list import EditList
|
||||
|
||||
from typing import TextIO
|
||||
|
||||
|
||||
def parse_cmx3600(f: TextIO) -> EditList:
|
||||
"""
|
||||
Parse a CMX 3600 EDL.
|
||||
@@ -17,4 +18,3 @@ def parse_cmx3600(f: TextIO) -> EditList:
|
||||
"""
|
||||
statements = parse_cmx3600_statements(f)
|
||||
return EditList(statements)
|
||||
|
||||
|
||||
@@ -61,19 +61,18 @@ def _parse_cmx3600_line(line: str, line_number: int) -> object:
|
||||
long_event_num_p = re.compile("^[0-9]{6} ")
|
||||
short_event_num_p = re.compile("^[0-9]{3} ")
|
||||
|
||||
|
||||
if isinstance(line, str):
|
||||
if line.startswith("TITLE:"):
|
||||
return _parse_title(line, line_number)
|
||||
elif line.startswith("FCM:"):
|
||||
return _parse_fcm(line, line_number)
|
||||
elif long_event_num_p.match(line) != None:
|
||||
elif long_event_num_p.match(line) is not None:
|
||||
length_file_128 = sum(_edl_column_widths(6, 128))
|
||||
if len(line) < length_file_128:
|
||||
return _parse_long_standard_form(line, 32, line_number)
|
||||
else:
|
||||
return _parse_long_standard_form(line, 128, line_number)
|
||||
elif short_event_num_p.match(line) != None:
|
||||
elif short_event_num_p.match(line) is not None:
|
||||
return _parse_standard_form(line, line_number)
|
||||
elif line.startswith("AUD"):
|
||||
return _parse_extended_audio_channels(line, line_number)
|
||||
@@ -185,5 +184,5 @@ def _parse_columns_for_standard_form(line, event_field_length,
|
||||
|
||||
|
||||
def _parse_source_umid_statement(line, line_number):
|
||||
trimmed = line[3:].strip()
|
||||
# trimmed = line[3:].strip()
|
||||
return StmtSourceUMID(name=None, umid=None, line_number=line_number)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
from typing import Optional
|
||||
|
||||
|
||||
class Transition:
|
||||
"""
|
||||
A CMX transition: a wipe, dissolve or cut.
|
||||
@@ -86,5 +87,3 @@ class Transition:
|
||||
the key foreground and replaced with the key background.
|
||||
"""
|
||||
return self.transition == Transition.KeyOut
|
||||
|
||||
|
||||
|
||||
@@ -28,4 +28,3 @@ def collimate(a_string, column_widths):
|
||||
element = a_string[:width]
|
||||
rest = a_string[width:]
|
||||
return [element] + collimate(rest, column_widths[1:])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user