From 135b90b32daecf60005d45b327181ad86f9b51f2 Mon Sep 17 00:00:00 2001 From: levina <82658782+levina-lab@users.noreply.github.com> Date: Tue, 25 Jan 2022 21:01:19 +0700 Subject: [PATCH] add duration info for local audio --- program/music.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/program/music.py b/program/music.py index 13ac7d7..01de72e 100644 --- a/program/music.py +++ b/program/music.py @@ -109,16 +109,18 @@ async def play(c: Client, m: Message): suhu = await replied.reply("📥 **downloading audio...**") dl = await replied.download() link = replied.link - if replied.audio: - if replied.audio.title: + + try: + if replied.audio: songname = replied.audio.title[:70] - else: - if replied.audio.file_name: - songname = replied.audio.file_name[:70] - else: - songname = "Audio" - elif replied.voice: - songname = "Voice Note" + songname = replied.audio.file_name[:70] + duration = replied.audio.duration + elif replied.voice: + songname = "Voice Note" + duration = replied.voice.duration + except BaseException: + songname = "Audio" + if chat_id in QUEUE: pos = add_to_queue(chat_id, songname, dl, link, "Audio", 0) requester = f"[{m.from_user.first_name}](tg://user?id={m.from_user.id})" @@ -127,7 +129,7 @@ async def play(c: Client, m: Message): await m.reply_photo( photo=f"{IMG_1}", reply_markup=InlineKeyboardMarkup(buttons), - caption=f"💡 **Track added to queue »** `{pos}`\n\n🗂 **Name:** [{songname}]({link}) | `music`\n💭 **Chat:** `{chat_id}`\n🧸 **Request by:** {requester}", + caption=f"💡 **Track added to queue »** `{pos}`\n\n🗂 **Name:** [{songname}]({link}) | `music`\n⏱️ **Duration:** `{duration}`\n🧸 **Request by:** {requester}", ) else: try: @@ -146,7 +148,7 @@ async def play(c: Client, m: Message): await m.reply_photo( photo=f"{IMG_2}", reply_markup=InlineKeyboardMarkup(buttons), - caption=f"🗂 **Name:** [{songname}]({link}) | `music`\n💭 **Chat:** `{chat_id}`\n🧸 **Request by:** {requester}", + caption=f"🗂 **Name:** [{songname}]({link}) | `music`\n⏱️ **Duration:** `{duration}`\n🧸 **Request by:** {requester}", ) except Exception as e: await suhu.delete()