Skip to content

Commit

Permalink
Merge pull request #12 from SimonIT/fix-different-count-of-millis
Browse files Browse the repository at this point in the history
Allow variable length after the dot and don't check empty lines
  • Loading branch information
doakey3 authored Jul 23, 2019
2 parents 2cc40e5 + 05034af commit f1cbd02
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
7 changes: 5 additions & 2 deletions pylrc/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .classes import Lyrics, LyricLine
from .utilities import validateTimecode

synced_line_regex = re.compile(r'^(\[[0-5]\d:[0-5]\d(\.\d\d)?\])+.*', flags=re.MULTILINE)
synced_line_regex = re.compile(r'^(\[[0-5]\d:[0-5]\d(\.\d+)?\])+.*', flags=re.MULTILINE)


def parse(lrc):
Expand All @@ -12,7 +12,10 @@ def parse(lrc):
items = []

for line in lines:
if line.startswith('[ar:'):
if not line:
continue

elif line.startswith('[ar:'):
lyrics.artist = line.rstrip()[4:-1].lstrip()

elif line.startswith('[ti:'):
Expand Down
6 changes: 3 additions & 3 deletions tests/static/P!nk - Bridge of Light.lrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@



[00:01.73]Is all you got,
[00:01.730]Is all you got,

[00:04.79]Blue turns black,

Expand Down Expand Up @@ -62,7 +62,7 @@

[01:37.59]And the need to be right cause us way too high costs

[01:44.00]
[01:44]

[01:45.11]That's when love can build a bridge of light

Expand All @@ -78,7 +78,7 @@

[02:05.73]That's when you gotta be strong tonight

[02:11.40]'cause only love can build us a bridge of light
[02:11.4]'cause only love can build us a bridge of light

[02:17.62]

Expand Down
10 changes: 10 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ def test_offset(self):
self.assertEqual(lrc_text[4].seconds, 1)
self.assertEqual(lrc_text[4].milliseconds, 890)

self.assertEqual(lrc_text[24].hours, 0)
self.assertEqual(lrc_text[24].minutes, 1)
self.assertEqual(lrc_text[24].seconds, 29)
self.assertEqual(lrc_text[24].milliseconds, 0)

self.assertEqual(lrc_text[32].hours, 0)
self.assertEqual(lrc_text[32].minutes, 2)
self.assertEqual(lrc_text[32].seconds, -4)
self.assertEqual(lrc_text[32].milliseconds, 400)


if __name__ == '__main__':
unittest.main()

0 comments on commit f1cbd02

Please sign in to comment.