I am trying to change my code to support video processing from multiple sites (youtube, vimeo, etc.) using the youtube extractions. I don't want to import youtube-dl (unless necessary). I would prefer to call a function. my understanding is that this: youtube-dl http://vimeo.com/channels/YOUR-CHANNEL) is a command line tool. please help!
import pymongo
import get_media
import configparser as ConfigParser
# shorten list to first 10 items
def shorten_list(mylist):
        return mylist[:10]
def main():
        config = ConfigParser.ConfigParser()
        config.read('settings.cfg')
        youtubedl_filename = config.get('media', 'youtubedl_input')
        print('creating file: %s - to be used as input for youtubedl' % youtubedl_filename)
        db = get_media.connect_to_media_db()
        items = db.raw
        url_list = []
        cursor = items.find()
        records = dict((record['_id'], record) for record in cursor)
        # iterate through records in media items collection
        # if 'Url' field exists and starts with youtube, add url to list
        for item in records:
                item_dict = records[item]
                #print(item_dict)
                if 'Url' in item_dict['Data']:
                        url = item_dict['Data']['Url']
                        if url.startswith('https://www.youtube.com/'):
                                url_list.append(url)
        # for testing purposes
        # shorten list to only download a few files at a time
        url_list = shorten_list(url_list)
        # save list of youtube media file urls
        with open(youtubedl_filename, 'w') as f:
                for url in url_list:
                        f.write(url+'\n')
if __name__ == "__main__":
        main()
