1
0
mirror of https://github.com/vimagick/dockerfiles.git synced 2024-12-16 11:37:32 +02:00
dockerfiles/youtube/youtube-worker/worker.py

33 lines
667 B
Python
Raw Normal View History

2015-07-12 18:43:50 +02:00
#!/usr/bin/env python
#
# youtube_dl worker
#
import logging
import os
import redis
import youtube_dl
def download(url):
with youtube_dl.YoutubeDL() as ydl:
ydl.download([url])
if __name__ == '__main__':
2015-07-12 19:01:12 +02:00
logging.basicConfig(format='%(asctime)s [%(levelname)s] %(message)s', datefmt='%FT%T', level='INFO')
2015-07-12 18:43:50 +02:00
logging.info('connect redis')
rdb = redis.StrictRedis(host='redis', password=os.getenv('PASSWORD'))
rdb.ping()
while True:
try:
_, url = rdb.brpop('urls')
logging.info('process: %s', url)
download(url)
except Exception as ex:
logging.error('error: %s', ex)