Replace playsound3 with pyglet for audio notifications

Switched sound notification library from playsound3 to pyglet in requirements and main GUI code. Updated all related logic and logging to use pyglet for audio playback, improving compatibility and maintainability.
This commit is contained in:
Your Name
2025-08-28 17:38:48 +03:00
parent 7be376c2fd
commit 70488e6ecc
2 changed files with 15 additions and 13 deletions
+1 -1
View File
@@ -4,6 +4,6 @@ requests
pillow pillow
packaging packaging
markdown markdown
playsound3 pyglet
loguru loguru
setuptools setuptools
+14 -12
View File
@@ -55,10 +55,11 @@ except ImportError:
YT_DLP_AVAILABLE = False YT_DLP_AVAILABLE = False
try: try:
from playsound3 import playsound import pyglet
PLAYSOUND_AVAILABLE = True
PYGLET_AVAILABLE = True
except ImportError: except ImportError:
PLAYSOUND_AVAILABLE = False PYGLET_AVAILABLE = False
class YTSageApp(QMainWindow, FormatTableMixin, VideoInfoMixin): # Inherit from mixins class YTSageApp(QMainWindow, FormatTableMixin, VideoInfoMixin): # Inherit from mixins
@@ -71,8 +72,8 @@ class YTSageApp(QMainWindow, FormatTableMixin, VideoInfoMixin): # Inherit from
# Log startup warnings for missing dependencies # Log startup warnings for missing dependencies
if not YT_DLP_AVAILABLE: if not YT_DLP_AVAILABLE:
self.logger.warning("yt-dlp not available at startup, will be downloaded at runtime") self.logger.warning("yt-dlp not available at startup, will be downloaded at runtime")
if not PLAYSOUND_AVAILABLE: if not PYGLET_AVAILABLE:
self.logger.warning("playsound3 not available, audio notifications disabled") self.logger.warning("pyglet not available, audio notifications disabled")
# Check for FFmpeg before proceeding # Check for FFmpeg before proceeding
if not check_ffmpeg(): if not check_ffmpeg():
@@ -304,13 +305,13 @@ class YTSageApp(QMainWindow, FormatTableMixin, VideoInfoMixin): # Inherit from
# Initialize UI state based on current mode # Initialize UI state based on current mode
self.handle_mode_change() self.handle_mode_change()
# Initialize playsound3 for sound notifications # Initialize pyglet for sound notifications
self.init_sound() self.init_sound()
def init_sound(self) -> None: def init_sound(self) -> None:
"""Initialize playsound3 for sound notifications""" """Initialize pyglet for sound notifications"""
try: try:
if PLAYSOUND_AVAILABLE: if PYGLET_AVAILABLE:
self.sound_enabled = True self.sound_enabled = True
# sound_path logic moved to src\utils\ytsage_constants.py # sound_path logic moved to src\utils\ytsage_constants.py
@@ -324,7 +325,7 @@ class YTSageApp(QMainWindow, FormatTableMixin, VideoInfoMixin): # Inherit from
self.logger.info(f"Notification sound loaded from: {self.notification_sound_path}") self.logger.info(f"Notification sound loaded from: {self.notification_sound_path}")
else: else:
self.sound_enabled = False self.sound_enabled = False
self.logger.info("Sound notifications disabled - playsound3 not available") self.logger.info("Sound notifications disabled - pyglet not available")
except Exception as e: except Exception as e:
self.logger.error(f"Error initializing sound: {e}") self.logger.error(f"Error initializing sound: {e}")
@@ -337,9 +338,10 @@ class YTSageApp(QMainWindow, FormatTableMixin, VideoInfoMixin): # Inherit from
def play_sound() -> None: def play_sound() -> None:
try: try:
if PLAYSOUND_AVAILABLE: if PYGLET_AVAILABLE:
# Play the sound using playsound3 # Play the sound using pyglet
playsound(str(self.notification_sound_path)) sound = pyglet.media.load(str(self.notification_sound_path))
sound.play()
except Exception as e: except Exception as e:
self.logger.error(f"Error playing notification sound: {e}") self.logger.error(f"Error playing notification sound: {e}")