yt-download to /tmp first

This commit is contained in:
Tomáš Mládek 2018-01-31 14:11:42 +01:00 committed by Tomáš Mládek
parent 705b662782
commit 290f8d3183

View file

@ -1,6 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import logging import logging
import os import os
import shutil
import sys import sys
import requests import requests
@ -13,6 +14,7 @@ logging.basicConfig(level=logging.INFO,
logger = logging.getLogger("kunsax") logger = logging.getLogger("kunsax")
DIR = os.path.dirname(os.path.realpath(__file__)) DIR = os.path.dirname(os.path.realpath(__file__))
TMP_DIR = '/tmp'
OUT_DIR = DIR + '/out' OUT_DIR = DIR + '/out'
@ -34,10 +36,13 @@ def download_ydl(urls, date):
ydl_opts = { ydl_opts = {
'noplaylist': True, 'noplaylist': True,
'download_archive': DIR + '/downloaded.lst', 'download_archive': DIR + '/downloaded.lst',
'outtmpl': OUT_DIR + '/' + datestr(date) + '__%(title)s__%(id)s.%(ext)s' 'outtmpl': TMP_DIR + '/' + datestr(date) + '__%(title)s__%(id)s.%(ext)s'
} }
with youtube_dl.YoutubeDL(ydl_opts) as ydl: with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download(urls) ydl.download(urls)
for filename in map(ydl.prepare_filename, map(ydl.extract_info, urls)):
logger.info("Moving %s to %s..." % (filename, OUT_DIR))
shutil.move(filename, OUT_DIR)
def download_raw(url, date): def download_raw(url, date):