Created
March 29, 2014 01:27
-
-
Save mtomwing/9846598 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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