Skip to content

Commit 12f5877

Browse files
committed
Kdenlive adapter: autopep8
1 parent 685cb71 commit 12f5877

File tree

3 files changed

+68
-68
lines changed

3 files changed

+68
-68
lines changed

contrib/opentimelineio_contrib/adapters/kdenlive.py

Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (C) 2019 Vincent Pinon <vpinon@kde.org>
2+
# Copyright (C) 2019 Kdenlive developers <kdenlive@kde.org>
33
#
44
# Licensed under the Apache License, Version 2.0 (the "Apache License")
55
# with the following modification; you may not use this file except in
@@ -60,15 +60,15 @@ def read_from_string(input_str):
6060
rate = float(profile.get("frame_rate_num")) \
6161
/ float(profile.get("frame_rate_den", 1))
6262
timeline = otio.schema.Timeline(
63-
name=mlt.get("name", "Kdenlive imported timeline"))
63+
name=mlt.get("name", "Kdenlive imported timeline"))
6464

6565
maintractor = mlt.find("tractor[@global_feed='1']")
6666
for maintrack in maintractor.findall("track"):
6767
if maintrack.get("producer") == 'black_track':
6868
continue
6969
subtractor = byid[maintrack.get("producer")]
7070
track = otio.schema.Track(
71-
name=mlt_property(subtractor, "kdenlive:track_name"))
71+
name=mlt_property(subtractor, "kdenlive:track_name"))
7272
if bool(mlt_property(subtractor, "kdenlive:audio_track")):
7373
track.kind = otio.schema.TrackKind.Audio
7474
else:
@@ -78,31 +78,31 @@ def read_from_string(input_str):
7878
for item in playlist.iter():
7979
if item.tag == 'blank':
8080
gap = otio.schema.Gap(
81-
duration=time(item.get("length"), rate))
81+
duration=time(item.get("length"), rate))
8282
track.append(gap)
8383
elif item.tag == 'entry':
8484
producer = byid[item.get("producer")]
8585
service = mlt_property(producer, "mlt_service")
8686
available_range = otio.opentime.TimeRange(
8787
start_time=time(producer.get("in"), rate),
88-
duration=time(producer.get("out"), rate)
89-
- time(producer.get("in"), rate))
88+
duration=time(producer.get("out"), rate) -
89+
time(producer.get("in"), rate))
9090
source_range = otio.opentime.TimeRange(
9191
start_time=time(item.get("in"), rate),
92-
duration=time(item.get("out"), rate)
93-
- time(item.get("in"), rate))
92+
duration=time(item.get("out"), rate) -
93+
time(item.get("in"), rate))
9494
# media reference clip
9595
reference = None
9696
if service in ["avformat", "avformat-novalidate", "qimage"]:
9797
reference = otio.schema.ExternalReference(
98-
target_url=mlt_property(producer, 'kdenlive:originalurl')
99-
or mlt_property(producer, 'resource'),
100-
available_range=available_range)
98+
target_url=mlt_property(producer, 'kdenlive:originalurl') or
99+
mlt_property(producer, 'resource'),
100+
available_range=available_range)
101101
elif service == "color":
102102
reference = otio.schema.GeneratorReference(
103-
generator_kind="SolidColor",
104-
parameters={"color": mlt_property(producer, "resource")},
105-
available_range=available_range)
103+
generator_kind="SolidColor",
104+
parameters={"color": mlt_property(producer, "resource")},
105+
available_range=available_range)
106106
clip = otio.schema.Clip(
107107
name=mlt_property(producer, 'kdenlive:clipname'),
108108
source_range=source_range,
@@ -140,11 +140,11 @@ def read_from_string(input_str):
140140
for transition in maintractor.findall("transition"):
141141
kdenlive_id = mlt_property(transition, "kdenlive_id")
142142
if kdenlive_id == "wipe":
143-
timeline.tracks[int(mlt_property(transition, "b_track"))-1].append(
144-
otio.schema.Transition(
145-
transition_type=otio.schema.TransitionTypes.SMPTE_Dissolve,
146-
in_offset=time(transition.get("in"), rate),
147-
out_offset=time(transition.get("out"), rate)))
143+
timeline.tracks[int(mlt_property(transition, "b_track")) - 1].append(
144+
otio.schema.Transition(
145+
transition_type=otio.schema.TransitionTypes.SMPTE_Dissolve,
146+
in_offset=time(transition.get("in"), rate),
147+
out_offset=time(transition.get("out"), rate)))
148148

149149
return timeline
150150

@@ -165,22 +165,22 @@ def write_to_string(input_otio):
165165
"producer": "main_bin"})
166166
rate = input_otio.duration().rate
167167
(rate_num, rate_den) = {
168-
23.98: (24000, 1001),
169-
29.97: (30000, 1001),
170-
59.94: (60000, 1001)
171-
}.get(round(float(rate), 2), (int(rate), 1))
168+
23.98: (24000, 1001),
169+
29.97: (30000, 1001),
170+
59.94: (60000, 1001)
171+
}.get(round(float(rate), 2), (int(rate), 1))
172172
ET.SubElement(mlt, "profile", {
173-
"description": f"HD 1080p {rate} fps",
174-
"frame_rate_num": str(rate_num),
175-
"frame_rate_den": str(rate_den),
176-
"width": "1920",
177-
"height": "1080",
178-
"display_aspect_num": "16",
179-
"display_aspect_den": "9",
180-
"sample_aspect_num": "1",
181-
"sample_aspect_den": "1",
182-
"colorspace": "709",
183-
"progressive": "1"})
173+
"description": f"HD 1080p {rate} fps",
174+
"frame_rate_num": str(rate_num),
175+
"frame_rate_den": str(rate_den),
176+
"width": "1920",
177+
"height": "1080",
178+
"display_aspect_num": "16",
179+
"display_aspect_den": "9",
180+
"sample_aspect_num": "1",
181+
"sample_aspect_den": "1",
182+
"colorspace": "709",
183+
"progressive": "1"})
184184

185185
# build media library, indexed by url
186186
main_bin = ET.Element("playlist", {"id": "main_bin"})
@@ -203,9 +203,9 @@ def write_to_string(input_otio):
203203
continue
204204
producer = ET.SubElement(mlt, "producer", {
205205
"id": f"producer{len(media_prod)}",
206-
"in": str(int(clip.media_reference.available_range.start_time.value)),
207-
"out": str(int((clip.media_reference.available_range.start_time
208-
+ clip.media_reference.available_range.duration).value))})
206+
"in": str(int(clip.media_reference.available_range.start_time.value)),
207+
"out": str(int((clip.media_reference.available_range.start_time +
208+
clip.media_reference.available_range.duration).value))})
209209
ET.SubElement(main_bin, "entry", {"producer": f"producer{len(media_prod)}"})
210210
add_property(producer, "mlt_service", service)
211211
add_property(producer, "resource", resource)
@@ -214,7 +214,7 @@ def write_to_string(input_otio):
214214
media_prod[resource] = producer
215215

216216
unsupported = ET.SubElement(mlt, "producer",
217-
{"id": "unsupported", "in": "0", "out": "10000"})
217+
{"id": "unsupported", "in": "0", "out": "10000"})
218218
add_property(unsupported, "mlt_service", "qtext")
219219
add_property(unsupported, "family", "Courier")
220220
add_property(unsupported, "fgcolour", "#ff808080")
@@ -240,21 +240,21 @@ def write_to_string(input_otio):
240240
add_property(subtractor, "kdenlive:track_name", track.name)
241241

242242
ET.SubElement(subtractor, "track", {
243-
"producer": f"playlist{track_count}_1",
244-
"hide": "audio" if track.kind == otio.schema.TrackKind.Video
245-
else "video"})
243+
"producer": f"playlist{track_count}_1",
244+
"hide": "audio" if track.kind == otio.schema.TrackKind.Video
245+
else "video"})
246246
ET.SubElement(subtractor, "track", {
247-
"producer": f"playlist{track_count}_2",
248-
"hide": "audio" if track.kind == otio.schema.TrackKind.Video
249-
else "video"})
247+
"producer": f"playlist{track_count}_2",
248+
"hide": "audio" if track.kind == otio.schema.TrackKind.Video
249+
else "video"})
250250
playlist = ET.SubElement(mlt, "playlist",
251251
{"id": f"playlist{track_count}_1"})
252252
playlist_ = ET.SubElement(mlt, "playlist",
253253
{"id": f"playlist{track_count}_2"})
254254
if track.kind == otio.schema.TrackKind.Audio:
255255
add_property(subtractor, "kdenlive:audio_track", "1")
256-
add_property(playlist, "kdenlive:audio_track", "1")
257-
add_property(playlist_, "kdenlive:audio_track", "1")
256+
add_property(playlist, "kdenlive:audio_track", "1")
257+
add_property(playlist_, "kdenlive:audio_track", "1")
258258

259259
for item in track:
260260
if isinstance(item, otio.schema.Gap):
@@ -272,13 +272,13 @@ def write_to_string(input_otio):
272272
and item.media_reference.generator_kind == "SolidColor":
273273
resource = item.media_reference.parameters["color"]
274274
ET.SubElement(playlist, "entry", {
275-
"producer": media_prod[resource].attrib["id"]
276-
if item.media_reference
277-
and not item.media_reference.is_missing_reference
278-
else "unsupported",
279-
"in": str(int(item.source_range.start_time.value)),
280-
"out": str(int((item.source_range.duration
281-
+ item.source_range.start_time).value))})
275+
"producer": media_prod[resource].attrib["id"]
276+
if item.media_reference and
277+
not item.media_reference.is_missing_reference
278+
else "unsupported",
279+
"in": str(int(item.source_range.start_time.value)),
280+
"out": str(int((item.source_range.duration +
281+
item.source_range.start_time).value))})
282282
# Effects handling to be added
283283
# for effect in item.effects:
284284
elif isinstance(item, otio.schema.Transition):
@@ -292,7 +292,8 @@ def write_to_string(input_otio):
292292

293293
if __name__ == "__main__":
294294
# timeline = otio.adapters.read_from_file("tests/sample_data/kdenlive_example.kdenlive")
295-
timeline = read_from_string(open("tests/sample_data/kdenlive_example.kdenlive", "r").read())
295+
timeline = read_from_string(
296+
open("tests/sample_data/kdenlive_example.kdenlive", "r").read())
296297
# print(otio.adapters.write_to_string(timeline, "otio_json"))
297298
print(str(timeline).replace("otio.schema", "\notio.schema"))
298299
xml = write_to_string(timeline)

contrib/opentimelineio_contrib/adapters/tests/sample_data/kdenlive_example.kdenlive

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version='1.0' encoding='utf-8'?>
2-
<mlt title="Anonymous Submission" LC_NUMERIC="en_US.UTF-8" producer="main_bin" version="6.17.0" root="C:/opt/home/kdenlive">
2+
<mlt title="Anonymous Submission" LC_NUMERIC="en_US.UTF-8" producer="main_bin" version="6.17.0" root="/opt/kdenlive">
33
<profile frame_rate_num="25" sample_aspect_num="16" display_aspect_den="3" colorspace="601" progressive="0" description="DV/DVD PAL" display_aspect_num="4" frame_rate_den="1" width="720" height="576" sample_aspect_den="15"/>
44
<producer title="Anonymous Submission" id="producer2" in="00:00:00.000" out="00:05:48.000">
55
<property name="length">8701</property>

contrib/opentimelineio_contrib/adapters/tests/test_kdenlive_adapter.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#/usr/bin/env python
21
import unittest
32
import opentimelineio as otio
43
import opentimelineio.test_utils as otio_test_utils
@@ -12,28 +11,28 @@ def __init__(self, *args, **kwargs):
1211

1312
def test_library_roundtrip(self):
1413
timeline = otio.adapters.read_from_file(
15-
os.path.join( os.path.dirname(__file__), "sample_data",
16-
"kdenlive_example.kdenlive"))
14+
os.path.join(os.path.dirname(__file__), "sample_data",
15+
"kdenlive_example.kdenlive"))
1716

1817
self.assertIsNotNone(timeline)
1918
self.assertEqual(len(timeline.tracks), 5)
2019

2120
self.assertEqual(len(timeline.video_tracks()), 2)
2221
self.assertEqual(len(timeline.audio_tracks()), 3)
2322

24-
clip_urls = ( ('AUD0002.OGG',),
25-
('AUD0001.OGG', 'AUD0001.OGG'),
26-
('VID0001.MKV', 'VID0001.MKV'),
27-
('VID0001.MKV', 'VID0001.MKV'),
28-
('VID0002.MKV', 'VID0003.MKV') )
23+
clip_urls = (('AUD0002.OGG',),
24+
('AUD0001.OGG', 'AUD0001.OGG'),
25+
('VID0001.MKV', 'VID0001.MKV'),
26+
('VID0001.MKV', 'VID0001.MKV'),
27+
('VID0002.MKV', 'VID0003.MKV'))
2928

3029
for n, track in enumerate(timeline.tracks):
3130
self.assertTupleEqual(clip_urls[n],
32-
tuple(c.media_reference.target_url
33-
for c in track
34-
if isinstance(c, otio.schema.Clip)
35-
and isinstance(c.media_reference, otio.schema.ExternalReference)
36-
))
31+
tuple(c.media_reference.target_url
32+
for c in track
33+
if isinstance(c, otio.schema.Clip) and
34+
isinstance(c.media_reference, otio.schema.ExternalReference)
35+
))
3736

3837
kdenlive_xml = otio.adapters.write_to_string(timeline, "kdenlive")
3938
self.assertIsNotNone(kdenlive_xml)

0 commit comments

Comments
 (0)