mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-05 04:53:01 +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)
|
songs = self.collection.find({"folder": query}).sort("title", pymongo.ASCENDING)
|
||||||
return convert_many(songs)
|
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:
|
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
|
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})
|
songs = self.collection.find({"folder": query})
|
||||||
return convert_many(songs)
|
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.
|
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"}}
|
{"filepath": {"$regex": f"^{path}", "$options": "i"}}
|
||||||
)
|
)
|
||||||
return convert_many(songs)
|
|
||||||
|
|
||||||
def find_songs_by_artist(self, query: str) -> list:
|
def find_songs_by_artist(self, query: str) -> list:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ def reindex_tracks():
|
|||||||
Checks for new songs every 5 minutes.
|
Checks for new songs every 5 minutes.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
while True:
|
# while True:
|
||||||
trackslib.validate_tracks()
|
trackslib.validate_tracks()
|
||||||
|
|
||||||
Populate()
|
Populate()
|
||||||
@@ -31,8 +31,6 @@ def reindex_tracks():
|
|||||||
if helpers.Ping()():
|
if helpers.Ping()():
|
||||||
CheckArtistImages()()
|
CheckArtistImages()()
|
||||||
|
|
||||||
time.sleep(60)
|
|
||||||
|
|
||||||
|
|
||||||
@helpers.background
|
@helpers.background
|
||||||
def start_watchdog():
|
def start_watchdog():
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from os import scandir
|
from os import scandir
|
||||||
|
import time
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
|
|
||||||
from app.models import Folder
|
from app.models import Folder
|
||||||
from app.models import Track
|
from app.models import Track
|
||||||
|
|
||||||
from app import instances
|
from app import instances
|
||||||
|
from app.logger import Log
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -28,7 +31,7 @@ def create_folder(dir: Dir) -> Folder:
|
|||||||
"name": dir.path.split("/")[-1],
|
"name": dir.path.split("/")[-1],
|
||||||
"path": dir.path,
|
"path": dir.path,
|
||||||
"is_sym": dir.is_sym,
|
"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)
|
return Folder(folder)
|
||||||
@@ -59,11 +62,17 @@ class getFnF:
|
|||||||
dirs.append(Dir(**dir))
|
dirs.append(Dir(**dir))
|
||||||
elif entry.is_file() and entry.name.endswith((".mp3", ".flac")):
|
elif entry.is_file() and entry.name.endswith((".mp3", ".flac")):
|
||||||
files.append(entry.path)
|
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]
|
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)
|
folders = filter(lambda f: f.trackcount > 0, folders)
|
||||||
|
|
||||||
return tracks, folders
|
return tracks, folders
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from pprint import pprint
|
|
||||||
import time
|
import time
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ class CopyFiles:
|
|||||||
|
|
||||||
for entry in files:
|
for entry in files:
|
||||||
src = os.path.join(os.getcwd(), entry["src"])
|
src = os.path.join(os.getcwd(), entry["src"])
|
||||||
print(f"Copying {src} to {entry['dest']}")
|
|
||||||
|
|
||||||
if entry["is_dir"]:
|
if entry["is_dir"]:
|
||||||
shutil.copytree(
|
shutil.copytree(
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ const queue = useQStore();
|
|||||||
|
|
||||||
.title {
|
.title {
|
||||||
font-weight: 900;
|
font-weight: 900;
|
||||||
|
word-break: break-all;
|
||||||
}
|
}
|
||||||
|
|
||||||
.artists {
|
.artists {
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ defineProps<{
|
|||||||
font-size: 0.9rem;
|
font-size: 0.9rem;
|
||||||
font-weight: 510;
|
font-weight: 510;
|
||||||
max-width: 7rem;
|
max-width: 7rem;
|
||||||
|
text-transform: capitalize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -117,15 +117,6 @@ function emitUpdate(track: Track) {
|
|||||||
user-select: none;
|
user-select: none;
|
||||||
-moz-user-select: none;
|
-moz-user-select: none;
|
||||||
|
|
||||||
.context {
|
|
||||||
position: fixed;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
height: 45px;
|
|
||||||
width: 45px;
|
|
||||||
background-color: red;
|
|
||||||
}
|
|
||||||
|
|
||||||
@include tablet-landscape {
|
@include tablet-landscape {
|
||||||
grid-template-columns: 1.5rem 1.5fr 1fr 1.5fr;
|
grid-template-columns: 1.5rem 1.5fr 1fr 1.5fr;
|
||||||
}
|
}
|
||||||
@@ -145,6 +136,8 @@ function emitUpdate(track: Track) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.song-album {
|
.song-album {
|
||||||
|
word-break: break-all;
|
||||||
|
|
||||||
.album {
|
.album {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
max-width: max-content;
|
max-width: max-content;
|
||||||
@@ -156,6 +149,8 @@ function emitUpdate(track: Track) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.song-artists {
|
.song-artists {
|
||||||
|
word-break: break-all;
|
||||||
|
|
||||||
.artist {
|
.artist {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
@@ -199,6 +194,7 @@ function emitUpdate(track: Track) {
|
|||||||
|
|
||||||
.title {
|
.title {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
word-break: break-all;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -122,7 +122,13 @@ const playThis = (track: Track) => {
|
|||||||
margin: 0 0.5rem 0 0;
|
margin: 0 0.5rem 0 0;
|
||||||
background-image: url(../../assets/images/null.webp);
|
background-image: url(../../assets/images/null.webp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.title {
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
|
|
||||||
.artist {
|
.artist {
|
||||||
|
word-break: break-all;
|
||||||
font-size: small;
|
font-size: small;
|
||||||
color: rgba(255, 255, 255, 0.637);
|
color: rgba(255, 255, 255, 0.637);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user