50 lines
1.2 KiB
Python
50 lines
1.2 KiB
Python
"""
|
|
A set of common utilities.
|
|
"""
|
|
|
|
import re
|
|
|
|
def inputYN(text: str, default: bool=None):
|
|
"""
|
|
Prompty the user with a yes/no prompt.
|
|
|
|
Args:
|
|
text (str): The text displayed to the user.
|
|
default (bool): The default answer.
|
|
"""
|
|
|
|
while True:
|
|
i = input(text)
|
|
|
|
if i.lower() in ['1', 'y', 'yes']:
|
|
return True
|
|
if i.lower() in ['0', 'n', 'no']:
|
|
return False
|
|
if default is not None and i == '':
|
|
return default
|
|
|
|
def parseLrcLine(lrcLine: str) -> [float, str]:
|
|
"""
|
|
Parses a line from an lrc file.
|
|
Turns "[00:36.21] If you decide to stay" into
|
|
[36.21, 'If you decide to stay'].
|
|
|
|
Args:
|
|
lrcLine (str): The single line from the lrc file.
|
|
|
|
Returns:
|
|
float: How many seconds into the song the lyric is.
|
|
str: The lytic.
|
|
"""
|
|
|
|
t = None
|
|
|
|
if re.search(r'^\[[0-9][0-9]:[0-9][0-9](\.[0-9][0-9])?\].*$', lrcLine):
|
|
timeStamp = lrcLine[1:].split(']')[0]
|
|
minutes, seconds = timeStamp.split(':')
|
|
minutes, seconds = (int(minutes), float(seconds))
|
|
t = minutes * 60 + seconds
|
|
lrcLine = ']'.join(lrcLine.split(']')[1:]).strip()
|
|
|
|
return t, lrcLine
|