diff --git a/server/app/api.py b/server/app/api.py index 5ff25980..c6ad1a6d 100644 --- a/server/app/api.py +++ b/server/app/api.py @@ -32,35 +32,36 @@ def search_by_title(): albums = [] artists = [] + tracks = [] - s = [] + albums_dicts = [] + artists_dicts = [] for track in all_the_f_music: if query.lower() in track['title'].lower(): - s.append(track) - - al = instances.songs_instance.search_songs_by_album(query) - ar = instances.songs_instance.search_songs_by_artist(query) + tracks.append(track) - for song in al: + if query.lower() in track['album'].lower(): + albums.append(track) + + if query.lower() in str(track['artists']).lower(): + artists.append(track) + + for song in albums: album_obj = { "name": song["album"], "artists": song["artists"], } - if album_obj not in albums: - albums.append(album_obj) - - for album in albums: - # try: - # image = convert_one_to_json(instances.songs_instance.get_song_by_album(album['name'], album['artists']))['image'] - # except: - # image: None - - album['image'] = "image" - - for song in ar: + if album_obj not in albums_dicts: + albums_dicts.append(album_obj) + for album in albums_dicts: + for track in albums: + if album['name'] == track['album']: + album['image'] = track['image'] + + for song in artists: for artist in song["artists"]: if query.lower() in artist.lower(): @@ -68,11 +69,31 @@ def search_by_title(): "name": artist, } - if artist_obj not in artists: - artists.append(artist_obj) + if artist_obj not in artists_dicts: + artists_dicts.append(artist_obj) - return {'songs': helpers.remove_duplicates(s), 'albums': albums, 'artists': artists} + tracks = helpers.remove_duplicates(tracks) + if len(tracks) > 5: + more_tracks = True + else: + more_tracks = False + + if len(artists_dicts) > 5: + more_artists = True + else: + more_artists = False + + if len(albums_dicts) > 5: + more_albums = True + else: + more_albums = False + + return {'data': [ + {'tracks': tracks[:5], 'more': more_tracks}, + {'albums': albums_dicts[:10], 'more': more_albums}, + {'artists': artists_dicts[:10], 'more': more_artists} + ]} @bp.route('/populate') def x(): @@ -282,11 +303,14 @@ def convert_images_to_webp(): 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') + 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" + @bp.route('/test') def test_http_status_response(): - return "OK", 200 \ No newline at end of file + return "OK", 200 diff --git a/server/app/functions.py b/server/app/functions.py index 73baad05..f785725f 100644 --- a/server/app/functions.py +++ b/server/app/functions.py @@ -211,10 +211,6 @@ def getTags(full_path: str) -> dict: "length": round(audio.info.length), "bitrate": audio.info.bitrate, "image": img_path, - "type": { - "name": None, - "id": None - } } instances.songs_instance.insert_song(tags) @@ -228,7 +224,7 @@ def getAlbumBio(title: str, album_artist: str) -> dict: try: response = requests.get(last_fm_url) data = response.json() - except requests.ConnectionError: + except: return "None" try: diff --git a/src/App.vue b/src/App.vue index 2f362e16..e6475d18 100644 --- a/src/App.vue +++ b/src/App.vue @@ -75,6 +75,7 @@ export default { }; const collapseSearch = () => { + console.log('hooooo') search.value = false; }; @@ -131,6 +132,7 @@ export default { } .content { + width: 100%; padding: 0 $small; display: grid; grid-template-rows: auto 1fr; diff --git a/src/components/FolderView/SongList.vue b/src/components/FolderView/SongList.vue index 60cb1a3b..d6016fa9 100644 --- a/src/components/FolderView/SongList.vue +++ b/src/components/FolderView/SongList.vue @@ -35,7 +35,7 @@ import { ref } from "@vue/reactivity"; import { onMounted } from "@vue/runtime-core"; -import SongItem from "../SongItem.vue"; +import SongItem from "../shared/SongItem.vue"; import routeLoader from "@/composables/routeLoader.js"; import perks from "@/composables/perks.js"; import state from "@/composables/state.js"; diff --git a/src/components/PlaylistView/FeaturedArtists.vue b/src/components/PlaylistView/FeaturedArtists.vue index 2445b252..7f7f3e65 100644 --- a/src/components/PlaylistView/FeaturedArtists.vue +++ b/src/components/PlaylistView/FeaturedArtists.vue @@ -5,29 +5,24 @@
-
+

Featured Artists

-
-
-
-

{{ artist.name }}

-
-
-
+
+ + \ No newline at end of file diff --git a/src/components/SongItem.vue b/src/components/shared/SongItem.vue similarity index 98% rename from src/components/SongItem.vue rename to src/components/shared/SongItem.vue index 03bd10cd..e90447bc 100644 --- a/src/components/SongItem.vue +++ b/src/components/shared/SongItem.vue @@ -56,12 +56,14 @@ import state from "@/composables/state.js"; export default { props: ["song"], + emits: ['updateQueue', 'loadAlbum'], setup(props, { emit }) { function emitUpdate(song) { emit("updateQueue", song); } function emitLoadAlbum(title, artist) { + console.log('hii') emit("loadAlbum", title, artist); } @@ -90,7 +92,7 @@ export default { .song-duration { width: 5rem !important; } - + cursor: pointer; .flex { diff --git a/src/composables/searchMusic.js b/src/composables/searchMusic.js index 8e41ba03..de95840a 100644 --- a/src/composables/searchMusic.js +++ b/src/composables/searchMusic.js @@ -3,15 +3,26 @@ import state from "./state.js"; const base_url = "http://0.0.0.0:9876/search?q="; async function search(query) { + state.loading.value = true; const url = base_url + encodeURIComponent(query); const res = await fetch(url); - const json = await res.json(); - state.search_tracks.value = json.songs; - state.search_albums.value = json.albums; - state.search_artists.value = json.artists; - console.log(state.search_tracks.value); + if (!res.ok) { + const message = `An error has occured: ${res.status}`; + throw new Error(message); + } + + const data = await res.json(); + console.log(data.data[1]); + + state.loading.value = false; + + return { + tracks: data.data[0], + albums: data.data[1], + artists: data.data[2], + }; } -export default search; \ No newline at end of file +export default search;