Skip to content

Instantly share code, notes, and snippets.

@mtomwing
Created March 29, 2014 01:27
Show Gist options
  • Save mtomwing/9846598 to your computer and use it in GitHub Desktop.
Save mtomwing/9846598 to your computer and use it in GitHub Desktop.
import itertools
import os
import sys
def is_valid_video(filepath):
return filepath.endswith('.gif')
def gather_files(path):
if os.path.isdir(path):
for base, _, filenames in os.walk(path):
for filename in filenames:
yield os.path.join(base, filename)
else:
yield path
def gather_videos(paths):
unique_paths = set(os.path.abspath(path) for path in paths)
filepaths = itertools.chain.from_iterable(gather_files(path) for path in unique_paths)
for filepath in filepaths:
if is_valid_video(filepath):
yield filepath
if __name__ == '__main__':
for filepath in gather_videos(sys.argv[1:]):
print filepath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment