mirror of
https://github.com/tcsenpai/swingmusic.git
synced 2025-07-28 21:51:41 +00:00
BREAK EVERYTHING
- some broken edits
This commit is contained in:
parent
7718a7c99f
commit
06ed41d869
@ -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():
|
||||
|
@ -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.
|
||||
"""
|
||||
|
@ -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)
|
||||
|
@ -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/"
|
||||
|
45
src/components/RightSideBar/Search/PlaylistsGrid.vue
Normal file
45
src/components/RightSideBar/Search/PlaylistsGrid.vue
Normal file
@ -0,0 +1,45 @@
|
||||
<template>
|
||||
<div class="albums-results border">
|
||||
<div class="grid">
|
||||
<PCard
|
||||
v-for="album in search.albums.value"
|
||||
:key="`${album.artist}-${album.title}`"
|
||||
:album="album"
|
||||
/>
|
||||
</div>
|
||||
<LoadMore v-if="search.albums.more" @loadMore="loadMore()" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import PCard from "../../playlists/PlaylistCard.vue";
|
||||
import LoadMore from "./LoadMore.vue";
|
||||
import useSearchStore from "../../../stores/search";
|
||||
|
||||
const search = useSearchStore();
|
||||
|
||||
function loadMore() {
|
||||
search.updateLoadCounter("albums");
|
||||
search.loadAlbums(search.loadCounter.albums);
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.right-search .albums-results {
|
||||
border-radius: 0.5rem;
|
||||
margin-top: $small;
|
||||
padding: $small;
|
||||
overflow-x: hidden;
|
||||
|
||||
.result-item:hover {
|
||||
background-color: $gray4;
|
||||
}
|
||||
|
||||
.grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr));
|
||||
flex-wrap: wrap;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
}
|
||||
</style>
|
@ -4,9 +4,6 @@
|
||||
:playlist="props.playlist"
|
||||
class="p-card rounded"
|
||||
>
|
||||
<div class="drop">
|
||||
<Option :color="'#48484a'" />
|
||||
</div>
|
||||
<div
|
||||
class="image p-image rounded shadow-sm"
|
||||
:style="{
|
||||
@ -28,12 +25,9 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
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;
|
||||
|
@ -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
|
@ -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: <Playlist[]>[],
|
||||
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,
|
||||
|
23
todo
23
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.
|
||||
- [ ] 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.
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user