major refactors

- remove jpgs
- add new album header
- remove duplicate components
- display album bio on client
- add a route loader module
- change color scheme
- other minor changes
This commit is contained in:
geoffrey45
2022-01-18 20:51:22 +03:00
parent 2ee8d27bf0
commit 1d1e697fd2
38 changed files with 327 additions and 465 deletions
+25 -6
View File
@@ -90,8 +90,6 @@ def get_album_artists(album, artist):
artists = []
for track in tracks:
print(track['artists'])
for artist in track['artists']:
if artist not in artists:
artists.append(artist)
@@ -100,7 +98,7 @@ def get_album_artists(album, artist):
for artist in artists:
artist_obj = {
"name": artist,
"image": "http://127.0.0.1:8900/images/artists/" + artist.replace('/', '::') + ".jpg"
"image": "http://127.0.0.1:8900/images/artists/webp/" + artist.replace('/', '::') + ".webp"
}
final_artists.append(artist_obj)
@@ -245,17 +243,38 @@ def getAlbumSongs(query: str):
if track['album'] == album and track['album_artist'] == artist:
songs.append(track)
songs = helpers.remove_duplicates(songs)
album_obj = {
"name": album,
"count": len(songs),
"duration": sum(song['length'] for song in songs),
"image": songs[0]['image'],
"artist": songs[0]['album_artist']
"artist": songs[0]['album_artist'],
"artist_image": "http://127.0.0.1:8900/images/artists/webp/" + songs[0]['album_artist'].replace('/', '::') + ".webp"
}
return {'songs': helpers.remove_duplicates(songs), 'info': album_obj}
return {'songs': songs, 'info': album_obj}
@bp.route('/album/<title>/<artist>/bio')
@cache.cached()
def drop_db(title, artist):
return functions.getAlbumBio(title, artist)
bio = functions.getAlbumBio(title, artist)
return {'bio': bio}
@bp.route('/convert')
def convert_images_to_webp():
path = os.path.join(home_dir, helpers.app_dir, 'images', 'artists')
final_path = os.path.join(
home_dir, helpers.app_dir, 'images', 'artists', 'webp')
for file in os.scandir(path):
if file.name.endswith(".jpg"):
print(file.name)
print(os.path.join(final_path, file.name.replace('.jpg', '.webp')))
img = helpers.Image.open(os.path.join(path, file.name)).resize((150, 150), helpers.Image.ANTIALIAS)
img.save(os.path.join(final_path, file.name.replace('.jpg', '.webp')), format='webp')
return "Done"
+10 -7
View File
@@ -60,7 +60,7 @@ def populate_images():
try:
response = requests.get(url)
except:
except requests.ConnectionError:
print('\n sleeping for 5 seconds')
time.sleep(5)
response = requests.get(url)
@@ -225,16 +225,19 @@ def getTags(full_path: str) -> dict:
def getAlbumBio(title: str, album_artist: str) -> dict:
last_fm_url = 'http://ws.audioscrobbler.com/2.0/?method=album.getinfo&api_key={}&artist={}&album={}&format=json'.format(
helpers.last_fm_api_key, album_artist, title)
response = requests.get(last_fm_url)
data = response.json()
try:
bio = data['album']['wiki']['content']
response = requests.get(last_fm_url)
data = response.json()
except requests.ConnectionError:
return "None"
try:
bio = data['album']['wiki']['summary'].split('<a href="https://www.last.fm/')[0]
except KeyError:
bio = None
if bio is None:
return "None"
return {'data': data}
return bio