mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 04:23:01 +00:00
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:
+25
-6
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user