Skip to content

Commit

Permalink
first attempt for get_folder_content
Browse files Browse the repository at this point in the history
  • Loading branch information
Groovylein committed Dec 18, 2023
1 parent 5784f8d commit 3b4f448
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
17 changes: 16 additions & 1 deletion src/jukebox/components/player/core/player_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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': [{}]}
Expand All @@ -32,11 +34,24 @@ 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

@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
19 changes: 11 additions & 8 deletions src/jukebox/jukebox/playlistgenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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]):
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/webapp/src/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const commands = {
// ToDo: Implement
folderList: {
_package: 'player',
plugin: 'ctrl',
plugin: 'content',
method: 'get_folder_content',
},
cardsList: {
Expand Down

0 comments on commit 3b4f448

Please sign in to comment.