sort files by creation date

This commit is contained in:
geoffrey45
2022-03-02 15:12:13 +03:00
parent 59646ce7f1
commit 6931cd926c
4 changed files with 77 additions and 15 deletions
+17 -5
View File
@@ -255,6 +255,7 @@ def get_folder_tree(folder: str):
dir_content = os.scandir(os.path.join(home_dir, req_dir))
folders = []
files = []
for entry in dir_content:
if entry.is_dir() and not entry.name.startswith("."):
@@ -269,11 +270,22 @@ def get_folder_tree(folder: str):
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 = []
for track in all_the_f_music:
if track.folder == req_dir:
songs.append(track)
for entry in files:
for track in all_the_f_music:
if track.filepath == entry.path:
songs.append(track)
# for track in all_the_f_music:
# if track.filepath == req_dir:
# songs.append(track)
return {
"files": helpers.remove_duplicates(songs),
@@ -348,10 +360,10 @@ def send_track_file(trackid):
return "File not found", 404
@bp.route('/sample')
@bp.route("/sample")
def get_sample_track():
"""
Returns a sample track object.
"""
return instances.songs_instance.get_song_by_album("Legends Never Die", "Juice WRLD")
return instances.songs_instance.get_song_by_album("Legends Never Die", "Juice WRLD")