mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-05 04:53:01 +00:00
sort files by creation date
This commit is contained in:
+14
-2
@@ -255,6 +255,7 @@ def get_folder_tree(folder: str):
|
|||||||
dir_content = os.scandir(os.path.join(home_dir, req_dir))
|
dir_content = os.scandir(os.path.join(home_dir, req_dir))
|
||||||
|
|
||||||
folders = []
|
folders = []
|
||||||
|
files = []
|
||||||
|
|
||||||
for entry in dir_content:
|
for entry in dir_content:
|
||||||
if entry.is_dir() and not entry.name.startswith("."):
|
if entry.is_dir() and not entry.name.startswith("."):
|
||||||
@@ -269,12 +270,23 @@ def get_folder_tree(folder: str):
|
|||||||
|
|
||||||
folders.append(_dir)
|
folders.append(_dir)
|
||||||
|
|
||||||
|
if entry.is_file():
|
||||||
|
if entry.name.endswith(".flac") or entry.name.endswith(".mp3"):
|
||||||
|
files.append(entry)
|
||||||
|
|
||||||
|
files.sort(key=lambda x: os.path.getmtime(x.path))
|
||||||
|
|
||||||
songs = []
|
songs = []
|
||||||
|
|
||||||
|
for entry in files:
|
||||||
for track in all_the_f_music:
|
for track in all_the_f_music:
|
||||||
if track.folder == req_dir:
|
if track.filepath == entry.path:
|
||||||
songs.append(track)
|
songs.append(track)
|
||||||
|
|
||||||
|
# for track in all_the_f_music:
|
||||||
|
# if track.filepath == req_dir:
|
||||||
|
# songs.append(track)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"files": helpers.remove_duplicates(songs),
|
"files": helpers.remove_duplicates(songs),
|
||||||
"folders": sorted(folders, key=lambda i: i["name"]),
|
"folders": sorted(folders, key=lambda i: i["name"]),
|
||||||
@@ -348,7 +360,7 @@ def send_track_file(trackid):
|
|||||||
return "File not found", 404
|
return "File not found", 404
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/sample')
|
@bp.route("/sample")
|
||||||
def get_sample_track():
|
def get_sample_track():
|
||||||
"""
|
"""
|
||||||
Returns a sample track object.
|
Returns a sample track object.
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ def reindex_tracks():
|
|||||||
while flag is False:
|
while flag is False:
|
||||||
functions.populate()
|
functions.populate()
|
||||||
functions.populate_images()
|
functions.populate_images()
|
||||||
|
# functions.save_t_colors()
|
||||||
|
|
||||||
time.sleep(300)
|
time.sleep(300)
|
||||||
|
|
||||||
|
|
||||||
@@ -153,17 +155,21 @@ def get_all_songs() -> List[models.Track]:
|
|||||||
|
|
||||||
for track in instances.songs_instance.get_all_songs():
|
for track in instances.songs_instance.get_all_songs():
|
||||||
try:
|
try:
|
||||||
os.chmod(os.path.join(track["filepath"]), 0o755)
|
os.chmod(track["filepath"], 0o755)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
instances.songs_instance.remove_song_by_filepath(track["filepath"])
|
instances.songs_instance.remove_song_by_filepath(track["filepath"])
|
||||||
|
|
||||||
tracks.append(functions.create_track_class(track))
|
tracks.append(models.Track(track))
|
||||||
|
|
||||||
return tracks
|
return tracks
|
||||||
|
|
||||||
|
|
||||||
def extract_colors(image) -> list:
|
def extract_colors(image) -> list:
|
||||||
|
"""Extracts 2 of the most dominant colors from an image."""
|
||||||
|
try:
|
||||||
colors = sorted(colorgram.extract(image, 2), key=lambda c: c.hsl.h)
|
colors = sorted(colorgram.extract(image, 2), key=lambda c: c.hsl.h)
|
||||||
|
except OSError:
|
||||||
|
return []
|
||||||
|
|
||||||
formatted_colors = []
|
formatted_colors = []
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
from app.models import AllSongs
|
from app.models import AllSongs
|
||||||
from app.models import Artists
|
from app.models import Artists
|
||||||
|
from app.models import TrackColors
|
||||||
|
|
||||||
songs_instance = AllSongs()
|
songs_instance = AllSongs()
|
||||||
artist_instance = Artists()
|
artist_instance = Artists()
|
||||||
|
track_color_instance = TrackColors()
|
||||||
+47
-5
@@ -53,8 +53,9 @@ class Artists(Mongo):
|
|||||||
"""
|
"""
|
||||||
Inserts an artist into the database.
|
Inserts an artist into the database.
|
||||||
"""
|
"""
|
||||||
self.collection.update_one(artist_obj, {"$set": artist_obj}, upsert=True).upserted_id
|
self.collection.update_one(
|
||||||
|
artist_obj, {"$set": artist_obj}, upsert=True
|
||||||
|
).upserted_id
|
||||||
|
|
||||||
def get_all_artists(self) -> list:
|
def get_all_artists(self) -> list:
|
||||||
"""
|
"""
|
||||||
@@ -201,6 +202,34 @@ class AllSongs(Mongo):
|
|||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
class TrackColors(Mongo):
|
||||||
|
"""
|
||||||
|
The class for all track-related database operations.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super(TrackColors, self).__init__("TRACK_COLORS")
|
||||||
|
self.collection = self.db["TRACK_COLORS"]
|
||||||
|
|
||||||
|
def insert_track_color(self, track_color: dict) -> None:
|
||||||
|
"""
|
||||||
|
Inserts a new track object into the database.
|
||||||
|
"""
|
||||||
|
return self.collection.update_one(
|
||||||
|
{"filepath": track_color["filepath"]},
|
||||||
|
{"$set": track_color},
|
||||||
|
upsert=True,
|
||||||
|
).upserted_id
|
||||||
|
|
||||||
|
def get_track_color_by_track(self, filepath: str) -> dict:
|
||||||
|
"""
|
||||||
|
Returns a track color object by its filepath.
|
||||||
|
"""
|
||||||
|
track_color = self.collection.find_one({"filepath": filepath})
|
||||||
|
return convert_one_to_json(track_color)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Track:
|
class Track:
|
||||||
"""
|
"""
|
||||||
@@ -213,6 +242,7 @@ class Track:
|
|||||||
albumartist: str
|
albumartist: str
|
||||||
album: str
|
album: str
|
||||||
folder: str
|
folder: str
|
||||||
|
filepath: str
|
||||||
length: int
|
length: int
|
||||||
date: int
|
date: int
|
||||||
genre: str
|
genre: str
|
||||||
@@ -221,6 +251,18 @@ class Track:
|
|||||||
tracknumber: int
|
tracknumber: int
|
||||||
discnumber: int
|
discnumber: int
|
||||||
|
|
||||||
def __post_init__(self):
|
def __init__(self, tags):
|
||||||
self.artists = self.artists.split(", ")
|
self.trackid = tags["_id"]["$oid"]
|
||||||
self.image = "http://127.0.0.1:8900/images/thumbnails/" + self.image
|
self.title = tags["title"]
|
||||||
|
self.artists = tags["artists"].split(", ")
|
||||||
|
self.albumartist = tags["albumartist"]
|
||||||
|
self.album = tags["album"]
|
||||||
|
self.folder = tags["folder"]
|
||||||
|
self.filepath = tags["filepath"]
|
||||||
|
self.length = tags["length"]
|
||||||
|
self.date = tags["date"]
|
||||||
|
self.genre = tags["genre"]
|
||||||
|
self.bitrate = tags["bitrate"]
|
||||||
|
self.image = "http://127.0.0.1:8900/images/thumbnails/" + tags["image"]
|
||||||
|
self.tracknumber = tags["tracknumber"]
|
||||||
|
self.discnumber = tags["discnumber"]
|
||||||
|
|||||||
Reference in New Issue
Block a user