mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 20:43:04 +00:00
use count_documents to get folder count
- map filenames with db data
This commit is contained in:
@@ -83,6 +83,13 @@ class Tracks(MongoTracks):
|
||||
songs = self.collection.find({"folder": query}).sort("title", pymongo.ASCENDING)
|
||||
return convert_many(songs)
|
||||
|
||||
def find_songs_by_filenames(self, filenames: list) -> list:
|
||||
"""
|
||||
Returns a list of all the tracks matching the filenames in the query params.
|
||||
"""
|
||||
songs = self.collection.find({"filepath": {"$in": filenames}})
|
||||
return convert_many(songs)
|
||||
|
||||
def find_songs_by_folder_og(self, query: str) -> list:
|
||||
"""
|
||||
Returns an unsorted list of all the track matching the folder in the query params
|
||||
@@ -90,14 +97,13 @@ class Tracks(MongoTracks):
|
||||
songs = self.collection.find({"folder": query})
|
||||
return convert_many(songs)
|
||||
|
||||
def find_tracks_inside_path_regex(self, path: str) -> list:
|
||||
def find_tracks_inside_path_regex(self, path: str) -> int:
|
||||
"""
|
||||
Returns a list of all the tracks matching the path in the query params.
|
||||
"""
|
||||
songs = self.collection.find(
|
||||
return self.collection.count_documents(
|
||||
{"filepath": {"$regex": f"^{path}", "$options": "i"}}
|
||||
)
|
||||
return convert_many(songs)
|
||||
|
||||
def find_songs_by_artist(self, query: str) -> list:
|
||||
"""
|
||||
|
||||
@@ -22,16 +22,14 @@ def reindex_tracks():
|
||||
Checks for new songs every 5 minutes.
|
||||
"""
|
||||
|
||||
while True:
|
||||
trackslib.validate_tracks()
|
||||
# while True:
|
||||
trackslib.validate_tracks()
|
||||
|
||||
Populate()
|
||||
CreateAlbums()
|
||||
Populate()
|
||||
CreateAlbums()
|
||||
|
||||
if helpers.Ping()():
|
||||
CheckArtistImages()()
|
||||
|
||||
time.sleep(60)
|
||||
if helpers.Ping()():
|
||||
CheckArtistImages()()
|
||||
|
||||
|
||||
@helpers.background
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
from dataclasses import dataclass
|
||||
from os import scandir
|
||||
import time
|
||||
from typing import Tuple
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
|
||||
from app.models import Folder
|
||||
from app.models import Track
|
||||
|
||||
from app import instances
|
||||
from app.logger import Log
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -28,7 +31,7 @@ def create_folder(dir: Dir) -> Folder:
|
||||
"name": dir.path.split("/")[-1],
|
||||
"path": dir.path,
|
||||
"is_sym": dir.is_sym,
|
||||
"trackcount": get_folder_track_count(dir.path),
|
||||
"trackcount": instances.tracks_instance.find_tracks_inside_path_regex(dir.path),
|
||||
}
|
||||
|
||||
return Folder(folder)
|
||||
@@ -59,11 +62,17 @@ class getFnF:
|
||||
dirs.append(Dir(**dir))
|
||||
elif entry.is_file() and entry.name.endswith((".mp3", ".flac")):
|
||||
files.append(entry.path)
|
||||
tracks = instances.tracks_instance.find_songs_by_folder(self.path)
|
||||
|
||||
tracks = instances.tracks_instance.find_songs_by_filenames(files)
|
||||
tracks = [Track(track) for track in tracks]
|
||||
s = time.time()
|
||||
|
||||
folders = [create_folder(dir) for dir in dirs]
|
||||
|
||||
# folders = [create_folder(dir) for dir in dirs]
|
||||
with ThreadPoolExecutor() as pool:
|
||||
iter = pool.map(create_folder, dirs)
|
||||
folders = [i for i in iter if i is not None]
|
||||
d = time.time() - s
|
||||
Log(f"Did that in {d} seconds")
|
||||
folders = filter(lambda f: f.trackcount > 0, folders)
|
||||
|
||||
return tracks, folders
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
from dataclasses import dataclass
|
||||
from pprint import pprint
|
||||
import time
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from typing import List
|
||||
|
||||
@@ -21,7 +21,6 @@ class CopyFiles:
|
||||
|
||||
for entry in files:
|
||||
src = os.path.join(os.getcwd(), entry["src"])
|
||||
print(f"Copying {src} to {entry['dest']}")
|
||||
|
||||
if entry["is_dir"]:
|
||||
shutil.copytree(
|
||||
|
||||
Reference in New Issue
Block a user