feat(commands/voice/queue): print video duration
This commit is contained in:
parent
dc795f7ffe
commit
333d6890c2
@ -36,25 +36,21 @@ async def uptime(message):
|
||||
format_plural = lambda noun, count: noun if count == 1 else noun + "s"
|
||||
|
||||
segments = []
|
||||
duration = time.time() - start_time
|
||||
duration = int(time.time() - start_time)
|
||||
|
||||
days, duration = divmod(duration, 86400)
|
||||
if days >= 1:
|
||||
days = int(days)
|
||||
segments.append(f"{days} {format_plural('day', days)}")
|
||||
|
||||
hours, duration = divmod(duration, 3600)
|
||||
if hours >= 1:
|
||||
hours = int(hours)
|
||||
segments.append(f"{hours} {format_plural('hour', hours)}")
|
||||
|
||||
minutes, duration = divmod(duration, 60)
|
||||
if minutes >= 1:
|
||||
minutes = int(minutes)
|
||||
segments.append(f"{minutes} {format_plural('minute', minutes)}")
|
||||
|
||||
seconds = int(duration)
|
||||
if seconds > 0:
|
||||
segments.append(f"{seconds} {format_plural('second', seconds)}")
|
||||
if duration > 0:
|
||||
segments.append(f"{duration} {format_plural('second', duration)}")
|
||||
|
||||
await utils.reply(message, f"up {', '.join(segments)}")
|
||||
|
19
youtubedl.py
19
youtubedl.py
@ -5,6 +5,7 @@ import disnake
|
||||
import yt_dlp
|
||||
|
||||
import constants
|
||||
import utils
|
||||
|
||||
ytdl = yt_dlp.YoutubeDL(constants.YTDL_OPTIONS)
|
||||
|
||||
@ -14,9 +15,9 @@ class YTDLSource(disnake.PCMVolumeTransformer):
|
||||
self, source: disnake.AudioSource, *, data: dict[str, Any], volume: float = 0.5
|
||||
):
|
||||
super().__init__(source, volume)
|
||||
print(data)
|
||||
self.title = data.get("title")
|
||||
self.original_url = data.get("original_url")
|
||||
self.duration = data.get("duration")
|
||||
|
||||
@classmethod
|
||||
async def from_url(
|
||||
@ -63,12 +64,24 @@ class QueuedSong:
|
||||
self.player = player
|
||||
self.queuer = queuer
|
||||
|
||||
def format(self, with_queuer=False, hide_preview=False):
|
||||
def format(self, with_queuer=False, hide_preview=False) -> str:
|
||||
return (
|
||||
f"[`{self.player.title}`]({'<' if hide_preview else ''}{self.player.original_url}{'>' if hide_preview else ''})"
|
||||
f"[`{self.player.title}`]({'<' if hide_preview else ''}{self.player.original_url}{'>' if hide_preview else ''}) [{self.format_duration(self.player.duration)}]"
|
||||
+ (f" (<@{self.queuer}>)" if with_queuer else "")
|
||||
)
|
||||
|
||||
def format_duration(self, duration: int) -> str:
|
||||
segments = []
|
||||
hours, duration = divmod(duration, 3600)
|
||||
if hours > 0:
|
||||
segments.append(hours)
|
||||
minutes, duration = divmod(duration, 60)
|
||||
if minutes > 0:
|
||||
segments.append(minutes)
|
||||
if duration > 0:
|
||||
segments.append(duration)
|
||||
return f"{':'.join(str(s) for s in segments)}"
|
||||
|
||||
|
||||
def __reload_module__():
|
||||
global ytdl
|
||||
|
Loading…
x
Reference in New Issue
Block a user