add image url handling

This commit is contained in:
Tomáš Mládek 2019-04-18 13:02:37 +02:00 committed by Tomáš Mládek
parent da66cbac82
commit 8edcefb7ae

View file

@ -175,9 +175,14 @@ class DelojzaBot:
def handle_url(self, _, update):
urls = map(lambda e: update.message.parse_entity(e),
filter(lambda e: e.type == 'url', update.message.entities))
ytdl_urls = list(filter(self.ytdl_can, urls))
ytdl_urls = [url for url in urls if self.ytdl_can(url)]
normal_urls = [url for url in urls if not self.ytdl_can(url)]
if len(ytdl_urls) > 0:
self.handle(ytdl_urls, update.message, self.download_ytdl)
if len(normal_urls) > 0:
image_urls = [url for url in normal_urls if "image" in requests.head(url).headers.get("Content-Type", "")]
if len(image_urls) > 0:
self.handle(image_urls, update.message, self.download_raw)
# noinspection PyBroadException
def handle_rest(self, bot, update):