Added parseLrcLine()
This commit is contained in:
27
utils.py
27
utils.py
@ -2,6 +2,8 @@
|
|||||||
A set of common utilities.
|
A set of common utilities.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
def inputYN(text: str, default: bool=None):
|
def inputYN(text: str, default: bool=None):
|
||||||
"""
|
"""
|
||||||
Prompty the user with a yes/no prompt.
|
Prompty the user with a yes/no prompt.
|
||||||
@ -20,3 +22,28 @@ def inputYN(text: str, default: bool=None):
|
|||||||
return False
|
return False
|
||||||
if default is not None and i == '':
|
if default is not None and i == '':
|
||||||
return default
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user