Freeseer / freeseer

Designed for capturing presentations at conferences. Pre-fill a list of talks to record, record them, and upload them to YouTube with our YouTube Uploader.
http://freeseer.readthedocs.org
GNU General Public License v3.0
215 stars 110 forks source link

Refactor gathering of videos to upload #550

Open dideler opened 10 years ago

dideler commented 10 years ago

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