From 737695016f9881b5fc7deb903d222998f39e2a04 Mon Sep 17 00:00:00 2001 From: Rafael Vargas Date: Thu, 30 Dec 2021 14:35:02 -0400 Subject: [PATCH] Creating utils file --- vulkanbot/music/utils.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 vulkanbot/music/utils.py diff --git a/vulkanbot/music/utils.py b/vulkanbot/music/utils.py new file mode 100644 index 0000000..2dd078c --- /dev/null +++ b/vulkanbot/music/utils.py @@ -0,0 +1,27 @@ +import re + +def format_time(duration): + if not duration: + return "00:00" + + hours = duration // 60 // 60 + minutes = duration // 60 % 60 + seconds = duration % 60 + + return "{}{}{:02d}:{:02d}".format( + hours if hours else "", + ":" if hours else "", + minutes, + seconds + ) + + +def is_url(string) -> bool: + """Verify if a string is a url""" + regex = re.compile( + "http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+") + + if re.search(regex, string): + return True + else: + return False