mirror of
https://github.com/UiO-Gaming/ShiteMusicBot.git
synced 2026-11-05 13:56:51 +01:00
28 lines
718 B
Python
28 lines
718 B
Python
# Discord Packages
|
|
import lavalink
|
|
|
|
|
|
def format_ms(milliseconds):
|
|
seconds = int(milliseconds)/1000
|
|
formatted = ''
|
|
hours, remainder = divmod(seconds, 60 * 60)
|
|
minutes, seconds = divmod(remainder, 60)
|
|
if hours:
|
|
formatted += '%02d:' % hours
|
|
formatted += '%02d:%02d' % (minutes, seconds)
|
|
return formatted
|
|
|
|
|
|
def unformat_ms(formatted):
|
|
hms = list(reversed([int(i) for i in formatted.split(':')]))
|
|
seconds = hms[0]
|
|
if len(hms) >= 2:
|
|
seconds += hms[1] * 60
|
|
if len(hms) == 3:
|
|
seconds += hms[2] * 3600
|
|
return seconds * 1000
|
|
|
|
|
|
def format_track_duration(track: lavalink.AudioTrack) -> str:
|
|
return '{live}' if track.stream else format_ms(track.duration)
|