use count_documents to get folder count

- map filenames with db data
This commit is contained in:
geoffrey45 2022-06-21 16:24:27 +03:00
parent 2b5e9c02bb
commit 3cd0527962
9 changed files with 41 additions and 26 deletions

View File

@ -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:
"""

View File

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

View File

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

View File

@ -1,5 +1,4 @@
from dataclasses import dataclass
from pprint import pprint
import time
from concurrent.futures import ThreadPoolExecutor
from typing import List

View File

@ -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(

View File

@ -102,6 +102,7 @@ const queue = useQStore();
.title {
font-weight: 900;
word-break: break-all;
}
.artists {

View File

@ -63,6 +63,7 @@ defineProps<{
font-size: 0.9rem;
font-weight: 510;
max-width: 7rem;
text-transform: capitalize;
}
}

View File

@ -117,15 +117,6 @@ function emitUpdate(track: Track) {
user-select: none;
-moz-user-select: none;
.context {
position: fixed;
top: 0;
left: 0;
height: 45px;
width: 45px;
background-color: red;
}
@include tablet-landscape {
grid-template-columns: 1.5rem 1.5fr 1fr 1.5fr;
}
@ -145,6 +136,8 @@ function emitUpdate(track: Track) {
}
.song-album {
word-break: break-all;
.album {
cursor: pointer;
max-width: max-content;
@ -156,6 +149,8 @@ function emitUpdate(track: Track) {
}
.song-artists {
word-break: break-all;
.artist {
cursor: pointer;
}
@ -199,6 +194,7 @@ function emitUpdate(track: Track) {
.title {
cursor: pointer;
word-break: break-all;
}
}

View File

@ -122,7 +122,13 @@ const playThis = (track: Track) => {
margin: 0 0.5rem 0 0;
background-image: url(../../assets/images/null.webp);
}
.title {
word-break: break-all;
}
.artist {
word-break: break-all;
font-size: small;
color: rgba(255, 255, 255, 0.637);
}