add featured artists in albumview

This commit is contained in:
geoffrey45
2022-01-15 18:18:55 +03:00
parent 1b9e6821d6
commit a720891c20
13 changed files with 166 additions and 148 deletions
+27 -34
View File
@@ -13,7 +13,7 @@ all_the_f_music = helpers.getAllSongs()
def initialize() -> None:
helpers.create_config_dir()
# helpers.check_for_new_songs()
helpers.check_for_new_songs()
initialize()
@@ -54,9 +54,8 @@ def search_by_title():
album['image'] = "image"
for song in ar:
a = song["artists"].split(', ')
for artist in a:
for artist in song["artists"]:
if query.lower() in artist.lower():
artist_obj = {
@@ -75,30 +74,34 @@ def x():
return "🎸"
@bp.route("/folder/artists")
def get_folder_artists():
dir = request.args.get('dir')
@bp.route("/album/<album>/<artist>/artists")
@cache.cached()
def get_album_artists(album, artist):
album = album.replace('|', '/')
artist = artist.replace('|', '/')
tracks = []
songs = instances.songs_instance.find_songs_by_folder(dir)
without_duplicates = helpers.remove_duplicates(songs)
for track in all_the_f_music:
if track["album"] == album and track["album_artist"] == artist:
tracks.append(track)
artists = []
for song in without_duplicates:
this_artists = song['artists'].split(', ')
for artist in this_artists:
for track in tracks:
print(track['artists'])
for artist in track['artists']:
if artist not in artists:
artists.append(artist)
final_artists = []
for artist in artists[:15]:
artist_obj = instances.artist_instance.find_artists_by_name(artist)
if artist_obj != []:
final_artists.append(artist_obj)
for artist in artists:
artist_obj = {
"name": artist,
"image": "http://127.0.0.1:8900/images/artists/" + artist.replace('/', '::') + ".jpg"
}
final_artists.append(artist_obj)
return {'artists': final_artists}
@@ -106,6 +109,7 @@ def get_folder_artists():
@bp.route("/populate/images")
def populate_images():
functions.populate_images()
return "Done"
@bp.route("/artist/<artist>")
@@ -129,9 +133,6 @@ def getArtistData(artist: str):
albums = instances.songs_instance.find_songs_by_album_artist(artist)
for song in songs:
song['artists'] = song['artists'].split(', ')
for song in albums:
if song['album'] not in artist_albums:
artist_albums.append(song['album'])
@@ -200,12 +201,6 @@ def getFolderTree(folder: str = None):
if x['folder'] == req_dir:
songs.append(x)
for song in songs:
try:
song['artists'] = song['artists'].split(', ')
except:
pass
return {"files": helpers.remove_duplicates(songs), "folders": sorted(folders, key=lambda i: i['name'])}
@bp.route('/qwerty')
@@ -215,9 +210,7 @@ def populateArtists():
artists = []
for song in all_songs:
artist = song['artists'].split(', ')
for a in artist:
for a in song['artists']:
a_obj = {
"name": a,
}
@@ -252,11 +245,11 @@ def getAlbumSongs(query: str):
album = query.split('::')[0].replace('|', '/')
artist = query.split('::')[1].replace('|', '/')
songs = instances.songs_instance.find_songs_by_album(album, artist)
songs = []
for song in songs:
song['artists'] = song['artists'].split(', ')
song['image'] = "http://127.0.0.1:8900/images/thumbnails/" + song['image']
for track in all_the_f_music:
if track['album'] == album and track['album_artist'] == artist:
songs.append(track)
album_obj = {
"name": album,
+19 -23
View File
@@ -2,13 +2,14 @@
This module contains larger functions for the server
"""
import time
from progress.bar import Bar
import requests
import os
from mutagen.flac import MutagenError
from app import helpers
from app import instances
from app import api
def populate():
'''
@@ -18,6 +19,7 @@ def populate():
also checks if the album art exists in the image path, if not tries to
extract it.
'''
print('\nchecking for new tracks')
files = helpers.run_fast_scandir(helpers.home_dir, [".flac", ".mp3"])[1]
for file in files:
@@ -36,8 +38,8 @@ def populate():
helpers.getTags(file)
except MutagenError:
pass
return {'msg': 'updated everything'}
api.all_the_f_music = helpers.getAllSongs()
print('\ncheck done')
def populate_images():
@@ -54,35 +56,29 @@ def populate_images():
bar = Bar('Processing images', max=len(artists))
for artist in artists:
file_path = helpers.app_dir + '/images/artists/' + artist + '.jpg'
file_path = helpers.app_dir + '/images/artists/' + \
artist.replace('/', '::') + '.jpg'
if not os.path.exists(file_path):
url = 'https://api.deezer.com/search/artist?q={}'.format(artist)
response = requests.get(url)
try:
response = requests.get(url)
except:
print('\n sleeping for 5 seconds')
time.sleep(5)
response = requests.get(url)
data = response.json()
try:
image_path = data['data'][0]['picture_xl']
img_data = data['data'][0]['picture_xl']
except:
image_path = None
img_data = None
if image_path is not None:
try:
helpers.save_image(image_path, file_path)
artist_obj = {
'name': artist
}
instances.artist_instance.insert_artist(artist_obj)
except:
pass
else:
pass
if img_data is not None:
helpers.save_image(img_data, file_path)
bar.next()
bar.finish()
artists_in_db = instances.artist_instance.get_all_artists()
return {'sample': artists_in_db[:25]}
+3
View File
@@ -268,8 +268,11 @@ def getAllSongs() -> None:
except FileNotFoundError:
instances.songs_instance.remove_song_by_filepath(
os.path.join(home_dir, track['filepath']))
if track['image'] is not None:
track['image'] = "http://127.0.0.1:8900/images/thumbnails/" + \
track['image']
if track['artists'] is not None:
track['artists'] = track['artists'].split(', ')
return tracks