From a720891c203c8d72fed3e62cb7eefeb3aef8cbfe Mon Sep 17 00:00:00 2001 From: geoffrey45 Date: Sat, 15 Jan 2022 18:18:55 +0300 Subject: [PATCH] add featured artists in albumview --- server/app/api.py | 61 ++++++++---------- server/app/functions.py | 42 ++++++------ server/app/helpers.py | 3 + src/assets/css/global.scss | 1 + src/components/FolderView/Header.vue | 18 ++++-- src/components/FolderView/SongList.vue | 6 +- src/components/LeftSidebar/Navigation.vue | 37 ++++++----- .../PlaylistView/FeaturedArtists.vue | 64 ++++++------------- src/components/SongItem.vue | 1 - src/composables/album.js | 44 +++++++++++++ src/composables/getAlbum.js | 16 ----- src/composables/state.js | 6 +- src/views/AlbumView.vue | 15 ++++- 13 files changed, 166 insertions(+), 148 deletions(-) create mode 100644 src/composables/album.js delete mode 100644 src/composables/getAlbum.js diff --git a/server/app/api.py b/server/app/api.py index b7fcd92..5dc76ff 100644 --- a/server/app/api.py +++ b/server/app/api.py @@ -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///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/") @@ -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, diff --git a/server/app/functions.py b/server/app/functions.py index 5ff25d3..8c1cc97 100644 --- a/server/app/functions.py +++ b/server/app/functions.py @@ -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]} diff --git a/server/app/helpers.py b/server/app/helpers.py index 8006d75..9913adc 100644 --- a/server/app/helpers.py +++ b/server/app/helpers.py @@ -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 diff --git a/src/assets/css/global.scss b/src/assets/css/global.scss index 25d6ac3..4765b09 100644 --- a/src/assets/css/global.scss +++ b/src/assets/css/global.scss @@ -52,6 +52,7 @@ a { button { border: none; + outline: none; color: inherit; font-size: 1rem; cursor: pointer; diff --git a/src/components/FolderView/Header.vue b/src/components/FolderView/Header.vue index ea80529..7db9ec8 100644 --- a/src/components/FolderView/Header.vue +++ b/src/components/FolderView/Header.vue @@ -5,9 +5,11 @@
Play -
+
- {{ path.split("/").splice(-1) + "" }} +
+ {{ path.split("/").splice(-1) + "" }} +