Skip to content

Commit

Permalink
Enable play_folder to play single songs as well
Browse files Browse the repository at this point in the history
Having one common way to play single songs as well as folders, harmonizes
how metadata is stored by the player. This makes it easier to
implement functionality working with both.
  • Loading branch information
Vito Zanotelli committed Dec 29, 2023
1 parent d6a4c6e commit f8e9de7
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/jukebox/jukebox/playlistgenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@
TYPE_DECODE = ['file', 'directory', 'stream', 'podcast']


class PseudoDirEntry:
def __init__(self, path):
import os, os.path
self.path = os.path.realpath(path)
self.name = os.path.basename(self.path)
self.is_dir = os.path.isdir(self.path)
self.stat = lambda: os.stat(self.path)

class PlaylistEntry:
def __init__(self, filetype: int, name: str, path: str):
self._type = filetype
Expand Down Expand Up @@ -230,11 +238,15 @@ def _get_directory_content(self, path='.') -> List[PlaylistEntry]:
files = []
playlist = []
self._folder = os.path.abspath(os.path.join(self._music_library_base_path, path))
for f in os.scandir(self._folder):
if f.is_dir(follow_symlinks=True):
dirs.append(f)
if self._is_valid(f):
files.append(f)
if os.path.isfile(self._folder):
files.append(PseudoDirEntry(self._folder))
path = os.path.dirname(self._folder)
else:
for f in os.scandir(self._folder):
if f.is_dir(follow_symlinks=True):
dirs.append(f)
if self._is_valid(f):
files.append(f)
# Sort the directory content (case in-sensitive) to give reproducible results across different machines
# And do this before parsing special content files. Reason: If there is a special content file (e.g. podcast)
# which links to multiple streams, these will already be ordered
Expand Down

0 comments on commit f8e9de7

Please sign in to comment.