summaryrefslogtreecommitdiff
path: root/scrap/parser.py
diff options
context:
space:
mode:
Diffstat (limited to 'scrap/parser.py')
-rw-r--r--scrap/parser.py37
1 files changed, 13 insertions, 24 deletions
diff --git a/scrap/parser.py b/scrap/parser.py
index a191fa2..c447a0d 100644
--- a/scrap/parser.py
+++ b/scrap/parser.py
@@ -4,54 +4,44 @@ import structures
import os
-def process_json_file(name, artist_id):
+def process_json_file(name, album_id, artist_id):
link = getLink(name)
file_json = open(link, "r")
album_json = file_json.read()
file_json.close()
- return process_json(album_json, artist_id)
+ return process_json(album_json, album_id, artist_id)
def getLink(name):
return "Lyrics_"+name.replace(" ", "")+".json"
-def process_json(album_json, artist_id):
+def process_json(album_json, album_id, artist_id):
data = json.loads(album_json)
- name = data["name"].lower()
+ album_name = data["name"].lower()
- artist_name_api = data["artist"]["name"].lower()
- artist_name = format_artist_name(artist_name_api)
off_cover = data["cover_art_thumbnail_url"]
- new_cover = get_cover_link(artist_name, name)
- download_cover(off_cover, new_cover, artist_name)
+ new_cover = get_cover_link(artist_id, album_id)
+ download_cover(off_cover, new_cover, artist_id)
songs = [analyze_song(song) for song in data["tracks"]]
- return structures.album(name, new_cover, songs, artist_id)
+ return structures.album(album_name, new_cover, songs, artist_id)
-def format_artist_name(name):
- name = name.replace(" ", "")
- name = re.sub(r'[\(\[].*?[\)\]]', '', name)
- return name
+def get_cover_link(artist_id, album_id):
+ cover_link = f"covers/{artist_id}/{album_id}.png"
+ return cover_link
-def get_cover_link(artist_name, album_name):
- album_name = album_name.replace(" ", "")
- location = f"covers/{artist_name}/{album_name}.png"
-
- return location
-
-
-def download_cover(off_cover, new_cover, artist_name):
+def download_cover(off_cover, new_cover, artist_id):
if not os.path.isdir("covers"):
os.system("mkdir covers")
- if not os.path.isdir(f"covers/{artist_name}"):
- os.system(f"mkdir 'covers/{artist_name}'")
+ if not os.path.isdir(f"covers/{artist_id}"):
+ os.system(f"mkdir 'covers/{artist_id}'")
if not os.path.isfile(new_cover):
os.system(f"wget {off_cover} -O '{new_cover}'")
@@ -78,7 +68,6 @@ def format_lyrics(lyrics):
lyrics = re.sub(r'[\(\[].*?[\)\]]', '', lyrics)
lyrics = re.sub("\n{3,}", "\n\n", lyrics)
- lyrics = lyrics.replace("\u0435", "e")
lyrics = lyrics.replace("\u2005", " ")
while lyrics[0] == '\n':