0

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()
dsmith
  • 39
  • 1
  • 4
  • If you want to support more than YouTube, then yes... What errors are you getting when you try? – OneCricketeer Mar 21 '18 at 01:58
  • I got "invalid syntax". I changed the line: if url.startswith('https://www.youtube.com/'): to youtube-dl http://vimeo.com/channels/YOUR-CHANNEL: – dsmith Mar 21 '18 at 02:17
  • Well, yes. `youtube-dl` is a command line tool... Not just a callable Python function. Especially not without importing something – OneCricketeer Mar 21 '18 at 02:18
  • Possible duplicate of [How to use youtube-dl from a python program](https://stackoverflow.com/questions/18054500/how-to-use-youtube-dl-from-a-python-program) – OneCricketeer Mar 21 '18 at 02:19
  • its not a duplicate. I changed the question. – dsmith Mar 21 '18 at 04:02

0 Answers0