diff --git a/package.json b/package.json index bbb07b46..b41d108a 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "dependencies": { "animate.css": "^4.1.1", "core-js": "^3.6.5", + "mitt": "^3.0.0", "register-service-worker": "^1.7.1", "sass": "^1.44.0", "sass-loader": "^10", diff --git a/server/app/api.py b/server/app/api.py index d9165f8f..d9d4968b 100644 --- a/server/app/api.py +++ b/server/app/api.py @@ -1,4 +1,6 @@ +import typing from app.models import Folders, Artists + from app.helpers import ( all_songs_instance, convert_one_to_json, @@ -29,6 +31,7 @@ bp = Blueprint('api', __name__, url_prefix='') artist_instance = Artists() folder_instance = Folders() +img_path = "http://127.0.0.1:8900/images/thumbnails/" def main_whatever(): @@ -242,26 +245,26 @@ def getArtistData(): @bp.route("/f/") @cache.cached() def getFolderTree(folder: str = None): - if folder == "home": - requested_dir = home_dir - - else: - try: - req_dir, last_id = folder.split('::') - except (ValueError): - req_dir = folder - last_id = None + try: + req_dir, last_id = folder.split('::') req_dir = req_dir.replace('|', '/') + dir_list = req_dir.split('/') + requested_dir = os.path.join(home_dir, *dir_list) - if req_dir: - dir_list = req_dir.split('/') - requested_dir = os.path.join(home_dir, *dir_list) + if req_dir == "home": + requested_dir = home_dir + + if last_id == "None": + last_id = None + + except: + requested_dir = home_dir + last_id = None dir_content = os.scandir(requested_dir) folders = [] - files = [] for entry in dir_content: if entry.is_dir() and not entry.name.startswith('.'): @@ -278,20 +281,23 @@ def getFolderTree(folder: str = None): if entry.is_file(): if isValidFile(entry.name) == True: - songs_array = all_songs_instance.find_songs_by_folder( - req_dir, last_id) - songs = convert_to_json(songs_array) - for song in songs: - song['artists'] = song['artists'].split(', ') + file = all_songs_instance.find_song_by_path(entry.path) - files = songs + if not file: + getTags(entry.path) - for file in files: - file['filepath'] = file['filepath'].replace(home_dir, '') - + songs_array = all_songs_instance.find_songs_by_folder( + req_dir, last_id) + songs = convert_to_json(songs_array) + for song in songs: + song['artists'] = song['artists'].split(', ') + song['filepath'] = song['filepath'].replace(home_dir, '') + song['image'] = img_path + song['image'] + song['type']['name'] = "folder" + song['type']['id'] = req_dir - return {"files": files, "folders": folders} + return {"files": songs, "folders": folders} @bp.route('/image//') @@ -313,3 +319,24 @@ def send_image(img_type, image_id): print(img_dir + image) return send_from_directory(img_dir, image) + + +@bp.route('/get/queue', methods=['POST']) +def post(): + args = request.get_json() + + type = args['type'] + id = args['id'] + + if type == "folder": + songs = all_songs_instance.find_songs_by_folder_og(id) + songs_array = convert_to_json(songs) + + for song in songs_array: + song['artists'] = song['artists'].split(', ') + song['filepath'] = song['filepath'].replace(home_dir, '') + song['image'] = img_path + song['image'] + + return {'songs': songs_array} + + return {'msg': 'ok'} diff --git a/server/app/helpers.py b/server/app/helpers.py index 34e1cb99..fe8586c8 100644 --- a/server/app/helpers.py +++ b/server/app/helpers.py @@ -54,16 +54,16 @@ def extract_thumb(path): return webp_path if path.endswith('.flac'): - audio = FLAC(path) try: + audio = FLAC(path) album_art = audio.pictures[0].data - except IndexError: + except: album_art = None elif path.endswith('.mp3'): - audio = ID3(path) try: + audio = ID3(path) album_art = audio.getall('APIC')[0].data - except IndexError: + except: album_art = None if album_art is None: @@ -91,10 +91,16 @@ def extract_thumb(path): def getTags(full_path): if full_path.endswith('.flac'): - audio = FLAC(full_path) + try: + audio = FLAC(full_path) + except: + return elif full_path.endswith('.mp3'): - audio = MP3(full_path) - + try: + audio = MP3(full_path) + except: + return + try: artists = audio['artist'][0] except KeyError: @@ -122,8 +128,8 @@ def getTags(full_path): title = audio['TIT2'][0] except: title = 'Unknown' - except IndexError: - title = 'Unknown' + except: + title = full_path.split('/')[-1] try: album = audio['album'][0] diff --git a/server/app/models.py b/server/app/models.py index c6305b3e..7d495861 100644 --- a/server/app/models.py +++ b/server/app/models.py @@ -51,8 +51,7 @@ class AllSongs(Mongo): def insert_song(self, song_obj): self.collection.update_one( - {'filepath': song_obj['filepath']}, { "$set": song_obj}, upsert=True) - # self.collection.insert_one(song_obj) + {'filepath': song_obj['filepath']}, {"$set": song_obj}, upsert=True) def find_song_by_title(self, query): self.collection.create_index([('title', pymongo.TEXT)]) @@ -71,6 +70,9 @@ class AllSongs(Mongo): else: return self.collection.find({'folder': query, '_id': {'$gt': ObjectId(last_id)}}).limit(limit) + def find_songs_by_folder_og(self, query): + return self.collection.find({'folder': query}) + def find_songs_by_artist(self, query): return self.collection.find({'artists': {'$regex': query, '$options': 'i'}}) diff --git a/src/App.vue b/src/App.vue index fbcc7544..40145c62 100644 --- a/src/App.vue +++ b/src/App.vue @@ -12,7 +12,7 @@
- +
- + @@ -51,6 +51,12 @@ export default { }, setup() { + const queue = ref(JSON.parse(localStorage.getItem("queue")) || []); + + const updpateQueue = (data)=> { + queue.value = data; + } + const collapsed = ref(true); function toggleNav() { @@ -76,12 +82,14 @@ export default { return { toggleNav, + updpateQueue, collapsed, up_next, expandQueue, expandSearch, collapseSearch, search, + queue, }; }, }; diff --git a/src/assets/css/global.scss b/src/assets/css/global.scss index 9ddc01e6..cc28ee2b 100644 --- a/src/assets/css/global.scss +++ b/src/assets/css/global.scss @@ -129,11 +129,11 @@ a { margin-bottom: 0.5em; } -@media (max-width: 70em) { - .r-sidebar { - display: none; - } -} +// @media (max-width: 70em) { +// .r-sidebar { +// display: none; +// } +// } .image { background-position: center; diff --git a/src/assets/images/null.webp b/src/assets/images/null.webp new file mode 100644 index 00000000..985be000 Binary files /dev/null and b/src/assets/images/null.webp differ diff --git a/src/components/FolderView/SongList.vue b/src/components/FolderView/SongList.vue index 28841323..4a66dcc4 100644 --- a/src/components/FolderView/SongList.vue +++ b/src/components/FolderView/SongList.vue @@ -2,44 +2,52 @@
- - - - - - - - - - - + + + + + + + + - {{ `${Math.trunc(song.length / 60)} min` }} - - + + + + + +
TrackArtistAlbumDuration
-
-
- {{ song.title }} -
-
-
- {{ artist }} -
-
-
{{ song.album }}
-
+
TrackArtistAlbumDuration
+
+
+ {{ song.title }} +
+
+
+ {{ artist }} +
+
+
{{ song.album }}
+
+ {{ `${Math.trunc(song.length / 60)} min` }} +
@@ -48,15 +56,17 @@ @@ -103,11 +125,15 @@ export default { position: relative; margin: 1rem; - tr { + tbody tr { + cursor: pointer; + transition: all 0.5s ease; + &:hover { td { background-color: rgba(255, 174, 0, 0.534); } + transform: scale(0.99); } } } diff --git a/src/components/LeftSidebar/Navigation.vue b/src/components/LeftSidebar/Navigation.vue index f5f89e98..7e7663f9 100644 --- a/src/components/LeftSidebar/Navigation.vue +++ b/src/components/LeftSidebar/Navigation.vue @@ -45,7 +45,7 @@

- +