BREAK EVERYTHING

- some broken edits
This commit is contained in:
geoffrey45 2022-06-17 20:29:09 +03:00
parent 7718a7c99f
commit 06ed41d869
9 changed files with 101 additions and 49 deletions

View File

@ -119,7 +119,9 @@ def create_album_hash(title: str, artist: str) -> str:
""" """
Creates a simple hash for an album 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(): def create_new_date():

View File

@ -5,8 +5,8 @@ from pprint import pprint
import random import random
from typing import List from typing import List
from app import api, helpers, instances, models from app import helpers, instances, models
from app.lib import taglib, trackslib from app.lib import taglib
from tqdm import tqdm from tqdm import tqdm
@ -120,7 +120,6 @@ class GetAlbumTracks:
self.tracks.sort(key=lambda x: x.albumhash) self.tracks.sort(key=lambda x: x.albumhash)
def __call__(self): def __call__(self):
tracks = []
tracks = helpers.UseBisection(self.tracks, "albumhash", [self.hash])() tracks = helpers.UseBisection(self.tracks, "albumhash", [self.hash])()
pprint(tracks) pprint(tracks)
@ -138,7 +137,7 @@ def get_album_tracks(tracklist: List[models.Track], hash: str) -> List:
return GetAlbumTracks(tracklist, hash)() 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. Generates and returns an album object from a track object.
""" """

View File

@ -1,13 +1,7 @@
import os
from pprint import pprint
import time import time
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor
from copy import deepcopy
from multiprocessing import Pool
from os import path
from typing import List from typing import List
from app import api
from app import settings from app import settings
from app.helpers import create_album_hash from app.helpers import create_album_hash
from app.helpers import run_fast_scandir 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.lib.trackslib import find_track
from app.logger import Log from app.logger import Log
from app.models import Album from app.models import Album
from app.models import Track
from tqdm import tqdm from tqdm import tqdm
from app import instances
class Populate: class Populate:
""" """
@ -48,12 +43,12 @@ class Populate:
def run(self): def run(self):
self.check_untagged() self.check_untagged()
self.get_all_tags() self.tag_untagged()
if len(self.tagged_tracks) == 0: if len(self.tagged_tracks) == 0:
return 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.pre_albums = self.create_pre_albums(self.tagged_tracks)
self.create_albums(self.pre_albums) self.create_albums(self.pre_albums)
@ -75,28 +70,15 @@ class Populate:
Log(f"Found {len(self.files)} untagged tracks") 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): def get_tags(self, file: str):
tags = get_tags(file) tags = get_tags(file)
if tags is not None: if tags is not None:
folder = tags["folder"] hash = create_album_hash(tags["album"], tags["albumartist"])
self.folders.add(folder) tags["albumhash"] = hash
tags["albumhash"] = create_album_hash(tags["album"], tags["albumartist"])
self.tagged_tracks.append(tags) 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. Loops through all the untagged files and tags them.
""" """
@ -106,6 +88,7 @@ class Populate:
with ThreadPoolExecutor() as executor: with ThreadPoolExecutor() as executor:
executor.map(self.get_tags, self.files) executor.map(self.get_tags, self.files)
tracks_instance.insert_many(self.tagged_tracks)
d = time.time() - s d = time.time() - s
Log(f"Tagged {len(self.tagged_tracks)} files in {d} seconds") Log(f"Tagged {len(self.tagged_tracks)} files in {d} seconds")
@ -127,20 +110,15 @@ class Populate:
def create_album(self, album: dict): def create_album(self, album: dict):
albumhash = create_album_hash(album["title"], album["artist"]) 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: if album is not None:
album = api.ALBUMS[index]
self.albums.append(album) self.albums.append(album)
self.exist_count += 1 self.exist_count += 1
return return
index = find_track(self.tagged_tracks, albumhash) index = find_track(self.tagged_tracks, albumhash)
if index is None:
return
track = self.tagged_tracks[index] track = self.tagged_tracks[index]
album = create_album(track, self.tagged_tracks) album = create_album(track, self.tagged_tracks)

View File

@ -12,7 +12,7 @@ HOME_DIR = os.path.expanduser("~")
APP_DIR = os.path.join(HOME_DIR, CONFIG_FOLDER) APP_DIR = os.path.join(HOME_DIR, CONFIG_FOLDER)
THUMBS_PATH = os.path.join(APP_DIR, "images", "thumbnails") THUMBS_PATH = os.path.join(APP_DIR, "images", "thumbnails")
TEST_DIR = "/home/cwilvx/Music/Link to Music/Chill/Wolftyla Radio" TEST_DIR = "/home/cwilvx/Music/Link to Music/Chill/Wolftyla Radio"
# HOME_DIR = TEST_DIR HOME_DIR = TEST_DIR
# URL # URL
IMG_BASE_URI = "http://127.0.0.1:8900/images/" IMG_BASE_URI = "http://127.0.0.1:8900/images/"
IMG_ARTIST_URI = IMG_BASE_URI + "artists/" IMG_ARTIST_URI = IMG_BASE_URI + "artists/"

View 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>

View File

@ -4,9 +4,6 @@
:playlist="props.playlist" :playlist="props.playlist"
class="p-card rounded" class="p-card rounded"
> >
<div class="drop">
<Option :color="'#48484a'" />
</div>
<div <div
class="image p-image rounded shadow-sm" class="image p-image rounded shadow-sm"
:style="{ :style="{
@ -28,12 +25,9 @@
<script setup lang="ts"> <script setup lang="ts">
import { Playlist } from "../../interfaces"; import { Playlist } from "../../interfaces";
import PlayBtn from "../shared/PlayBtn.vue";
import Option from "../shared/Option.vue";
import { paths } from "../../config"; import { paths } from "../../config";
const imguri = paths.images.playlist const imguri = paths.images.playlist;
const props = defineProps<{ const props = defineProps<{
playlist: Playlist; playlist: Playlist;

View File

@ -43,7 +43,7 @@ async function searchTracks(query: string) {
} }
const data = await res.json(); const data = await res.json();
console.log(data) console.log(data);
return data; return data;
} }
@ -105,3 +105,6 @@ export {
loadMoreAlbums, loadMoreAlbums,
loadMoreArtists, loadMoreArtists,
}; };
// TODO:
// Rewrite this module using `useAxios` hook

View File

@ -1,6 +1,6 @@
import { ref, reactive } from "@vue/reactivity"; import { ref, reactive } from "@vue/reactivity";
import { defineStore } from "pinia"; import { defineStore } from "pinia";
import { AlbumInfo, Artist, Track } from "../interfaces"; import { AlbumInfo, Artist, Playlist, Track } from "../interfaces";
import { import {
searchTracks, searchTracks,
searchAlbums, searchAlbums,
@ -33,6 +33,7 @@ export default defineStore("search", () => {
tracks: 0, tracks: 0,
albums: 0, albums: 0,
artists: 0, artists: 0,
playlists: 0,
}); });
const tracks = reactive({ const tracks = reactive({
@ -53,6 +54,12 @@ export default defineStore("search", () => {
more: false, more: false,
}); });
const playlists = reactive({
query: "",
value: <Playlist[]>[],
more: false,
});
/** /**
* Searches for tracks, albums and artists * Searches for tracks, albums and artists
* @param newquery query to search for * @param newquery query to search for
@ -123,7 +130,9 @@ export default defineStore("search", () => {
.then(() => scrollOnLoad()); .then(() => scrollOnLoad());
} }
function updateLoadCounter(type: string) { type loadType = "tracks" | "albums" | "artists" | "playlists";
function updateLoadCounter(type: loadType) {
switch (type) { switch (type) {
case "tracks": case "tracks":
loadCounter.tracks += 6; loadCounter.tracks += 6;
@ -204,6 +213,7 @@ export default defineStore("search", () => {
tracks, tracks,
albums, albums,
artists, artists,
playlists,
query, query,
currentTab, currentTab,
loadCounter, loadCounter,

23
todo
View File

@ -13,4 +13,25 @@
- [ ] Add settings page (or modal) - [ ] Add settings page (or modal)
- [ ] Add keyboard shortcuts listing page (or modal) - [ ] Add keyboard shortcuts listing page (or modal)
- [ ] Add backspace shortcut to go back. - [ ] 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.