Skip to content
This repository has been archived by the owner on May 28, 2022. It is now read-only.

Refactor gathering of videos to upload #550

Open
dideler opened this issue Apr 12, 2014 · 0 comments
Open

Refactor gathering of videos to upload #550

dideler opened this issue Apr 12, 2014 · 0 comments

Comments

@dideler
Copy link
Member

dideler commented Apr 12, 2014

See the discussion on the mailing list.

@mtomwing recommended

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

Related to #529

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant