Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lyric): support to parse ill-formed lyric like [mm:ss:ms] #864

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions feeluown/player/lyric.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,21 @@ def parse_lyric_text(content: str) -> Dict[int, str]:
>>> list(r.items())[-1]
(90000, '再等直至再吻到你')
"""
def to_mileseconds(time_str):
def to_mileseconds(time_str: str):
mileseconds = 0
unit = 1000
t_seq = time_str.split(':')

t_seq = time_str.split(":", 1)
t_seq[1] = t_seq[1].replace(":", ".")
t_seq.reverse()

for num in t_seq:
mileseconds += int(float(num) * unit)
unit *= 60
return mileseconds

ms_sentence_map = OrderedDict()
sentence_pattern = re.compile(r'\[(\d+(:\d+){0,2}(\.\d+)?)\]')
sentence_pattern = re.compile(r'\[(\d+(:\d+){0,2}([:\.]\d+)?)\]')
lines = content.splitlines()
for line in lines:
m = sentence_pattern.search(line, 0)
Expand Down
Loading