-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparsers.py
48 lines (30 loc) · 882 Bytes
/
parsers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import json
from collections import Counter
from ErrorHandler import *
def read_lrc(filename):
"""
Reads a lyrical file
:param filename (string): name of the lrc file to read
:return (string): song as string
"""
# file not found error
# file is not of lrc type
# read the file
try:
with open(filename) as f:
contents = f.read()
except FileNotFoundError:
raise FileNotFound(filename)
# get the contents of the file as a list of lyrics
contents = contents.split("\n")
song = ''
# for every lyric in contents add it to the song string
for line in contents:
try:
line = line.split(']')
lyric = line[1]
except IndexError:
raise Index(filename)
song = song.strip()
song += '\n' + lyric
return song.strip()