diff --git a/server/app/helpers.py b/server/app/helpers.py index e6196ec..f2b3867 100644 --- a/server/app/helpers.py +++ b/server/app/helpers.py @@ -119,7 +119,9 @@ def create_album_hash(title: str, artist: str) -> str: """ Creates a simple hash for an album """ - return (title + artist).replace(" ", "").lower() + lower = (title + artist).replace(" ", "").lower() + hash = lower.join([i for i in lower if i not in '/\\:*?"<>|&']) + return hash def create_new_date(): diff --git a/server/app/lib/albumslib.py b/server/app/lib/albumslib.py index 6405ace..7030cbf 100644 --- a/server/app/lib/albumslib.py +++ b/server/app/lib/albumslib.py @@ -5,8 +5,8 @@ from pprint import pprint import random from typing import List -from app import api, helpers, instances, models -from app.lib import taglib, trackslib +from app import helpers, instances, models +from app.lib import taglib from tqdm import tqdm @@ -120,7 +120,6 @@ class GetAlbumTracks: self.tracks.sort(key=lambda x: x.albumhash) def __call__(self): - tracks = [] tracks = helpers.UseBisection(self.tracks, "albumhash", [self.hash])() pprint(tracks) @@ -138,7 +137,7 @@ def get_album_tracks(tracklist: List[models.Track], hash: str) -> List: return GetAlbumTracks(tracklist, hash)() -def create_album(track: dict, tracklist: list) -> dict: +def create_album(track: dict, tracklist: list[models.Track]) -> dict: """ Generates and returns an album object from a track object. """ diff --git a/server/app/lib/populate.py b/server/app/lib/populate.py index f550019..d1bd63e 100644 --- a/server/app/lib/populate.py +++ b/server/app/lib/populate.py @@ -1,13 +1,7 @@ -import os -from pprint import pprint import time from concurrent.futures import ThreadPoolExecutor -from copy import deepcopy -from multiprocessing import Pool -from os import path from typing import List -from app import api from app import settings from app.helpers import create_album_hash from app.helpers import run_fast_scandir @@ -19,9 +13,10 @@ from app.lib.taglib import get_tags from app.lib.trackslib import find_track from app.logger import Log from app.models import Album -from app.models import Track from tqdm import tqdm +from app import instances + class Populate: """ @@ -48,12 +43,12 @@ class Populate: def run(self): self.check_untagged() - self.get_all_tags() + self.tag_untagged() if len(self.tagged_tracks) == 0: return - self.tagged_tracks.sort(key=lambda x: x["albumhash"]) + # self.tagged_tracks.sort(key=lambda x: x["albumhash"]) self.pre_albums = self.create_pre_albums(self.tagged_tracks) self.create_albums(self.pre_albums) @@ -75,28 +70,15 @@ class Populate: Log(f"Found {len(self.files)} untagged tracks") - def process_tags(self, tags: dict): - for t in tags: - if t is None: - continue - - t["albumhash"] = create_album_hash(t["album"], t["albumartist"]) - self.tagged_tracks.append(t) - - self.folders.add(t["folder"]) - def get_tags(self, file: str): tags = get_tags(file) if tags is not None: - folder = tags["folder"] - self.folders.add(folder) - - tags["albumhash"] = create_album_hash(tags["album"], tags["albumartist"]) + hash = create_album_hash(tags["album"], tags["albumartist"]) + tags["albumhash"] = hash self.tagged_tracks.append(tags) - api.DB_TRACKS.append(tags) - def get_all_tags(self): + def tag_untagged(self): """ Loops through all the untagged files and tags them. """ @@ -106,6 +88,7 @@ class Populate: with ThreadPoolExecutor() as executor: executor.map(self.get_tags, self.files) + tracks_instance.insert_many(self.tagged_tracks) d = time.time() - s Log(f"Tagged {len(self.tagged_tracks)} files in {d} seconds") @@ -127,20 +110,15 @@ class Populate: def create_album(self, album: dict): albumhash = create_album_hash(album["title"], album["artist"]) - index = find_album(api.ALBUMS, albumhash) + album = instances.album_instance.find_album_by_hash(albumhash) - if index is not None: - album = api.ALBUMS[index] + if album is not None: self.albums.append(album) - self.exist_count += 1 return index = find_track(self.tagged_tracks, albumhash) - if index is None: - return - track = self.tagged_tracks[index] album = create_album(track, self.tagged_tracks) diff --git a/server/app/settings.py b/server/app/settings.py index 9cce056..fb840a2 100644 --- a/server/app/settings.py +++ b/server/app/settings.py @@ -12,7 +12,7 @@ HOME_DIR = os.path.expanduser("~") APP_DIR = os.path.join(HOME_DIR, CONFIG_FOLDER) THUMBS_PATH = os.path.join(APP_DIR, "images", "thumbnails") TEST_DIR = "/home/cwilvx/Music/Link to Music/Chill/Wolftyla Radio" -# HOME_DIR = TEST_DIR +HOME_DIR = TEST_DIR # URL IMG_BASE_URI = "http://127.0.0.1:8900/images/" IMG_ARTIST_URI = IMG_BASE_URI + "artists/" diff --git a/src/components/RightSideBar/Search/PlaylistsGrid.vue b/src/components/RightSideBar/Search/PlaylistsGrid.vue new file mode 100644 index 0000000..5a611d2 --- /dev/null +++ b/src/components/RightSideBar/Search/PlaylistsGrid.vue @@ -0,0 +1,45 @@ + + + + + diff --git a/src/components/playlists/PlaylistCard.vue b/src/components/playlists/PlaylistCard.vue index 4a67709..cd56149 100644 --- a/src/components/playlists/PlaylistCard.vue +++ b/src/components/playlists/PlaylistCard.vue @@ -4,9 +4,6 @@ :playlist="props.playlist" class="p-card rounded" > -
-
import { Playlist } from "../../interfaces"; -import PlayBtn from "../shared/PlayBtn.vue"; -import Option from "../shared/Option.vue"; import { paths } from "../../config"; -const imguri = paths.images.playlist - +const imguri = paths.images.playlist; const props = defineProps<{ playlist: Playlist; diff --git a/src/composables/searchMusic.ts b/src/composables/searchMusic.ts index 75bdac4..12d9ea2 100644 --- a/src/composables/searchMusic.ts +++ b/src/composables/searchMusic.ts @@ -43,7 +43,7 @@ async function searchTracks(query: string) { } const data = await res.json(); - console.log(data) + console.log(data); return data; } @@ -105,3 +105,6 @@ export { loadMoreAlbums, loadMoreArtists, }; + +// TODO: +// Rewrite this module using `useAxios` hook \ No newline at end of file diff --git a/src/stores/search.ts b/src/stores/search.ts index b36dccd..49344b7 100644 --- a/src/stores/search.ts +++ b/src/stores/search.ts @@ -1,6 +1,6 @@ import { ref, reactive } from "@vue/reactivity"; import { defineStore } from "pinia"; -import { AlbumInfo, Artist, Track } from "../interfaces"; +import { AlbumInfo, Artist, Playlist, Track } from "../interfaces"; import { searchTracks, searchAlbums, @@ -33,6 +33,7 @@ export default defineStore("search", () => { tracks: 0, albums: 0, artists: 0, + playlists: 0, }); const tracks = reactive({ @@ -53,6 +54,12 @@ export default defineStore("search", () => { more: false, }); + const playlists = reactive({ + query: "", + value: [], + more: false, + }); + /** * Searches for tracks, albums and artists * @param newquery query to search for @@ -123,7 +130,9 @@ export default defineStore("search", () => { .then(() => scrollOnLoad()); } - function updateLoadCounter(type: string) { + type loadType = "tracks" | "albums" | "artists" | "playlists"; + + function updateLoadCounter(type: loadType) { switch (type) { case "tracks": loadCounter.tracks += 6; @@ -204,6 +213,7 @@ export default defineStore("search", () => { tracks, albums, artists, + playlists, query, currentTab, loadCounter, diff --git a/todo b/todo index f69cb3c..83035e5 100644 --- a/todo +++ b/todo @@ -13,4 +13,25 @@ - [ ] Add settings page (or modal) - [ ] Add keyboard shortcuts listing page (or modal) - [ ] Add backspace shortcut to go back. -- [ ] Implement Esc key to cancel modals. \ No newline at end of file +- [ ] Implement Esc key to cancel modals. + + +### Notes + +- Maybe first process tags and store them to the database, then process albums from these tags. + +Like,this: +1. Tag files +2. Insert all into the database +3. Fetch all albums +4. Fetch all tracks +5. Create prealbums +6. Pop all processed albums +7. Use the following procedure to process single album image: + 7.1. Get a single album track, pop it from memory + 7.2. Try ripping image, + (i). if successful: hurray! we won't have to go further. + (ii). if failed, try getting another track from the same album, try ripping image. + (iii). If failed, repeat (ii) until success, or until you run out of tracks. In that case, set album image to fallback. + +