From 3b4f448adb73af35ca93947ed54ab085a623724c Mon Sep 17 00:00:00 2001 From: Groovylein Date: Mon, 18 Dec 2023 09:26:32 +0100 Subject: [PATCH] first attempt for get_folder_content --- .../components/player/core/player_content.py | 17 ++++++++++++++++- src/jukebox/jukebox/playlistgenerator.py | 19 +++++++++++-------- src/webapp/src/commands/index.js | 2 +- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/jukebox/components/player/core/player_content.py b/src/jukebox/components/player/core/player_content.py index 601d13e1d..93b3372b8 100644 --- a/src/jukebox/components/player/core/player_content.py +++ b/src/jukebox/components/player/core/player_content.py @@ -4,6 +4,7 @@ import jukebox.plugs as plugin import jukebox.cfghandler +from jukebox import playlistgenerator logger = logging.getLogger('jb.player_content') cfg = jukebox.cfghandler.get_handler('jukebox') @@ -13,6 +14,7 @@ class PlayerData: def __init__(self): self.audiofile = cfg.setndefault('players', 'content', 'audiofile', value='../../shared/audiofolders/audiofiles.yaml') + self.audiofile_basedir = cfg.setndefault('players', 'content', 'audiofile_basedir', value='../../shared/audiofolders') self._database = {'file': [{}], 'podcasts': [{}], 'livestreams': [{}]} @@ -32,7 +34,7 @@ def read_player_content(self, content_type): return self._database.get(content_type, "empty") @plugin.tag - def get_location(self, titlename): + def get_uri(self, titlename): for key, value in self._database.items(): for elem in value: return f"mpd:{key}:{elem['location']}" if elem['name'] == titlename else None @@ -40,3 +42,16 @@ def get_location(self, titlename): @plugin.tag def list_content(self): return self._database + + @plugin.tag + def get_folder_content(self, folder: str): + """ + Get the folder content as content list with meta-information. Depth is always 1. + + Call repeatedly to descend in hierarchy + + :param folder: Folder path relative to music library path + """ + plc = playlistgenerator.PlaylistCollector(self.audiofile_basedir) + plc.get_directory_content(folder) + return plc.playlist diff --git a/src/jukebox/jukebox/playlistgenerator.py b/src/jukebox/jukebox/playlistgenerator.py index db64d3eff..e0e463d70 100755 --- a/src/jukebox/jukebox/playlistgenerator.py +++ b/src/jukebox/jukebox/playlistgenerator.py @@ -55,6 +55,8 @@ from typing import (List) +from components.player.core import player_content + logger = logging.getLogger('jb.plgen') # From .xml podcasts, need to parse out these strings: @@ -71,23 +73,23 @@ class PlaylistEntry: - def __init__(self, filetype: int, name: str, path: str): + def __init__(self, filetype: int, name: str, uri: str = None): self._type = filetype self._name = name - self._path = path + self._uri = uri @property def name(self): return self._name - @property - def path(self): - return self._path - @property def filetype(self): return self._type + @property + def uri(self): + return self._uri + def decode_podcast_core(url, playlist): # Example url: @@ -212,7 +214,7 @@ def _is_valid(cls, direntry: os.DirEntry) -> bool: Check if filename is valid """ return direntry.is_file() and not direntry.name.startswith('.') \ - and PlaylistCollector._exclude_re.match(direntry.name) is None and direntry.name.find('.') >= 0 + and PlaylistCollector._exclude_re.match(direntry.name) is None and direntry.name.find('.') >= 0 @classmethod def set_exclusion_endings(cls, endings: List[str]): @@ -276,8 +278,9 @@ def get_directory_content(self, path='.'): except FileNotFoundError as e: logger.error(f" {e.__class__.__name__}: {e}") else: + logger.debug(f"Playlist Content: {content}") for m in content: - self.playlist.append({'type': TYPE_DECODE[m.filetype], 'name': m.name, 'path': m.path}) + self.playlist.append({'type': TYPE_DECODE[m.filetype], 'name': m.name, 'path': m.path, 'uri': m.uri}) def _parse_nonrecusive(self, path='.'): return [x.path for x in self._get_directory_content(path) if x.filetype != TYPE_DIR] diff --git a/src/webapp/src/commands/index.js b/src/webapp/src/commands/index.js index 46b0939f1..34e4e5a24 100644 --- a/src/webapp/src/commands/index.js +++ b/src/webapp/src/commands/index.js @@ -30,7 +30,7 @@ const commands = { // ToDo: Implement folderList: { _package: 'player', - plugin: 'ctrl', + plugin: 'content', method: 'get_folder_content', }, cardsList: {