patch 50155e1ef1b508f47640d4f570da84407efac9cb Author: E. Bosch Date: Fri Dec 15 00:00:44 CET 2023 * telegram: Improve metadata shown for audio and recording/voice media, and get filename from them diff -rN -u old-irgramd/telegram.py new-irgramd/telegram.py --- old-irgramd/telegram.py 2024-11-22 16:27:29.196201143 +0100 +++ new-irgramd/telegram.py 2024-11-22 16:27:29.200201136 +0100 @@ -728,17 +728,17 @@ filename = None def scan_doc_attributes(document): - attrib_file = attrib_video = filename = None + attrib_file = attrib_av = filename = None size = document.size h_size = get_human_size(size) for x in document.attributes: - if isinstance(x, tgty.DocumentAttributeVideo): - attrib_video = x + if isinstance(x, tgty.DocumentAttributeVideo) or isinstance(x, tgty.DocumentAttributeAudio): + attrib_av = x if isinstance(x, tgty.DocumentAttributeFilename): attrib_file = x filename = attrib_file.file_name if attrib_file else None - return size, h_size, attrib_video, filename + return size, h_size, attrib_av, filename if isinstance(message.media, tgty.MessageMediaWebPage): to_download = False @@ -756,8 +756,17 @@ caption = '' elif message.photo: size, media_type = self.scan_photo_attributes(message.media.photo) - elif message.audio: media_type = 'audio' - elif message.voice: media_type = 'rec' + elif message.audio: + size, h_size, attrib_audio, filename = scan_doc_attributes(message.media.document) + dur = get_human_duration(attrib_audio.duration) if attrib_audio else '' + per = attrib_audio.performer or '' + tit = attrib_audio.title or '' + theme = ',{}/{}'.format(per, tit) if per or tit else '' + media_type = 'audio:{},{}{}'.format(h_size, dur, theme) + elif message.voice: + size, _, attrib_audio, filename = scan_doc_attributes(message.media.document) + dur = get_human_duration(attrib_audio.duration) if attrib_audio else '' + media_type = 'rec:{}'.format(dur) elif message.video: size, h_size, attrib_video, filename = scan_doc_attributes(message.media.document) dur = get_human_duration(attrib_video.duration) if attrib_video else '' diff -rN -u old-irgramd/utils.py new-irgramd/utils.py --- old-irgramd/utils.py 2024-11-22 16:27:29.200201136 +0100 +++ new-irgramd/utils.py 2024-11-22 16:27:29.200201136 +0100 @@ -130,7 +130,7 @@ if h > 0: res = str(h) + 'h' if m > 0: res += str(m) + 'm' - if s > 0: res += str(s) + 's' + if s > 0 or duration < 60: res += str(s) + 's' return res def compact_date(date, tz):