Skip to content

Commit

Permalink
Use black to reformat / autofix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonm23 committed Sep 1, 2024
1 parent fbaaa0a commit 1a1dc0c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 39 deletions.
32 changes: 18 additions & 14 deletions get_edl_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
def help():
script = os.path.basename(__file__)

print(inspect.cleandoc(f'''
print(
inspect.cleandoc(
f"""
Get .edl sources
Print an unsorted list of unique primary media files
Expand All @@ -17,37 +19,39 @@ def help():
Usage:
python3 {script} <edlfile.edl>
'''))
"""
)
)


def media_filename(line):
return line.split(',')[0]
return line.split(",")[0]


def get_edl_media(edl_filename):
'''
"""
Open edl_filename and read the contents,
parse out and return the unique media filenames.
'''
"""
media = set()

nested_edls = set()

with open(edl_filename, 'r') as edl_file:
with open(edl_filename, "r") as edl_file:
for line in edl_file:
line = line.rstrip()

_, ext = os.path.splitext(line)

# Ignore comments and file header
if line.startswith('#'):
if line.startswith("#"):
continue

# Ignore stream commands etc.
if line.startswith('!'):
if line.startswith("!"):
continue

if ext == '.edl':
if ext == ".edl":
nested_edls.add(line)
continue

Expand All @@ -66,17 +70,17 @@ def get_edl_media(edl_filename):
return media


if __name__ == '__main__':
if __name__ == "__main__":
if len(sys.argv) != 2:
help()
quit()

edl = sys.argv[1]
if os.path.exists(edl):
filename, ext = os.path.splitext(edl)
if ext == '.edl':
print('\n'.join(get_edl_media(edl)))
if ext == ".edl":
print("\n".join(get_edl_media(edl)))
else:
print(f'Not an edl file: {edl}')
print(f"Not an edl file: {edl}")
else:
print(f'File not found: {edl}')
print(f"File not found: {edl}")
50 changes: 25 additions & 25 deletions test_get_edl_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,58 +6,58 @@


def fixture(name):
return os.path.join(os.path.dirname(__file__), 'fixtures', name)
return os.path.join(os.path.dirname(__file__), "fixtures", name)


class TestGetEdlMedia(unittest.TestCase):

def test_get_edl_media_exclude_blank(self):
edl_file = fixture('test1.edl')
edl_file = fixture("test1.edl")
media = get_edl_media(edl_file)

self.assertNotIn('', media)
self.assertNotIn("", media)

def test_get_edl_media_exclude_header(self):
edl_file = fixture('test1.edl')
edl_file = fixture("test1.edl")
media = get_edl_media(edl_file)

self.assertNotIn('#mpv EDL v0', media)
self.assertNotIn("#mpv EDL v0", media)

def test_get_edl_media_exclude_commands(self):
edl_file = fixture('test1.edl')
edl_file = fixture("test1.edl")
media = get_edl_media(edl_file)

self.assertNotIn('!new_stream', media)
self.assertNotIn("!new_stream", media)

def test_get_edl_media_flat_file(self):
edl_file = fixture('test1.edl')
edl_file = fixture("test1.edl")
media = get_edl_media(edl_file)

self.assertIn('video.mp4', media)
self.assertIn('video1.mp4', media)
self.assertIn('video3.mp4', media)
self.assertIn('audio.mp3', media)
self.assertIn("video.mp4", media)
self.assertIn("video1.mp4", media)
self.assertIn("video3.mp4", media)
self.assertIn("audio.mp3", media)

def test_get_edl_media_recursive(self):
edl_file = fixture('test2.edl')
edl_file = fixture("test2.edl")
media = get_edl_media(edl_file)

self.assertNotIn('fixtures/test1.edl', media)
self.assertIn('video5.mp4', media)
self.assertIn('video.mp4', media)
self.assertIn('video0.mp4', media)
self.assertIn('video1.mp4', media)
self.assertIn('video3.mp4', media)
self.assertIn('video4.mp4', media)
self.assertIn('audio.mp3', media)
self.assertIn('/Volumes/spare/videos/video.mp4', media)
self.assertNotIn("fixtures/test1.edl", media)
self.assertIn("video5.mp4", media)
self.assertIn("video.mp4", media)
self.assertIn("video0.mp4", media)
self.assertIn("video1.mp4", media)
self.assertIn("video3.mp4", media)
self.assertIn("video4.mp4", media)
self.assertIn("audio.mp3", media)
self.assertIn("/Volumes/spare/videos/video.mp4", media)

def test_get_edl_media_recursive_cyclic_protection(self):
edl_file = fixture('test3.edl')
edl_file = fixture("test3.edl")
media = get_edl_media(edl_file)

self.assertEqual(media, {'video.mp4'})
self.assertEqual(media, {"video.mp4"})


if __name__ == '__main__':
if __name__ == "__main__":
unittest.main()

0 comments on commit 1a1dc0c

Please sign in to comment.