From 27927b480a0648746384b049197e9672a198dfc3 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Mon, 24 Jan 2022 14:26:31 +0800 Subject: [PATCH] =?UTF-8?q?autocaption=20=E6=94=AF=E6=8C=81=E8=AF=AD?= =?UTF-8?q?=E9=9F=B3\=E8=AF=AD=E9=9F=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- autocaption.py | 22 +++++++++++++++++++++- list.json | 4 ++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/autocaption.py b/autocaption.py index 77a0fa8..6be8b15 100644 --- a/autocaption.py +++ b/autocaption.py @@ -1,7 +1,8 @@ from pagermaid import version from pagermaid.listener import listener from telethon.tl.custom.message import Message -from telethon.tl.types import MessageMediaDocument, DocumentAttributeFilename, DocumentAttributeImageSize +from telethon.tl.types import MessageMediaDocument, DocumentAttributeFilename, DocumentAttributeImageSize, \ + DocumentAttributeAudio def unit_convert(byte): @@ -19,6 +20,15 @@ def unit_convert(byte): return f"{round(byte, 2)} {units[zero]}" +def duration_convert(duration: int): + """ Converts duration into readable formats. """ + minutes = duration // 60 + seconds = duration % 60 + hours = minutes // 60 + minutes %= 60 + return f"{hours:02d}:{minutes:02d}:{seconds:02d}" + + @listener(is_plugin=True, outgoing=True, incoming=False, ignore_edited=True) async def auto_caption_file(context: Message): if not context.media: @@ -36,6 +46,16 @@ async def auto_caption_file(context: Message): # 图片尺寸 if isinstance(i, DocumentAttributeImageSize): text += f"`图片尺寸:{i.w}x{i.h}`\n" + # 音乐时长、歌手、歌曲名 + if isinstance(i, DocumentAttributeAudio): + if i.title: + text += f"`歌曲名:{i.title}`\n" + if i.performer: + text += f"`歌手:{i.performer}`\n" + if not i.voice: + text += f"`音乐时长:{duration_convert(i.duration)}`\n" + else: + text += f"`语音时长:{duration_convert(i.duration)}`\n" # 文件类型 text += f"`文件类型:{context.media.document.mime_type}`\n" # 文件大小 diff --git a/list.json b/list.json index 2c963b7..bc78243 100644 --- a/list.json +++ b/list.json @@ -852,10 +852,10 @@ }, { "name": "autocaption", - "version": "1.0", + "version": "1.001", "section": "chat", "maintainer": "xtaodada", - "size": "1.47 kb", + "size": "2.2 kb", "supported": true, "des-short": "自动获取所发送文件的信息。", "des": "自动获取所发送文件的信息。"