patch 59776df1810cf643a8b7d70ab0502afde6a5c47f
Author: E. Bosch <presidev@AT@gmail.com>
Date: Sun Dec 17 02:49:18 CET 2023
* telegram: Add compact message IDs to filenames of media,
this will prevent most of the possible collisions of media with the same filename
hunk ./telegram.py 25
-from utils import sanitize_filename, is_url_equiv, extract_url, get_human_size, get_human_duration, get_highlighted, fix_braces, format_timestamp
+from utils import sanitize_filename, add_filename, is_url_equiv, extract_url, get_human_size, get_human_duration, get_highlighted, fix_braces, format_timestamp
hunk ./telegram.py 572
- text = await self.handle_webpage(upd_to_webpend, message)
+ text = await self.handle_webpage(upd_to_webpend, message, mid)
hunk ./telegram.py 579
- final_text = await self.handle_telegram_action(message)
+ final_text = await self.handle_telegram_action(message, mid)
hunk ./telegram.py 672
- async def handle_telegram_action(self, message):
+ async def handle_telegram_action(self, message, mid):
hunk ./telegram.py 679
- photo_url = await self.download_telegram_media(message)
+ photo_url = await self.download_telegram_media(message, mid)
hunk ./telegram.py 747
- return await self.handle_webpage(message.media.webpage, message)
+ return await self.handle_webpage(message.media.webpage, message, mid)
hunk ./telegram.py 834
- media_url_or_data = await self.download_telegram_media(message, filename, size, relay_attr)
+ media_url_or_data = await self.download_telegram_media(message, mid, filename, size, relay_attr)
hunk ./telegram.py 857
- async def handle_webpage(self, webpage, message):
+ async def handle_webpage(self, webpage, message, mid):
hunk ./telegram.py 859
- logo = await self.download_telegram_media(message)
+ logo = await self.download_telegram_media(message, mid)
hunk ./telegram.py 917
- async def download_telegram_media(self, message, filename=None, size=0, relay_attr=None):
+ async def download_telegram_media(self, message, mid, filename=None, size=0, relay_attr=None):
hunk ./telegram.py 921
- new_file = sanitize_filename(filename)
+ idd_file = add_filename(filename, mid)
+ new_file = sanitize_filename(idd_file)
hunk ./telegram.py 935
- new_file = str(self.media_cn) + filetype
+ gen_file = str(self.media_cn) + filetype
+ idd_file = add_filename(gen_file, mid)
+ new_file = sanitize_filename(idd_file)
hunk ./utils.py 86
+def add_filename(filename, add):
+ if add:
+ aux = filename.rsplit('.', 1)
+ name = aux[0]
+ ext = aux[1]
+ return '{}-{}.{}'.format(name, add, ext)
+ else:
+ return filename
+