From c3040d1996ce582ddb46945e8730a8748d092a2a Mon Sep 17 00:00:00 2001 From: pabera <1260686+pabera@users.noreply.github.com> Date: Sun, 17 Nov 2024 13:01:41 +0100 Subject: [PATCH] Adapt Webapp to new play_content and play_from_reader API --- src/jukebox/components/playermpd/__init__.py | 14 +++--- src/jukebox/components/rfid/cards/__init__.py | 46 +++++++++++-------- src/jukebox/components/rpc_command_alias.py | 6 +-- src/webapp/public/locales/de/translation.json | 17 +++---- src/webapp/public/locales/en/translation.json | 17 +++---- src/webapp/src/commands/index.js | 18 ++++++++ .../Cards/controls/actions-controls.js | 8 ++-- .../{play-music => play-content}/index.js | 23 +++++----- .../no-music-selected.js | 2 +- .../selected-album.js | 2 +- .../selected-folder.js | 0 .../selected-single.js | 2 +- .../Cards/controls/controls-selector.js | 6 +-- src/webapp/src/components/Cards/edit.js | 4 +- src/webapp/src/components/Cards/list.js | 10 +++- src/webapp/src/components/Cards/register.js | 1 + src/webapp/src/components/Cards/utils.js | 5 ++ .../Library/lists/albums/song-list/index.js | 6 +-- .../albums/song-list/song-list-controls.js | 7 ++- .../lists/albums/song-list/song-list-item.js | 9 ++-- .../Library/lists/folders/folder-list-item.js | 6 +-- .../Library/lists/folders/folder-list.js | 4 +- .../components/Library/lists/folders/index.js | 4 +- .../src/components/Library/lists/index.js | 8 ++-- src/webapp/src/config.js | 6 +-- src/webapp/src/utils/utils.js | 11 +++++ 26 files changed, 145 insertions(+), 97 deletions(-) rename src/webapp/src/components/Cards/controls/actions/{play-music => play-content}/index.js (69%) rename src/webapp/src/components/Cards/controls/actions/{play-music => play-content}/no-music-selected.js (80%) rename src/webapp/src/components/Cards/controls/actions/{play-music => play-content}/selected-album.js (88%) rename src/webapp/src/components/Cards/controls/actions/{play-music => play-content}/selected-folder.js (100%) rename src/webapp/src/components/Cards/controls/actions/{play-music => play-content}/selected-single.js (95%) diff --git a/src/jukebox/components/playermpd/__init__.py b/src/jukebox/components/playermpd/__init__.py index f5f8669bd..161b81679 100644 --- a/src/jukebox/components/playermpd/__init__.py +++ b/src/jukebox/components/playermpd/__init__.py @@ -577,7 +577,7 @@ def play_content(self, content: Union[str, Dict[str, Any]], content_type: str = :param content: Content identifier: - For singles/folders: file/folder path as string - - For albums: dict with 'artist' and 'album' keys + - For albums: dict with 'albumartist' and 'album' keys :param content_type: Type of content ('single', 'album', 'folder') :param recursive: Add folder recursively (only used for folder type) """ @@ -585,16 +585,16 @@ def play_content(self, content: Union[str, Dict[str, Any]], content_type: str = content_type = content_type.lower() if content_type == 'album': if isinstance(content, dict): - artist = content.get('artist') + albumartist = content.get('albumartist') album = content.get('album') - if not artist or not album: - raise ValueError("Album content must contain both 'artist' and 'album' keys") + if not albumartist or not album: + raise ValueError("Album content must contain both 'albumartist' and 'album' keys") else: - raise ValueError("Album content must be a dictionary with 'artist' and 'album' keys") + raise ValueError("Album content must be a dictionary with 'albumartist' and 'album' keys") play_content = PlayContent( type=PlayContentType.ALBUM, - content=(artist, album) + content=(albumartist, album) ) elif content_type == 'single': if isinstance(content, dict): @@ -635,7 +635,7 @@ def play_from_reader(self, content: Union[str, Dict[str, str]], content_type: st :param content: Content identifier, either: - string path for single/folder types - - dict with 'artist' and 'album' keys for album type + - dict with 'albumartist' and 'album' keys for album type :param content_type: Type of content ('single', 'album', 'folder') :param recursive: Add folder recursively (only used for folder type) :param second_swipe: Override default second swipe action for this reader: diff --git a/src/jukebox/components/rfid/cards/__init__.py b/src/jukebox/components/rfid/cards/__init__.py index 65e3ff8b9..1413f791e 100644 --- a/src/jukebox/components/rfid/cards/__init__.py +++ b/src/jukebox/components/rfid/cards/__init__.py @@ -17,7 +17,7 @@ import logging import time -from typing import (List, Dict, Optional) +from typing import List, Dict, Optional, Union import jukebox.utils as utils import jukebox.cfghandler import jukebox.plugs as plugs @@ -89,42 +89,48 @@ def delete_card(card_id: str, auto_save: bool = True): @plugs.register def register_card(card_id: str, cmd_alias: str, - args: Optional[List] = None, kwargs: Optional[Dict] = None, - ignore_card_removal_action: Optional[bool] = None, ignore_same_id_delay: Optional[bool] = None, - overwrite: bool = False, - auto_save: bool = True): - """Register a new card based on quick-selection - - If you are going to call this through the RPC it will get a little verbose - - **Example:** Registering a new card with ID *0009* for increment volume with a custom argument to inc_volume - (*here: 15*) and custom *ignore_same_id_delay value*:: - - plugin.call_ignore_errors('cards', 'register_card', - args=['0009', 'inc_volume'], - kwargs={'args': [15], 'ignore_same_id_delay': True, 'overwrite': True}) - - """ + args: Optional[Union[List, Dict]] = None, + kwargs: Optional[Dict] = None, + ignore_card_removal_action: Optional[bool] = None, + ignore_same_id_delay: Optional[bool] = None, + overwrite: bool = False, + auto_save: bool = True): + """Register a new card based on quick-selection""" if cmd_alias not in cmd_alias_definitions.keys(): msg = f"Unknown RPC command alias: '{cmd_alias}'" log.error(msg) raise KeyError(msg) + with cfg_cards: if not overwrite and card_id in cfg_cards.keys(): msg = f"Card already registered: '{card_id}'. Abort. (use overwrite=True to overrule)" log.error(msg) raise KeyError(msg) + cfg_cards[card_id] = {'alias': cmd_alias} - if args is not None: + + # For play_from_reader, expect a single dict of args + if cmd_alias == 'play_from_reader': + # Use either kwargs or args if it's a dict + if kwargs is not None: + cfg_cards[card_id]['args'] = kwargs + elif isinstance(args, dict): + cfg_cards[card_id]['args'] = args + else: + log.error(f"play_from_reader requires dict arguments, got: {type(args)}") + raise ValueError("play_from_reader requires dict arguments") + # For other commands, maintain list args support + elif args is not None: cfg_cards[card_id]['args'] = args - if kwargs is not None: - cfg_cards[card_id]['kwargs'] = args + if ignore_same_id_delay is not None: cfg_cards[card_id]['ignore_same_id_delay'] = ignore_same_id_delay if ignore_card_removal_action is not None: cfg_cards[card_id]['ignore_card_removal_action'] = ignore_card_removal_action + if auto_save: cfg_cards.save() + publishing.get_publisher().send(f'{plugs.loaded_as(__name__)}.database.has_changed', time.ctime()) diff --git a/src/jukebox/components/rpc_command_alias.py b/src/jukebox/components/rpc_command_alias.py index 5a7820733..48b76ea7c 100644 --- a/src/jukebox/components/rpc_command_alias.py +++ b/src/jukebox/components/rpc_command_alias.py @@ -12,12 +12,12 @@ # -------------------------------------------------------------- cmd_alias_definitions = { # Player - 'play_card': { - 'title': 'Play music folder triggered by card swipe', + 'play_from_reader': { + 'title': 'Play content triggered by card swipe, supports second swipe', 'note': "This function you'll want to use most often", 'package': 'player', 'plugin': 'ctrl', - 'method': 'play_card'}, + 'method': 'play_from_reader'}, 'play_album': { 'title': 'Play Album triggered by card swipe', 'note': "This function plays the content of a given album", diff --git a/src/webapp/public/locales/de/translation.json b/src/webapp/public/locales/de/translation.json index 1c6729415..42046e7b6 100644 --- a/src/webapp/public/locales/de/translation.json +++ b/src/webapp/public/locales/de/translation.json @@ -27,6 +27,7 @@ "next_song": "Nächster Song", "pause": "Pause", "play": "Abspielen", + "play_content": "Inhalte abspielen", "prev_song": "Vorheriger Song", "shuffle": "Zufallswiedergabe", "repeat": "Wiedergabe wiederholen", @@ -40,7 +41,7 @@ "label": "Aktionen", "placeholder": "Wähle eine Aktion aus", "actions": { - "play_music": "Musik abspielen", + "play_content": "Inhalte abspielen", "audio": "Audio & Lautstärke", "host": "System", "timers": "Timer", @@ -53,15 +54,15 @@ "label-full": "Gesamte Addresse (z.B. 192.168.1.53)", "label-short": "Letzter Quadrant (z.B. 53)" }, - "play-music": { + "play-content": { "commands": { - "play_album": "Ausgewähltes Album", - "play_folder": "Ausgewählter Ordner", - "play_single": "Ausgewählter Song" + "album": "Ausgewähltes Album", + "folder": "Ausgewählter Ordner", + "single": "Ausgewählter Song" }, - "button-label": "Musik auswählen", - "no-music-selected": "Es ist keine Musik ausgewählt.", - "loading-song-error": "Während des Ladens des Songs ist ein Fehler aufgetreten." + "button-label": "Inhalt auswählen", + "no-music-selected": "Es sind keine Inhalte ausgewählt.", + "loading-song-error": "Während des Ladens des Inhalts ist ein Fehler aufgetreten." }, "audio": { "repeat": { diff --git a/src/webapp/public/locales/en/translation.json b/src/webapp/public/locales/en/translation.json index 20a28bdac..358b6b1ec 100644 --- a/src/webapp/public/locales/en/translation.json +++ b/src/webapp/public/locales/en/translation.json @@ -27,6 +27,7 @@ "next_song": "Next song", "pause": "Pause", "play": "Play", + "play_content": "Play content", "prev_song": "Previous song", "shuffle": "Shuffle", "repeat": "Repeat", @@ -40,7 +41,7 @@ "label": "Actions", "placeholder": "Select an action", "actions": { - "play_music": "Play music", + "play_content": "Play content", "audio": "Audio & Volume", "host": "System", "timers": "Timers", @@ -53,15 +54,15 @@ "label-full": "Full address (e.g. 192.168.1.53)", "label-short": "Last quadrant (e.g. 53)" }, - "play-music": { + "play-content": { "commands": { - "play_album": "Selected album", - "play_folder": "Selected folder", - "play_single": "Selected song" + "album": "Selected album", + "folder": "Selected folder", + "single": "Selected song" }, - "button-label": "Select music", - "no-music-selected": "No music selected", - "loading-song-error": "An error occurred while loading song." + "button-label": "Select content", + "no-music-selected": "No content selected", + "loading-song-error": "An error occurred while loading the content." }, "audio": { "repeat": { diff --git a/src/webapp/src/commands/index.js b/src/webapp/src/commands/index.js index ffbc01f03..5a419e1f8 100644 --- a/src/webapp/src/commands/index.js +++ b/src/webapp/src/commands/index.js @@ -65,6 +65,24 @@ const commands = { method: 'play_content', argKeys: ['content', 'content_type', 'recursive'] }, + // play_single: { + // _package: 'player', + // plugin: 'ctrl', + // method: 'play_single', + // argKeys: ['song_url'] + // }, + // play_folder: { + // _package: 'player', + // plugin: 'ctrl', + // method: 'play_folder', + // argKeys: ['folder'] + // }, + // play_album: { + // _package: 'player', + // plugin: 'ctrl', + // method: 'play_album', + // argKeys: ['albumartist', 'album'] + // }, pause: { _package: 'player', plugin: 'ctrl', diff --git a/src/webapp/src/components/Cards/controls/actions-controls.js b/src/webapp/src/components/Cards/controls/actions-controls.js index 90afb56ad..b1577f25b 100644 --- a/src/webapp/src/components/Cards/controls/actions-controls.js +++ b/src/webapp/src/components/Cards/controls/actions-controls.js @@ -10,8 +10,8 @@ import { import CardsDeleteDialog from '../dialogs/delete'; import request from '../../../utils/request'; import { + cleanObject, getActionAndCommand, - getArgsValues } from '../utils'; const ActionsControls = ({ @@ -24,14 +24,14 @@ const ActionsControls = ({ const [deleteDialogOpen, setDeleteDialogOpen] = useState(false); const handleRegisterCard = async () => { - const args = getArgsValues(actionData); + const { args } = actionData.command || {}; const { command: cmd_alias } = getActionAndCommand(actionData); const kwargs = { card_id: cardId.toString(), - cmd_alias, + cmd_alias: cmd_alias === 'play_content' ? 'play_from_reader' : cmd_alias, overwrite: true, - ...(args.length && { args }), + args: cleanObject(args), }; const { error } = await request('registerCard', kwargs); diff --git a/src/webapp/src/components/Cards/controls/actions/play-music/index.js b/src/webapp/src/components/Cards/controls/actions/play-content/index.js similarity index 69% rename from src/webapp/src/components/Cards/controls/actions/play-music/index.js rename to src/webapp/src/components/Cards/controls/actions/play-content/index.js index 2e8d7332c..0e8fe8eae 100644 --- a/src/webapp/src/components/Cards/controls/actions/play-music/index.js +++ b/src/webapp/src/components/Cards/controls/actions/play-content/index.js @@ -20,17 +20,18 @@ import SelectedAlbum from './selected-album'; import SelectedFolder from './selected-folder'; import SelectedSingle from './selected-single'; -const SelectPlayMusic = ({ +const SelectPlayContent = ({ actionData, cardId, }) => { const { t } = useTranslation(); const navigate = useNavigate(); - const { command } = getActionAndCommand(actionData); + const { content_type } = actionData.command.args || {}; + const values = getArgsValues(actionData); - const selectMusic = () => { + const selectContent = () => { const searchParams = createSearchParams({ isSelecting: true, cardId @@ -44,30 +45,30 @@ const SelectPlayMusic = ({ return ( - {command && + {content_type && - {t(`cards.controls.actions.play-music.commands.${command}`)} + {t(`cards.controls.actions.play-content.commands.${content_type}`)} } - {command === 'play_album' && } - {command === 'play_folder' && } - {command === 'play_single' && } + {content_type === 'album' && } + {content_type === 'folder' && } + {content_type === 'single' && } ); }; -export default SelectPlayMusic; +export default SelectPlayContent; diff --git a/src/webapp/src/components/Cards/controls/actions/play-music/no-music-selected.js b/src/webapp/src/components/Cards/controls/actions/play-content/no-music-selected.js similarity index 80% rename from src/webapp/src/components/Cards/controls/actions/play-music/no-music-selected.js rename to src/webapp/src/components/Cards/controls/actions/play-content/no-music-selected.js index 90821d151..ce9478f14 100644 --- a/src/webapp/src/components/Cards/controls/actions/play-music/no-music-selected.js +++ b/src/webapp/src/components/Cards/controls/actions/play-content/no-music-selected.js @@ -8,7 +8,7 @@ const NoMusicSelected = () => { return ( - {t('cards.controls.actions.play-music.no-music-selected')} + {t('cards.controls.actions.play-content.no-music-selected')} ); } diff --git a/src/webapp/src/components/Cards/controls/actions/play-music/selected-album.js b/src/webapp/src/components/Cards/controls/actions/play-content/selected-album.js similarity index 88% rename from src/webapp/src/components/Cards/controls/actions/play-music/selected-album.js rename to src/webapp/src/components/Cards/controls/actions/play-content/selected-album.js index b0f5d2bc9..f7f323245 100644 --- a/src/webapp/src/components/Cards/controls/actions/play-music/selected-album.js +++ b/src/webapp/src/components/Cards/controls/actions/play-content/selected-album.js @@ -4,7 +4,7 @@ import { List } from '@mui/material'; import AlbumListItem from '../../../../Library/lists/albums/album-list/album-list-item' import NoMusicSelected from './no-music-selected'; -const SelectedAlbum = ({ values: [albumartist, album] }) => { +const SelectedAlbum = ({ values: [{ albumartist, album }] }) => { if (albumartist && album) { return ( diff --git a/src/webapp/src/components/Cards/controls/actions/play-music/selected-folder.js b/src/webapp/src/components/Cards/controls/actions/play-content/selected-folder.js similarity index 100% rename from src/webapp/src/components/Cards/controls/actions/play-music/selected-folder.js rename to src/webapp/src/components/Cards/controls/actions/play-content/selected-folder.js diff --git a/src/webapp/src/components/Cards/controls/actions/play-music/selected-single.js b/src/webapp/src/components/Cards/controls/actions/play-content/selected-single.js similarity index 95% rename from src/webapp/src/components/Cards/controls/actions/play-music/selected-single.js rename to src/webapp/src/components/Cards/controls/actions/play-content/selected-single.js index a7280c11e..a369e93b2 100644 --- a/src/webapp/src/components/Cards/controls/actions/play-music/selected-single.js +++ b/src/webapp/src/components/Cards/controls/actions/play-content/selected-single.js @@ -32,7 +32,7 @@ const SelectecSingle = ({ values: [song_url] }) => { if (error) { return ( - {t('cards.controls.actions.play-music.loading-song-error')} + {t('cards.controls.actions.play-content.loading-song-error')} ); } diff --git a/src/webapp/src/components/Cards/controls/controls-selector.js b/src/webapp/src/components/Cards/controls/controls-selector.js index eea2d5c67..1295bcfe7 100644 --- a/src/webapp/src/components/Cards/controls/controls-selector.js +++ b/src/webapp/src/components/Cards/controls/controls-selector.js @@ -7,7 +7,7 @@ import { } from '@mui/material'; import SelectCommandAliases from './select-command-aliases'; -import SelectPlayMusic from './actions/play-music'; +import SelectPlayContent from './actions/play-content'; import SelectTimers from './actions/timers'; import SelectAudio from './actions/audio'; import { buildActionData } from '../utils'; @@ -61,8 +61,8 @@ const ControlsSelector = ({ /> } - {actionData.action === 'play_music' && - diff --git a/src/webapp/src/components/Cards/edit.js b/src/webapp/src/components/Cards/edit.js index 6bcf11012..7ca5f803c 100644 --- a/src/webapp/src/components/Cards/edit.js +++ b/src/webapp/src/components/Cards/edit.js @@ -22,9 +22,11 @@ const CardsEdit = () => { if (result && result[cardId]) { const { action: { args }, - from_alias: command + from_alias, } = result[cardId]; + const command = from_alias === 'play_from_reader' ? 'play_content' : from_alias; + const action = findActionByCommand(command); const actionData = buildActionData(action, command, args); diff --git a/src/webapp/src/components/Cards/list.js b/src/webapp/src/components/Cards/list.js index 4e8211a27..020389b7f 100644 --- a/src/webapp/src/components/Cards/list.js +++ b/src/webapp/src/components/Cards/list.js @@ -13,6 +13,7 @@ import { } from '@mui/material'; import BookmarkIcon from '@mui/icons-material/Bookmark'; +import { printObject } from '../../utils/utils'; const CardsList = ({ cardsList }) => { const { t } = useTranslation(); @@ -28,10 +29,15 @@ const CardsList = ({ cardsList }) => { return }); - const description = cardsList[cardId].from_alias + const command = cardsList[cardId].from_alias === 'play_from_reader' ? 'play_content' : cardsList[cardId].from_alias; + + const description = command ? reject( isNil, - [cardsList[cardId].from_alias, cardsList[cardId].action.args] + [ + t(`cards.controls.command-selector.commands.${command}`), + printObject(cardsList[cardId].action.args) + ] ).join(', ') : cardsList[cardId].func diff --git a/src/webapp/src/components/Cards/register.js b/src/webapp/src/components/Cards/register.js index c4d3d32f0..848acb9db 100644 --- a/src/webapp/src/components/Cards/register.js +++ b/src/webapp/src/components/Cards/register.js @@ -17,6 +17,7 @@ const CardsRegister = () => { const [cardId, setCardId] = useState(undefined); const [actionData, setActionData] = useState(registerCard?.actionData || {}); + const [args, setArgs] = useState(registerCard?.args || {}); useEffect(() => { setState(state => (omit(['rfid.card_id'], state))); diff --git a/src/webapp/src/components/Cards/utils.js b/src/webapp/src/components/Cards/utils.js index 17eaede6f..0202b783e 100644 --- a/src/webapp/src/components/Cards/utils.js +++ b/src/webapp/src/components/Cards/utils.js @@ -1,6 +1,8 @@ import { isEmpty, + isNil, has, + reject, } from 'ramda'; import commands from '../../commands'; @@ -67,8 +69,11 @@ const getArgsValues = (actionData) => { ); }; +const cleanObject = reject(isNil); + export { buildActionData, + cleanObject, findActionByCommand, getActionAndCommand, getArgsValues, diff --git a/src/webapp/src/components/Library/lists/albums/song-list/index.js b/src/webapp/src/components/Library/lists/albums/song-list/index.js index 006ab791b..9fb87a841 100644 --- a/src/webapp/src/components/Library/lists/albums/song-list/index.js +++ b/src/webapp/src/components/Library/lists/albums/song-list/index.js @@ -18,7 +18,7 @@ import SongListItem from './song-list-item'; const SongList = ({ isSelecting, - registerMusicToCard, + registerContentToCard, }) => { const { t } = useTranslation(); const { artist, album } = useParams(); @@ -59,7 +59,7 @@ const SongList = ({ albumartist={decodeURIComponent(artist)} disabled={songs.length === 0} isSelecting={isSelecting} - registerMusicToCard={registerMusicToCard} + registerContentToCard={registerContentToCard} /> )} diff --git a/src/webapp/src/components/Library/lists/albums/song-list/song-list-controls.js b/src/webapp/src/components/Library/lists/albums/song-list/song-list-controls.js index 18b240382..a3db788e0 100644 --- a/src/webapp/src/components/Library/lists/albums/song-list/song-list-controls.js +++ b/src/webapp/src/components/Library/lists/albums/song-list/song-list-controls.js @@ -14,18 +14,17 @@ const SongListControls = ({ albumartist, album, disabled, - registerMusicToCard, + registerContentToCard, isSelecting }) => { const { t } = useTranslation(); - const command = 'play_album'; const playAlbum = () => ( - request('play_content', { content: { "artist": albumartist, album }, content_type: 'album' }) + request('play_content', { content: { albumartist, album }, content_type: 'album' }) ); const registerAlbumToCard = () => ( - registerMusicToCard(command, { albumartist, album }) + registerContentToCard('play_content', { content: { albumartist, album }, content_type: 'album' }) ); return ( diff --git a/src/webapp/src/components/Library/lists/albums/song-list/song-list-item.js b/src/webapp/src/components/Library/lists/albums/song-list/song-list-item.js index 4b76a984c..e9edea8eb 100644 --- a/src/webapp/src/components/Library/lists/albums/song-list/song-list-item.js +++ b/src/webapp/src/components/Library/lists/albums/song-list/song-list-item.js @@ -12,12 +12,11 @@ import request from '../../../../../utils/request' const SongListItem = ({ isSelecting, - registerMusicToCard, + registerContentToCard, song, }) => { const { t } = useTranslation(); - const command = 'play_single'; const { artist, duration, @@ -29,15 +28,15 @@ const SongListItem = ({ request('play_content', { content: file, content_type: 'single' }) } - const registerSongToCard = () => ( - registerMusicToCard(command, { song_url: file }) + const registerSingleToCard = () => ( + registerContentToCard('play_content', { content: file, content_type: 'single' }) ); return ( (isSelecting ? registerSongToCard() : playSingle())} + onClick={() => (isSelecting ? registerSingleToCard() : playSingle())} > { const { t } = useTranslation(); const { type, name, relpath } = folder; @@ -34,8 +34,8 @@ const FolderListItem = ({ const registerItemToCard = () => { switch(type) { - case 'directory': return registerMusicToCard('play_folder', { folder: relpath, recursive: true }); - case 'file': return registerMusicToCard('play_single', { song_url: relpath }); + case 'directory': return registerContentToCard('play_content', { content: relpath, content_type: 'folder', recursive: true }); + case 'file': return registerContentToCard('play_content', { content: relpath, content_type: 'single' }); // TODO: Add missing Podcast // TODO: Add missing Stream default: return; diff --git a/src/webapp/src/components/Library/lists/folders/folder-list.js b/src/webapp/src/components/Library/lists/folders/folder-list.js index 3222e4234..2c2f90086 100644 --- a/src/webapp/src/components/Library/lists/folders/folder-list.js +++ b/src/webapp/src/components/Library/lists/folders/folder-list.js @@ -17,7 +17,7 @@ const FolderList = ({ dir, folders, isSelecting, - registerMusicToCard, + registerContentToCard, }) => { const { t } = useTranslation(); @@ -47,7 +47,7 @@ const FolderList = ({ key={key} folder={folder} isSelecting={isSelecting} - registerMusicToCard={registerMusicToCard} + registerContentToCard={registerContentToCard} /> )} diff --git a/src/webapp/src/components/Library/lists/folders/index.js b/src/webapp/src/components/Library/lists/folders/index.js index fa0532589..ce279cebd 100644 --- a/src/webapp/src/components/Library/lists/folders/index.js +++ b/src/webapp/src/components/Library/lists/folders/index.js @@ -15,7 +15,7 @@ import { ROOT_DIR } from '../../../../config'; const Folders = ({ musicFilter, isSelecting, - registerMusicToCard, + registerContentToCard, }) => { const { t } = useTranslation(); const { dir = ROOT_DIR } = useParams(); @@ -60,7 +60,7 @@ const Folders = ({ dir={dir} folders={filteredFolders} isSelecting={isSelecting} - registerMusicToCard={registerMusicToCard} + registerContentToCard={registerContentToCard} /> ); }; diff --git a/src/webapp/src/components/Library/lists/index.js b/src/webapp/src/components/Library/lists/index.js index e2b7a2d46..7390eb451 100644 --- a/src/webapp/src/components/Library/lists/index.js +++ b/src/webapp/src/components/Library/lists/index.js @@ -32,8 +32,8 @@ const LibraryLists = () => { setMusicFilter(event.target.value); }; - const registerMusicToCard = (command, args) => { - const actionData = buildActionData('play_music', command, args); + const registerContentToCard = (command, args) => { + const actionData = buildActionData('play_content', command, args); const state = { registerCard: { actionData, @@ -71,7 +71,7 @@ const LibraryLists = () => { element={ } exact @@ -86,7 +86,7 @@ const LibraryLists = () => { } /> diff --git a/src/webapp/src/config.js b/src/webapp/src/config.js index 46a6ec1df..9d5f5d372 100644 --- a/src/webapp/src/config.js +++ b/src/webapp/src/config.js @@ -28,11 +28,9 @@ const ROOT_DIR = './'; const JUKEBOX_ACTIONS_MAP = { // Command Aliases // Player - play_music: { + play_content: { commands: { - play_album: {}, - play_folder: {}, - play_single: {}, + play_content: {}, } }, diff --git a/src/webapp/src/utils/utils.js b/src/webapp/src/utils/utils.js index 170a8994f..5b217e9fb 100644 --- a/src/webapp/src/utils/utils.js +++ b/src/webapp/src/utils/utils.js @@ -24,10 +24,21 @@ const flatByAlbum = (albumList, { albumartist, album }) => { return [...albumList, ...list]; }; +const printObject = (obj) => { + return Object.entries(obj) + .map(([key, value]) => { + if (value && typeof value === 'object') { + return `${key}: ${printObject(value)}`; + } + return `${key}: ${value}`; + }) + .join(', '); +}; export { flatByAlbum, pluginIsLoaded, + printObject, progressToTime, timeToProgress, toHHMMSS,