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)
|
|
|
|
|