Make sure files are shown and played in order.
This commit is contained in:
+18
-7
@@ -431,6 +431,17 @@ class MenuDialog(QDialog):
|
||||
self.accept()
|
||||
|
||||
|
||||
def natural_sort_key(path):
|
||||
"""
|
||||
Generate a key for natural (human) sorting of file paths.
|
||||
Ensures that '2 - file.mp3' comes before '10 - file.mp3'.
|
||||
"""
|
||||
import re
|
||||
def convert(text):
|
||||
return int(text) if text.isdigit() else text.lower()
|
||||
return [convert(c) for c in re.split('([0-9]+)', str(path))]
|
||||
|
||||
|
||||
class AudioPlayer:
|
||||
"""Handles cross-platform audio playback using VLC if available"""
|
||||
|
||||
@@ -689,12 +700,12 @@ class AudioManualDialog(QDialog):
|
||||
def populateManuals(self):
|
||||
"""Populate manual selection combo box"""
|
||||
items = []
|
||||
# Add all directories
|
||||
for item in sorted(self.manualPath.iterdir()):
|
||||
# Add all directories with natural sorting
|
||||
for item in sorted(self.manualPath.iterdir(), key=natural_sort_key):
|
||||
if item.is_dir():
|
||||
items.append(item.name)
|
||||
# Add standalone MP3 files at root level (like "08 - Special Thanks and Shoutouts.mp3")
|
||||
for item in sorted(self.manualPath.iterdir()):
|
||||
for item in sorted(self.manualPath.iterdir(), key=natural_sort_key):
|
||||
if item.is_file() and item.suffix.lower() == '.mp3':
|
||||
items.append(item.name)
|
||||
self.manualCombo.addItems(items)
|
||||
@@ -712,8 +723,8 @@ class AudioManualDialog(QDialog):
|
||||
# For standalone MP3s, just add the file itself
|
||||
self.trackCombo.addItem(selectedManual.stem)
|
||||
else:
|
||||
# For directories, recursively find all MP3 files
|
||||
tracks = sorted(selectedManual.rglob('*.mp3'))
|
||||
# For directories, recursively find all MP3 files with natural sorting
|
||||
tracks = sorted(selectedManual.rglob('*.mp3'), key=natural_sort_key)
|
||||
if tracks:
|
||||
self.trackCombo.addItem("Play All")
|
||||
# Use relative path from selected manual for better readability
|
||||
@@ -743,8 +754,8 @@ class AudioManualDialog(QDialog):
|
||||
tracks = [selectedManual]
|
||||
self.audioPlayer.loadTracks([str(t) for t in tracks])
|
||||
elif selectedTrack == "Play All":
|
||||
# Get sorted list of all MP3 files recursively
|
||||
tracks = sorted(selectedManual.rglob('*.mp3'))
|
||||
# Get naturally sorted list of all MP3 files recursively
|
||||
tracks = sorted(selectedManual.rglob('*.mp3'), key=natural_sort_key)
|
||||
print(f"Loading {len(tracks)} tracks for Play All")
|
||||
self.audioPlayer.loadTracks([str(t) for t in tracks])
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user