From 8edcefb7ae5a75fe441c9283263e910bb484acbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Thu, 18 Apr 2019 13:02:37 +0200 Subject: [PATCH] add image url handling --- delojza.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/delojza.py b/delojza.py index 588cd82..5266b26 100755 --- a/delojza.py +++ b/delojza.py @@ -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):