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()
|
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:
|
class AudioPlayer:
|
||||||
"""Handles cross-platform audio playback using VLC if available"""
|
"""Handles cross-platform audio playback using VLC if available"""
|
||||||
|
|
||||||
@@ -689,12 +700,12 @@ class AudioManualDialog(QDialog):
|
|||||||
def populateManuals(self):
|
def populateManuals(self):
|
||||||
"""Populate manual selection combo box"""
|
"""Populate manual selection combo box"""
|
||||||
items = []
|
items = []
|
||||||
# Add all directories
|
# Add all directories with natural sorting
|
||||||
for item in sorted(self.manualPath.iterdir()):
|
for item in sorted(self.manualPath.iterdir(), key=natural_sort_key):
|
||||||
if item.is_dir():
|
if item.is_dir():
|
||||||
items.append(item.name)
|
items.append(item.name)
|
||||||
# Add standalone MP3 files at root level (like "08 - Special Thanks and Shoutouts.mp3")
|
# 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':
|
if item.is_file() and item.suffix.lower() == '.mp3':
|
||||||
items.append(item.name)
|
items.append(item.name)
|
||||||
self.manualCombo.addItems(items)
|
self.manualCombo.addItems(items)
|
||||||
@@ -712,8 +723,8 @@ class AudioManualDialog(QDialog):
|
|||||||
# For standalone MP3s, just add the file itself
|
# For standalone MP3s, just add the file itself
|
||||||
self.trackCombo.addItem(selectedManual.stem)
|
self.trackCombo.addItem(selectedManual.stem)
|
||||||
else:
|
else:
|
||||||
# For directories, recursively find all MP3 files
|
# For directories, recursively find all MP3 files with natural sorting
|
||||||
tracks = sorted(selectedManual.rglob('*.mp3'))
|
tracks = sorted(selectedManual.rglob('*.mp3'), key=natural_sort_key)
|
||||||
if tracks:
|
if tracks:
|
||||||
self.trackCombo.addItem("Play All")
|
self.trackCombo.addItem("Play All")
|
||||||
# Use relative path from selected manual for better readability
|
# Use relative path from selected manual for better readability
|
||||||
@@ -743,8 +754,8 @@ class AudioManualDialog(QDialog):
|
|||||||
tracks = [selectedManual]
|
tracks = [selectedManual]
|
||||||
self.audioPlayer.loadTracks([str(t) for t in tracks])
|
self.audioPlayer.loadTracks([str(t) for t in tracks])
|
||||||
elif selectedTrack == "Play All":
|
elif selectedTrack == "Play All":
|
||||||
# Get sorted list of all MP3 files recursively
|
# Get naturally sorted list of all MP3 files recursively
|
||||||
tracks = sorted(selectedManual.rglob('*.mp3'))
|
tracks = sorted(selectedManual.rglob('*.mp3'), key=natural_sort_key)
|
||||||
print(f"Loading {len(tracks)} tracks for Play All")
|
print(f"Loading {len(tracks)} tracks for Play All")
|
||||||
self.audioPlayer.loadTracks([str(t) for t in tracks])
|
self.audioPlayer.loadTracks([str(t) for t in tracks])
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user