add multiple URLs for ytdl; add manual mp4 to animations

This commit is contained in:
Tomáš Mládek 2018-01-30 14:21:50 +01:00 committed by Tomáš Mládek
parent 819e8205c0
commit c2203f3d40

View file

@ -29,18 +29,21 @@ def date():
return datetime.now().strftime("%Y-%m-%d@%H:%M") return datetime.now().strftime("%Y-%m-%d@%H:%M")
def download_ydl(url): def download_ydl(urls):
ydl_opts = { ydl_opts = {
'noplaylist': True, 'noplaylist': True,
'download_archive': DIR + '/downloaded.lst', 'download_archive': DIR + '/downloaded.lst',
'outtmpl': OUT_DIR + '/' + date() + '__%(title)s__%(id)s.%(ext)s' 'outtmpl': OUT_DIR + '/' + 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([url]) ydl.download(urls)
def download_raw(url): def download_raw(url):
local_filename = OUT_DIR + '/' + date() + '__' + url.split('/')[-1] ext = ''
if 'api.telegram.org' in url and 'animation' in url:
ext = '.mp4'
local_filename = OUT_DIR + '/' + date() + '__' + url.split('/')[-1] + ext
r = requests.get(url, stream=True) r = requests.get(url, stream=True)
with open(local_filename, 'wb') as f: with open(local_filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=1024): for chunk in r.iter_content(chunk_size=1024):
@ -49,12 +52,14 @@ def download_raw(url):
def handle_url(bot, update): def handle_url(bot, update):
for entity in update.message.entities: ytdl_urls = list(filter(ytdl_has,
if entity.type == 'url': map(lambda e: update.message.text[e.offset:e.offset + e.length],
url = update.message.text[entity.offset:entity.offset + entity.length] filter(lambda e: e.type == 'url',
if ytdl_has(url): update.message.entities))))
update.message.reply_text('Downloading now...') if len(ytdl_urls) > 0:
download_ydl(url) logger.info("Downloading %s" % ytdl_urls)
update.message.reply_text('Downloading now...')
download_ydl(ytdl_urls)
def handle_photo(bot, update): def handle_photo(bot, update):