Skip to content

Commit

Permalink
added duration to video (UsergeTeam#317)
Browse files Browse the repository at this point in the history
* fixed vc bool bug + added duration to video

* typo

* Update voice_call.py

* update voice_call.py
  • Loading branch information
Krishna-Singhal authored May 5, 2021
1 parent f09a96c commit 8c8fd0f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion userge/plugins/utils/voice_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

VC_DB = get_collection("VC_CMDS_TOGGLE")
CMDS_FOR_ALL = False
MAX_DURATION = 900

ADMINS = {}

Expand Down Expand Up @@ -456,7 +457,12 @@ async def yt_down(msg: Message):

title, url = _get_yt_info(msg)
message = await reply_text(msg, f"`Downloading {title}`")
title, duration = await mp3_down(url.strip())
song_details = await mp3_down(url.strip())
if not song_details:
await message.delete()
return await _skip()

title, duration = song_details

audio_path = None
for i in ["*.mp3", "*.flac", "*.wav", "*.m4a"]:
Expand Down Expand Up @@ -501,6 +507,9 @@ async def tg_down(msg: Message):

global BACK_BUTTON_TEXT # pylint: disable=global-statement

if msg.audio.duration > MAX_DURATION:
return await _skip()

message = await reply_text(msg, f"`Downloading {msg.audio.title}`")
path = await msg.download("temp_music_dir/")
filename = os.path.join("temp_music_dir", os.path.basename(path))
Expand Down Expand Up @@ -566,6 +575,8 @@ def mp3_down(url: str):

with ytdl.YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(url)
if info.get("duration") > MAX_DURATION:
return False

return info.get("title"), time_formatter(info.get("duration"))

Expand Down

0 comments on commit 8c8fd0f

Please sign in to comment.