NFLmusic库文件
This commit is contained in:
29
nflmusic/lyrics.py
Normal file
29
nflmusic/lyrics.py
Normal file
@ -0,0 +1,29 @@
|
||||
import re
|
||||
|
||||
|
||||
def load_lyrics(file):
|
||||
with open(file, 'r', encoding='utf-8') as file:
|
||||
lines = file.readlines()
|
||||
lyrics = {}
|
||||
for line in lines:
|
||||
match = re.match(r'\[(\d+):(\d+\.\d+)\](.*)', line)
|
||||
if match:
|
||||
minutes = int(match.group(1))
|
||||
seconds = int(float(match.group(2)))
|
||||
timestamp = f'{minutes:02}:{seconds:02}'
|
||||
text = match.group(3)
|
||||
lyrics[timestamp] = text
|
||||
|
||||
return lyrics
|
||||
|
||||
|
||||
def get_lyrics(lyrics, time):
|
||||
try:
|
||||
lyric = lyrics[time]
|
||||
return lyric
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(load_lyrics("C:/Users/admin/Desktop/NFLmusic/3.8.8/music/王菲 - 匆匆那年.lrc"))
|
Reference in New Issue
Block a user