Skip to content

Commit

Permalink
fist player content core
Browse files Browse the repository at this point in the history
  • Loading branch information
Groovylein committed Nov 6, 2023
1 parent c7a3eab commit 20d7284
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ requests
eyed3
# For the publisher event reactor loop:
tornado
# for collecting audiofiles
pyyaml

# RPi's GPIO packages: these are installed via APT on the PI
# On regular machines, install them manually if needed for development
Expand Down
34 changes: 34 additions & 0 deletions src/jukebox/components/playern/core/player_content.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import logging
import yaml

import jukebox.plugs as plugin
import jukebox.cfghandler

logger = logging.getLogger('jb.player_content')
cfg = jukebox.cfghandler.get_handler('jukebox')


class PlayerData:

def __init__(self):
self.audiofile = cfg.setndefault('players', 'content', 'audiofile', value='../../shared/audio/audiofiles.yaml')
self._database = {'audio': [],
'podcasts': [],
'livestreams': []}
self._fill_database(self.audiofile)

def _fill_database(self, yaml_file):
with open(yaml_file, 'r') as stream:
try:
self._database = yaml.safe_load(stream)
logger.debug("audiofiles database read")
except yaml.YAMLError as err:
logger.error(f"Error occured while reading {yaml_file}: {err}")

@plugin.tag
def read_player_content(self, content_type):
return self._database.get(content_type, "empty")

@plugin.tag
def get_location_of_file(self, filename):
[v.get('x', None) for v in self._database.values()]
3 changes: 3 additions & 0 deletions src/jukebox/components/playern/plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import jukebox.cfghandler
from components.playern.backends.mpd.interfacing_mpd import MPDBackend
from components.playern.core import PlayerCtrl
from components.playern.core.player_content import PlayerData
from components.playern.core.player_status import PlayerStatus

logger = logging.getLogger('jb.player')
Expand Down Expand Up @@ -64,6 +65,8 @@ def init():
player_status = PlayerStatus()
player_status.publish()

player_content = PlayerData()

# Create and register the players (this is explicit for the moment)
register_mpd()

Expand Down

0 comments on commit 20d7284

Please sign in to comment.