Skip to content

Commit

Permalink
pupdate
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesmadere committed Feb 4, 2025
1 parent f5f3575 commit a2d9688
Show file tree
Hide file tree
Showing 24 changed files with 431 additions and 232 deletions.
8 changes: 8 additions & 0 deletions src/soundPlayerManager/audioPlayer/audioPlayerMediaPlayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ def __play(self, task: AudioPlayerPlaybackTask):
self.__timber.log('AudioPlayerMediaPlayer', f'Attempted to play, but encountered bizarre durationSeconds value ({task=}) ({audioPlayer=}) ({durationSeconds=})')
return

if task.isCanceled:
# It is technically possible that playback could have been canceled before we
# even begin playing this file. So let's do one final cancelation check super
# quick before we start the actual file playback.
self.__playbackTask = None
self.__isPlayingOrLoading = False
return

audioPlayer.play(
loop = False,
block = False
Expand Down
102 changes: 55 additions & 47 deletions src/soundPlayerManager/audioPlayer/audioPlayerSoundPlayerManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from ..settings.soundPlayerSettingsRepositoryInterface import SoundPlayerSettingsRepositoryInterface
from ..soundAlert import SoundAlert
from ..soundPlayerManagerInterface import SoundPlayerManagerInterface
from ..soundPlayerPlaylist import SoundPlayerPlaylist
from ...chatBand.chatBandInstrument import ChatBandInstrument
from ...chatBand.chatBandInstrumentSoundsRepositoryInterface import ChatBandInstrumentSoundsRepositoryInterface
from ...location.timeZoneRepositoryInterface import TimeZoneRepositoryInterface
Expand Down Expand Up @@ -92,59 +93,17 @@ async def playChatBandInstrument(
filePaths.append(filePath)
filePaths.freeze()

return await self.playPlaylist(
return await self.playSoundFiles(
filePaths = filePaths,
volume = volume
)

async def playPlaylist(
self,
filePaths: Collection[str],
volume: int | None = None
playlist: SoundPlayerPlaylist
) -> bool:
if not isinstance(filePaths, Collection):
raise TypeError(f'filePaths argument is malformed: \"{filePaths}\"')
elif volume is not None and not utils.isValidInt(volume):
raise TypeError(f'volume argument is malformed: \"{volume}\"')

if not await self.__soundPlayerSettingsRepository.isEnabled():
return False
elif self.isLoadingOrPlaying:
self.__timber.log('AudioPlayerSoundPlayerManager', f'There is already an ongoing sound!')
return False

self.__isLoadingOrPlaying = True
frozenFilePaths: FrozenList[str] = FrozenList(filePaths)
frozenFilePaths.freeze()

if len(frozenFilePaths) == 0:
self.__timber.log('AudioPlayerSoundPlayerManager', f'filePaths argument has no elements: \"{filePaths}\"')
self.__isLoadingOrPlaying = False
return False

for index, filePath in enumerate(frozenFilePaths):
if not utils.isValidStr(filePath):
self.__timber.log('AudioPlayerSoundPlayerManager', f'The given file path at index {index} is not a valid string: \"{filePath}\"')
self.__isLoadingOrPlaying = False
return False
elif not await aiofiles.ospath.exists(filePath):
self.__timber.log('AudioPlayerSoundPlayerManager', f'The given file path at index {index} does not exist: \"{filePath}\"')
self.__isLoadingOrPlaying = False
return False
elif not await aiofiles.ospath.isfile(filePath):
self.__timber.log('AudioPlayerSoundPlayerManager', f'The given file path at index {index} is not a file: \"{filePath}\"')
self.__isLoadingOrPlaying = False
return False

if not utils.isValidInt(volume):
volume = await self.__soundPlayerSettingsRepository.getMediaPlayerVolume()

await self.__progressThroughPlaylist(
playlistFilePaths = frozenFilePaths,
volume = volume
)

return True
# TODO
return False

async def playSoundAlert(
self,
Expand Down Expand Up @@ -196,11 +155,60 @@ async def playSoundFile(
filePaths.append(filePath)
filePaths.freeze()

return await self.playPlaylist(
return await self.playSoundFiles(
filePaths = filePaths,
volume = volume
)

async def playSoundFiles(
self,
filePaths: Collection[str],
volume: int | None = None
) -> bool:
if not isinstance(filePaths, Collection):
raise TypeError(f'filePaths argument is malformed: \"{filePaths}\"')
elif volume is not None and not utils.isValidInt(volume):
raise TypeError(f'volume argument is malformed: \"{volume}\"')

if not await self.__soundPlayerSettingsRepository.isEnabled():
return False
elif self.isLoadingOrPlaying:
self.__timber.log('AudioPlayerSoundPlayerManager', f'There is already an ongoing sound!')
return False

self.__isLoadingOrPlaying = True
frozenFilePaths: FrozenList[str] = FrozenList(filePaths)
frozenFilePaths.freeze()

if len(frozenFilePaths) == 0:
self.__timber.log('AudioPlayerSoundPlayerManager', f'filePaths argument has no elements: \"{filePaths}\"')
self.__isLoadingOrPlaying = False
return False

for index, filePath in enumerate(frozenFilePaths):
if not utils.isValidStr(filePath):
self.__timber.log('AudioPlayerSoundPlayerManager', f'The given file path at index {index} is not a valid string: \"{filePath}\"')
self.__isLoadingOrPlaying = False
return False
elif not await aiofiles.ospath.exists(filePath):
self.__timber.log('AudioPlayerSoundPlayerManager', f'The given file path at index {index} does not exist: \"{filePath}\"')
self.__isLoadingOrPlaying = False
return False
elif not await aiofiles.ospath.isfile(filePath):
self.__timber.log('AudioPlayerSoundPlayerManager', f'The given file path at index {index} is not a file: \"{filePath}\"')
self.__isLoadingOrPlaying = False
return False

if not utils.isValidInt(volume):
volume = await self.__soundPlayerSettingsRepository.getMediaPlayerVolume()

await self.__progressThroughPlaylist(
playlistFilePaths = frozenFilePaths,
volume = volume
)

return True

async def __progressThroughPlaylist(
self,
playlistFilePaths: FrozenList[str],
Expand Down
7 changes: 7 additions & 0 deletions src/soundPlayerManager/soundPlaybackFile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from dataclasses import dataclass


@dataclass(frozen = True)
class SoundPlaybackFile:
volume: int | None
filePath: str
12 changes: 10 additions & 2 deletions src/soundPlayerManager/soundPlayerManagerInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Collection

from .soundAlert import SoundAlert
from .soundPlayerPlaylist import SoundPlayerPlaylist
from ..chatBand.chatBandInstrument import ChatBandInstrument


Expand All @@ -23,8 +24,7 @@ async def playChatBandInstrument(
@abstractmethod
async def playPlaylist(
self,
filePaths: Collection[str],
volume: int | None = None
playlist: SoundPlayerPlaylist
) -> bool:
pass

Expand All @@ -44,6 +44,14 @@ async def playSoundFile(
) -> bool:
pass

@abstractmethod
async def playSoundFiles(
self,
filePaths: Collection[str],
volume: int | None = None
) -> bool:
pass

@abstractmethod
async def stop(self):
pass
10 changes: 10 additions & 0 deletions src/soundPlayerManager/soundPlayerPlaylist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from dataclasses import dataclass

from frozenlist import FrozenList

from .soundPlaybackFile import SoundPlaybackFile


@dataclass(frozen = True)
class SoundPlayerPlaylist:
playlist: FrozenList[SoundPlaybackFile]
12 changes: 10 additions & 2 deletions src/soundPlayerManager/stub/stubSoundPlayerManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from ..soundAlert import SoundAlert
from ..soundPlayerManagerInterface import SoundPlayerManagerInterface
from ..soundPlayerPlaylist import SoundPlayerPlaylist
from ...chatBand.chatBandInstrument import ChatBandInstrument


Expand All @@ -22,8 +23,7 @@ async def playChatBandInstrument(

async def playPlaylist(
self,
filePaths: Collection[str],
volume: int | None = None
playlist: SoundPlayerPlaylist
) -> bool:
# this method is intentionally empty
return False
Expand All @@ -44,6 +44,14 @@ async def playSoundFile(
# this method is intentionally empty
return False

async def playSoundFiles(
self,
filePaths: Collection[str],
volume: int | None = None
) -> bool:
# this method is intentionally empty
return False

async def stop(self):
# this method is intentionally empty
pass
102 changes: 55 additions & 47 deletions src/soundPlayerManager/vlc/vlcSoundPlayerManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from ..settings.soundPlayerSettingsRepositoryInterface import SoundPlayerSettingsRepositoryInterface
from ..soundAlert import SoundAlert
from ..soundPlayerManagerInterface import SoundPlayerManagerInterface
from ..soundPlayerPlaylist import SoundPlayerPlaylist
from ...chatBand.chatBandInstrument import ChatBandInstrument
from ...chatBand.chatBandInstrumentSoundsRepositoryInterface import ChatBandInstrumentSoundsRepositoryInterface
from ...misc import utils as utils
Expand Down Expand Up @@ -82,59 +83,17 @@ async def playChatBandInstrument(
filePaths.append(filePath)
filePaths.freeze()

return await self.playPlaylist(
return await self.playSoundFiles(
filePaths = filePaths,
volume = volume
)

async def playPlaylist(
self,
filePaths: Collection[str],
volume: int | None = None
playlist: SoundPlayerPlaylist
) -> bool:
if not isinstance(filePaths, Collection):
raise TypeError(f'filePaths argument is malformed: \"{filePaths}\"')
elif volume is not None and not utils.isValidInt(volume):
raise TypeError(f'volume argument is malformed: \"{volume}\"')

if not await self.__soundPlayerSettingsRepository.isEnabled():
return False
elif self.isLoadingOrPlaying:
self.__timber.log('VlcSoundPlayerManager', f'There is already an ongoing sound!')
return False

self.__isLoadingOrPlaying = True
frozenFilePaths: FrozenList[str] = FrozenList(filePaths)
frozenFilePaths.freeze()

if len(frozenFilePaths) == 0:
self.__timber.log('VlcSoundPlayerManager', f'filePaths argument has no elements: \"{filePaths}\"')
self.__isLoadingOrPlaying = False
return False

for index, filePath in enumerate(frozenFilePaths):
if not utils.isValidStr(filePath):
self.__timber.log('VlcSoundPlayerManager', f'The given file path at index {index} is not a valid string: \"{filePath}\"')
self.__isLoadingOrPlaying = False
return False
elif not await aiofiles.ospath.exists(filePath):
self.__timber.log('VlcSoundPlayerManager', f'The given file path at index {index} does not exist: \"{filePath}\"')
self.__isLoadingOrPlaying = False
return False
elif not await aiofiles.ospath.isfile(filePath):
self.__timber.log('VlcSoundPlayerManager', f'The given file path at index {index} is not a file: \"{filePath}\"')
self.__isLoadingOrPlaying = False
return False

if not utils.isValidInt(volume):
volume = await self.__soundPlayerSettingsRepository.getMediaPlayerVolume()

await self.__progressThroughPlaylist(
playlistFilePaths = frozenFilePaths,
volume = volume
)

return True
# TODO
return False

async def playSoundAlert(
self,
Expand Down Expand Up @@ -186,11 +145,60 @@ async def playSoundFile(
filePaths.append(filePath)
filePaths.freeze()

return await self.playPlaylist(
return await self.playSoundFiles(
filePaths = filePaths,
volume = volume
)

async def playSoundFiles(
self,
filePaths: Collection[str],
volume: int | None = None
) -> bool:
if not isinstance(filePaths, Collection):
raise TypeError(f'filePaths argument is malformed: \"{filePaths}\"')
elif volume is not None and not utils.isValidInt(volume):
raise TypeError(f'volume argument is malformed: \"{volume}\"')

if not await self.__soundPlayerSettingsRepository.isEnabled():
return False
elif self.isLoadingOrPlaying:
self.__timber.log('VlcSoundPlayerManager', f'There is already an ongoing sound!')
return False

self.__isLoadingOrPlaying = True
frozenFilePaths: FrozenList[str] = FrozenList(filePaths)
frozenFilePaths.freeze()

if len(frozenFilePaths) == 0:
self.__timber.log('VlcSoundPlayerManager', f'filePaths argument has no elements: \"{filePaths}\"')
self.__isLoadingOrPlaying = False
return False

for index, filePath in enumerate(frozenFilePaths):
if not utils.isValidStr(filePath):
self.__timber.log('VlcSoundPlayerManager', f'The given file path at index {index} is not a valid string: \"{filePath}\"')
self.__isLoadingOrPlaying = False
return False
elif not await aiofiles.ospath.exists(filePath):
self.__timber.log('VlcSoundPlayerManager', f'The given file path at index {index} does not exist: \"{filePath}\"')
self.__isLoadingOrPlaying = False
return False
elif not await aiofiles.ospath.isfile(filePath):
self.__timber.log('VlcSoundPlayerManager', f'The given file path at index {index} is not a file: \"{filePath}\"')
self.__isLoadingOrPlaying = False
return False

if not utils.isValidInt(volume):
volume = await self.__soundPlayerSettingsRepository.getMediaPlayerVolume()

await self.__progressThroughPlaylist(
playlistFilePaths = frozenFilePaths,
volume = volume
)

return True

async def __progressThroughPlaylist(
self,
playlistFilePaths: FrozenList[str],
Expand Down
2 changes: 1 addition & 1 deletion src/tts/halfLife/halfLifeTtsManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async def __executeTts(self, fileNames: FrozenList[str]):
timeoutSeconds = await self.__ttsSettingsRepository.getTtsTimeoutSeconds()

async def playPlaylist():
await self.__soundPlayerManager.playPlaylist(
await self.__soundPlayerManager.playSoundFiles(
filePaths = fileNames,
volume = volume
)
Expand Down
Loading

0 comments on commit a2d9688

Please sign in to comment.