diff --git a/package.json b/package.json index b0a71c41..d6e85445 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "lint": "eslint --ext .js,.vue --ignore-path .gitignore --fix src" }, "dependencies": { + "axios": "^0.26.0", "mitt": "^3.0.0", "register-service-worker": "^1.7.1", "sass": "^1.49.0", diff --git a/server/app/api.py b/server/app/api.py index 226e1d77..1884da97 100644 --- a/server/app/api.py +++ b/server/app/api.py @@ -1,4 +1,5 @@ import os +from pprint import pprint import urllib from typing import List from flask import Blueprint, request, send_file @@ -54,6 +55,13 @@ def get_artists(artist: str) -> List: ] +search_results = { + "tracks": [], + "albums": [], + "artists": [], +} + + @bp.route("/search") def search_by_title(): """ @@ -64,6 +72,7 @@ def search_by_title(): albums = get_search_albums(query) albums_dicts = [] artists_dicts = [] + search_results.clear() for song in albums: album_obj = { @@ -86,8 +95,8 @@ def search_by_title(): artist_obj = { "name": artist, "image": "http://0.0.0.0:8900/images/artists/" - + artist.replace("/", "::") - + ".webp", + + artist.replace("/", "::") + + ".webp", } if artist_obj not in artists_dicts: @@ -95,6 +104,10 @@ def search_by_title(): tracks = helpers.remove_duplicates(get_tracks(query)) + search_results["tracks"] = tracks + search_results["albums"] = albums_dicts + search_results["artists"] = artists_dicts + return { "data": [ {"tracks": tracks[:5], "more": len(tracks) > 5}, @@ -104,6 +117,33 @@ def search_by_title(): } +@bp.route("/search/loadmore") +def search_load_more(): + """ + Returns more songs, albums or artists from a search query. + """ + type = request.args.get("type") + start = int(request.args.get("start")) + + if type == "tracks": + return { + "tracks": search_results["tracks"][start : start + 5], + "more": len(search_results["tracks"]) > start + 5, + } + + elif type == "albums": + return { + "albums": search_results["albums"][start : start + 6], + "more": len(search_results["albums"]) > start + 6, + } + + elif type == "artists": + return { + "artists": search_results["artists"][start : start + 6], + "more": len(search_results["artists"]) > start + 6, + } + + @bp.route("/populate") def find_tracks(): """call the populate function""" @@ -136,8 +176,8 @@ def get_albumartists(album, artist): artist_obj = { "name": artist, "image": "http://0.0.0.0:8900/images/artists/" - + artist.replace("/", "::") - + ".webp", + + artist.replace("/", "::") + + ".webp", } final_artists.append(artist_obj) @@ -272,8 +312,8 @@ def get_album_tracks(title: str, artist: str): "date": songs[0].date, "artist": songs[0].albumartist, "artist_image": "http://127.0.0.1:8900/images/artists/" - + songs[0].albumartist.replace("/", "::") - + ".webp", + + songs[0].albumartist.replace("/", "::") + + ".webp", } return {"songs": songs, "info": album_obj} @@ -293,9 +333,7 @@ def send_track_file(trackid): Returns an audio file that matches the passed id to the client. """ try: - filepath = instances.songs_instance.get_song_by_id(trackid)['filepath'] + filepath = instances.songs_instance.get_song_by_id(trackid)["filepath"] return send_file(filepath, mimetype="audio/mp3") except FileNotFoundError: return "File not found", 404 - - diff --git a/src/components/AlbumView/Header.vue b/src/components/AlbumView/Header.vue index 6baf520b..7378e878 100644 --- a/src/components/AlbumView/Header.vue +++ b/src/components/AlbumView/Header.vue @@ -10,8 +10,9 @@
-
- {{ album_info.count }} Tracks • {{ album_info.duration }} • {{album_info.date}} +
+ {{ album_info.count }} Tracks • {{ album_info.duration }} • + {{ album_info.date }}
@@ -60,7 +61,14 @@ export default { align-items: center; padding: $small; height: 100%; - background-image: url("../../assets/images/abg.webp"); + background-image: linear-gradient( + 56deg, + $gray 0%, + $gray4 25%, + $gray1 50%, + $gray1 75%, + $gray 100% + ); background-position: 0% 60%; background-repeat: no-repeat; background-size: cover; @@ -97,7 +105,7 @@ export default { position: relative; .stats { - background-color: #1f1f1f8e; + background-color: $gray; padding: $small; border-radius: $small; position: absolute; diff --git a/src/components/LeftSidebar/Navigation.vue b/src/components/LeftSidebar/Navigation.vue index 2efa652f..debbef10 100644 --- a/src/components/LeftSidebar/Navigation.vue +++ b/src/components/LeftSidebar/Navigation.vue @@ -17,7 +17,6 @@ diff --git a/src/composables/loadmore.js b/src/composables/loadmore.js new file mode 100644 index 00000000..1a32eab7 --- /dev/null +++ b/src/composables/loadmore.js @@ -0,0 +1,42 @@ +import axios from "axios"; + +const url = "http://0.0.0.0:9876/search/loadmore"; + +async function loadMoreTracks(start) { + const response = await axios.get(url, { + params: { + type: "tracks", + start: start, + }, + }); + + return response.data; +} + +async function loadMoreAlbums(start) { + const response = await axios.get(url, { + params: { + type: "albums", + start: start, + }, + }); + + return response.data; +} + +async function loadMoreArtists(start) { + const response = await axios.get(url, { + params: { + type: "artists", + start: start, + }, + }); + + return response.data; +} + +export default { + loadMoreTracks, + loadMoreAlbums, + loadMoreArtists, +}; diff --git a/yarn.lock b/yarn.lock index 56bec5fb..4c13cc3e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -353,6 +353,13 @@ argparse@^2.0.1: resolved "https://registry.yarnpkg.com/argparse/-/argparse-2.0.1.tgz#246f50f3ca78a3240f6c997e8a9bd1eac49e4b38" integrity sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q== +axios@^0.26.0: + version "0.26.0" + resolved "https://registry.yarnpkg.com/axios/-/axios-0.26.0.tgz#9a318f1c69ec108f8cd5f3c3d390366635e13928" + integrity sha512-lKoGLMYtHvFrPVt3r+RBMp9nh34N0M8zEfCWqdWZx6phynIEhQqAdydpyBAAG211zlhX9Rgu08cOamy6XjE5Og== + dependencies: + follow-redirects "^1.14.8" + balanced-match@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee" @@ -807,6 +814,11 @@ flatted@^3.1.0: resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.5.tgz#76c8584f4fc843db64702a6bd04ab7a8bd666da3" integrity sha512-WIWGi2L3DyTUvUrwRKgGi9TwxQMUEqPOPQBVi71R96jZXJdFskXEmf54BoZaS1kknGODoIGASGEzBUYdyMCBJg== +follow-redirects@^1.14.8: + version "1.14.9" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.9.tgz#dd4ea157de7bfaf9ea9b3fbd85aa16951f78d8d7" + integrity sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w== + fs.realpath@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"