mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 12:33:03 +00:00
BREAK EVERYTHING
- some broken edits
This commit is contained in:
@@ -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.
|
||||
"""
|
||||
|
||||
+10
-32
@@ -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/"
|
||||
|
||||
Reference in New Issue
Block a user