-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
34 lines (26 loc) 路 766 Bytes
/
Copy pathtest.py
File metadata and controls
34 lines (26 loc) 路 766 Bytes
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
import syncedlyrics
import re
import json
query = input("Enter Song Name: ")
lrc = syncedlyrics.search(query)
# Input data
data = lrc
# Split the data into lines
lines = data.split('\n')
# Initialize a list to store the JSON entries
json_data = []
# Define a regular expression pattern to extract timestamps and text
pattern = r'\[(\d+:\d+\.\d+)\](.*)'
for line in lines:
match = re.match(pattern, line)
if match:
timestamp, text = match.groups()
json_entry = {
"time": timestamp.strip(),
"lyrics": text.strip()
}
json_data.append(json_entry)
# Convert the list of JSON entries to a JSON-formatted string
json_string = json.dumps(json_data, indent=4)
# Print the JSON string
print(json_string)