doctorfree / MusicPlayerPlus

Featureful ncurses based MPD client inspired by ncmpc with integration for Beets, spectrum visualization,Bandcamp/Soundcloud, asciimatics, cantata, and more
https://musicplayerplus.dev
MIT License
77 stars 1 forks source link

[FEATURE] Merge any pre-existing cava configuration into the initial mppcava configuration #6

Closed doctorfree closed 2 years ago

doctorfree commented 2 years ago

MusicPlayerPlus includes an enhanced fork of the Cava spectrum visualizer. If the user has previously installed and configured Cava then merge any user customization of Cava into the mppcava configuration, preserving user preferences.

doctorfree commented 2 years ago

One approach with the Cava config would be to use crudini.py to perform a merge as the format of the Cava config file is INI:

/usr/share/musicplayerplus/scripts/crudini.py --merge $HOME/.config/mppcava/config < $HOME/.config/cava/config

Crudini does a very good job with merges. The difficulty with this approach is we do not want to overwrite some of the mppcava configuration. The method and source configuration parameters need to conform to MusicPlayerPlus expectations. For example, if method = fifo then source = $HOME/.config/mpd/mpd.fifo

doctorfree commented 2 years ago

Initial crack at merging previously set cava configuration with mppcava configuration:

#!/bin/bash
#
# set_prev_cava.sh - merge previously configured cava user preferences
#                       with $HOME/.config/mppcava/config

USERCONF="${HOME}/.config"
CAV_USER_CONF="${USERCONF}/cava/config"
MPP_USER_CONF="${USERCONF}/mppcava/config"
SCPTDIR="/usr/share/musicplayerplus/scripts"

if [ -x "${SCPTDIR}/crudini.py" ]
then
  CRUDINI="${SCPTDIR}/crudini.py"
else
  have_crudini=`type -p crudini`
  if [ "${have_crudini}" ]
  then
    CRUDINI=crudini
  else
    CRUDINI=
  fi
fi

[ -f "${CAV_USER_CONF}" ] && [ -f "${MPP_USER_CONF}" ] && [ "${CRUDINI}" ] && {
  mth=`${CRUDINI} --get ${MPP_USER_CONF} input method`
  src=`${CRUDINI} --get ${MPP_USER_CONF} input source`
  ${CRUDINI} --merge ${MPP_USER_CONF} < ${CAV_USER_CONF}
  ${CRUDINI} --set ${MPP_USER_CONF} input method ${mth}
  ${CRUDINI} --set ${MPP_USER_CONF} input source ${src}
}

exit 0
doctorfree commented 2 years ago

This seems to work. Closing.