Home of the Squeezebox™ & Transporter® network music players.
Results 1 to 10 of 10
  1. #1
    Senior Member agillis's Avatar
    Join Date
    Nov 2008
    Posts
    811

    API to install Plug-in

    I want to programmatically install a plug-in. I don't think there is a was to do this using the CLI. Is this possible?
    rip, tag, get cover art… All you do is insert the CD!
    http://vortexbox.org

    agillis
    Lead Developer VortexBox

  2. #2
    Senior Member
    Join Date
    Apr 2005
    Posts
    6,932
    Quote Originally Posted by agillis View Post
    I want to programmatically install a plug-in. I don't think there is a was to do this using the CLI. Is this possible?
    Not from cli. From a perl plugin you would be able to call the downloader to install another plugin, but this is not exposed via cli.

  3. #3
    Senior Member agillis's Avatar
    Join Date
    Nov 2008
    Posts
    811
    OK thanks. This is on linux. Could I somehow just call the perl installer code from a script.

    I want it to work like this. I copy a plugin to /usr/share/squeezeboxserver/Plugins. Then I run a script of some kind and restart LMS. The plugin appears as if I had installed it through the plugins web GUI.
    rip, tag, get cover art… All you do is insert the CD!
    http://vortexbox.org

    agillis
    Lead Developer VortexBox

  4. #4
    Senior Member erland's Avatar
    Join Date
    Dec 2005
    Location
    Sweden
    Posts
    10,313
    Quote Originally Posted by agillis View Post
    OK thanks. This is on linux. Could I somehow just call the perl installer code from a script.

    I want it to work like this. I copy a plugin to /usr/share/squeezeboxserver/Plugins. Then I run a script of some kind and restart LMS. The plugin appears as if I had installed it through the plugins web GUI.
    Do you want to be able to upgrade the plugins via the LMS GUI later ?
    Do you want the plugins to be downloaded or will you handle the download and copying ?

    It's always possible to manually install a plugin by download and copy it to the "Plugins" folder but manually installed plugins will not be upgradable via the GUI (if I remember correctly).
    Only the plugins installed under <Cache>/InstalledPlugins/ will be possible to upgrade via the LMS GUI.

    Theoretically I think you can copy a plugin also to <Cache>/InstalledPlugins/ but I'm not sure if you also need to change some state for them to appear as activated after LMS is restarted.
    Erland Isaksson (My homepage)
    (Developer of many plugins/applets (both free and commercial).
    If you like to encourage future presence on this forum and/or third party plugin/applet development, consider purchasing some plugins)
    You may also want to try my Android apps Squeeze Display and RSS Photo Show
    Interested in the future of music streaming ? ickStream - A world of music at your fingertips.

  5. #5
    Senior Member gharris999's Avatar
    Join Date
    Apr 2005
    Location
    Santa Fe, NM
    Posts
    3,299
    Quote Originally Posted by agillis View Post
    OK thanks. This is on linux. Could I somehow just call the perl installer code from a script.

    I want it to work like this. I copy a plugin to /usr/share/squeezeboxserver/Plugins. Then I run a script of some kind and restart LMS. The plugin appears as if I had installed it through the plugins web GUI.
    A minor point: /usr/share/squeezeboxserver/Plugins is frequently a symlink. You can get the real path via:

    MANUAL_PLUGINS=$(readlink -f '/usr/share/squeezeboxserver/Plugins')
    Last edited by gharris999; 2012-07-14 at 10:50.

  6. #6
    Senior Member gharris999's Avatar
    Join Date
    Apr 2005
    Location
    Santa Fe, NM
    Posts
    3,299
    Quote Originally Posted by agillis View Post
    OK thanks. This is on linux. Could I somehow just call the perl installer code from a script.

    I want it to work like this. I copy a plugin to /usr/share/squeezeboxserver/Plugins. Then I run a script of some kind and restart LMS. The plugin appears as if I had installed it through the plugins web GUI.
    I think you might be able to do this completely from a bash script. You'd need to:

    Download the plugin zip file to: /var/squeezeboxserver/cache/DownloadedPlugins (using wget or curl).

    Fixup entries in /var/squeezeboxserver/prefs/plugin/extensions.prefs (using sed) with:

    _ts_plugin: with a new epoch time, i.e. $(date --utc '+%s') like this:

    FIXFILE='/var/squeezeboxserver/prefs/plugin/extensions.prefs'
    NEWTIME="$(date --utc '+%s')"
    sed -i -e "s/^_ts_plugin: .*\$/_ts_plugin: ${NEWTIME}/" "$FIXFILE"

    Add the Name of the plugin to the plugin: section, i.e.

    plugin:
    NewPluginName: 1

    ..via:

    sed '/^plugin:/a \ \ NewPluginName: 1' "$FIXFILE"


    Add entries in /var/squeezeboxserver/prefs/plugin/state.prefs (via simple echoing):

    NewPluginName: needs-install

    via:

    echo "NewPluginName: needs-install" >> /var/squeezeboxserver/prefs/plugin/state.prefs

    ..and.. add a:

    _ts_NewPluginName: $(date --utc '+%s')

    via:

    echo "_ts_NewPluginName: $(date --utc '+%s')" >> /var/squeezeboxserver/prefs/plugin/state.prefs


    ..and then restart the lms/sbs service.

    I think that ought to fake-out lms into installing your plugin.
    Last edited by gharris999; 2012-07-14 at 11:16.

  7. #7
    Senior Member gharris999's Avatar
    Join Date
    Apr 2005
    Location
    Santa Fe, NM
    Posts
    3,299
    This bash script should do exactly what you want. It downloads the plugin zip file and then convinces LMS to install the plugin via the extension down loader when the LMS service restarts. Thus, the plugin is, as Erland says, "upgradable via the GUI."

    As an example, this script will download Michael's MusicInfoSCR plugin and then convinces LMS to install it on restart.

    lms_install_plugin.sh:
    Code:
    #!/bin/bash
    # Bash script to download and install a Logitech Media Server plugin..
    
    LIBDIR='/var/lib/squeezeboxserver'
    
    download_plugin(){
    	NAME="$1"
    	URL="$2"
    	
    	TARGETDIR="${LIBDIR}/cache/DownloadedPlugins"
    	TARGETFILE="${TARGETDIR}/${NAME}.zip"
    	
    	TMPFILE=$(tempfile)
    	
    	echo "Downloading ${URL}"
    	
    	CURL_OPTS=' --connect-timeout 30 --progress-bar --max-time 120'
    	
    	curl $CURL_OPTS --output "$TMPFILE" "$URL"
    	
    	# Error downloading?
    	if [ $? -gt 0 ]; then
    		echo "Error: could not download ${URL}"
    		rm "$TMPFILE"
    		exit 1
    	fi
    	
    	# Put the file in place..
    	mv -f "$TMPFILE" "$TARGETFILE"
    	
    	if [ ! -f "$TARGETFILE" ]; then
    		echo "Error: could not create ${TARGETFILE}."
    		rm "$TMPFILE"
    		exit 1
    	fi
    	
    	# Fix the permissions
    	USER=$(stat -c %U "$TARGETDIR")
    	GROUP=$(id -ng $USER)
    	chown "${USER}:${GROUP}" "$TARGETFILE"
    	
    	if [ -f "$TARGETFILE" ]; then
    		echo "${TARGETFILE} downloaded successfully!"
    	else
    		echo "ERROR: ${TARGETFILE} NOT downloaded!"
    		exit 1
    	fi
    	
    	return 0
    }
    
    fix_prefs(){
    	NAME="$1"
    	
    	#Fixup extensions.prefs
    	FIXFILE="${LIBDIR}/prefs/plugin/extensions.prefs"
    	
    	echo "Fixing up ${FIXFILE}.."
    
    	# make a backup of the prefs file..
    	cp -f "$FIXFILE" "${FIXFILE}.bak"
    
    	# Fixup the _ts_plugin: entry with current epoch time
    	NEWTIME="$(date --utc '+%s')"
    	sed -i -e "s/^_ts_plugin:.*\$/_ts_plugin: ${NEWTIME}/" "$FIXFILE"
    	
    	# Delete plugin:{} if no plugins have been previously installed..
    	sed -i -e "s/^plugin:.*\$/plugin:/" "$FIXFILE"
    	
    	# Delete any previous reference to the Plugin..
    	sed -i "/ ${NAME}: /d" "$FIXFILE"
    	sed -i "/_ts_${NAME}: /d" "$FIXFILE"
    
    	# Add the plugin name to the plugin: section..
    	sed -i "/^plugin:/a \ \ ${NAME}: 1" "$FIXFILE"
    	
    	echo "Fixes:"
    	cat "$FIXFILE" | egrep '^_ts_plugin: .*$'
    	cat "$FIXFILE" | egrep "$NAME"
    
    	# Fixup state.prefs
    	FIXFILE="${LIBDIR}/prefs/plugin/state.prefs"
    
    	echo "Fixing up ${FIXFILE}.."
    
    	cp -f "$FIXFILE" "${FIXFILE}.bak"
    
    	# Delete any previous reference to the Plugin..
    	sed -i "/^${NAME}:.*\$/d" "$FIXFILE"
    	sed -i "/^_ts_${NAME}:.*\$/d" "$FIXFILE"
    	
    	# Add our 'needs-install' flag
    	
    sed -i "1,/^_ts_.*\$/ {/^_ts_.*\$/i\
    ${NAME}: needs-install
    }" "$FIXFILE"
    	
    	
    	# Add our _ts_NewPluginName date
    
    sed -i "1,/^_ts_.*\$/ {/^_ts_.*\$/a\
    _ts_${NAME}: ${NEWTIME}
    }" "$FIXFILE"
    	
    	echo "Fixes:"
    	cat "$FIXFILE" | egrep "$NAME"
    }
    
    
    stop_service(){
    	service squeezeboxserver stop
    }
    
    start_service(){
    	service squeezeboxserver start
    }
    
    # From: http://svn.slimdevices.com/slim/vendor/plugins/repo.xml?revision=33979&view=markup
    
    #<plugin name="MusicInfoSCR" creator="Michael Herger" email="slim@herger.net" link="http://www.herger.net/MusicInfoSCR/" maxTarget="*" minTarget="7.0" sha="8a746410d2b7298ce08b88bfd07df947a0fd6e06" url="http://www.herger.net/_data/MusicInfoSCR-4.4.7.zip" version="4.4.7">
    #	<desc lang="EN">The Music Information Screen plugin allows customization of the player's Now Playing screen and other elements.</desc>
    #	<desc lang="DE">Das Musik-Informations Plugin erlaubt es, den Bildschirm weitgehend selber zu gestalten.</desc>
    #	<title lang="EN">Music Information Screen</title>
    #</plugin>
    
    PLUGIN_NAME='MusicInfoSCR'
    PLUGIN_URL='http://www.herger.net/_data/MusicInfoSCR-4.4.7.zip'
    
    stop_service
    
    download_plugin "$PLUGIN_NAME" "$PLUGIN_URL"
    
    fix_prefs "$PLUGIN_NAME"
    
    sleep 10
    
    start_service
    
    sleep 10
    
    CHECK_DIR="${LIBDIR}/cache/InstalledPlugins/Plugins/${PLUGIN_NAME}"
    
    if [ -d "$CHECK_DIR" ]; then
    	echo "${PLUGIN_NAME} installed successfully!"
    else
    	echo "ERROR: ${PLUGIN_NAME} NOT installed!"
    fi
    You may want to flesh that script out a bit and write your own prefs file for the newly installed plugin.
    Last edited by gharris999; 2012-07-16 at 11:52. Reason: Fix from agillis

  8. #8
    Senior Member agillis's Avatar
    Join Date
    Nov 2008
    Posts
    811
    Wow! Thanks for doing all that coding. The only problem is I can't get it to work! It runs with no errors and I can see the plug-in is installed in /var/lib/squeezeboxserver/cache/InstalledPlugins/Plugins/PlayWMA/ but it doesn't appear as installed. This is the plug-in I'm trying to use.

    PLUGIN_NAME='PlayWMA'
    PLUGIN_URL='http://bpaplugins.googlecode.com/files/PlayWMA-v100.ZIP'

    I'll keep hacking at it and see if I can figure out the problem.
    rip, tag, get cover art… All you do is insert the CD!
    http://vortexbox.org

    agillis
    Lead Developer VortexBox

  9. #9
    Senior Member agillis's Avatar
    Join Date
    Nov 2008
    Posts
    811
    I think I found the problem. When there are no plug-ins installed the line in extensions.prefs is "plugin: {}" but it needs to be changed to "plugin:" once plug-ins are installed. I added this line to fix it.

    sed -i -e "s/^plugin:.*\$/plugin:/" "$FIXFILE"

    Thanks again for all your work on this!
    Last edited by agillis; 2012-07-16 at 11:13.
    rip, tag, get cover art… All you do is insert the CD!
    http://vortexbox.org

    agillis
    Lead Developer VortexBox

  10. #10
    Senior Member gharris999's Avatar
    Join Date
    Apr 2005
    Location
    Santa Fe, NM
    Posts
    3,299
    Quote Originally Posted by agillis View Post
    I think I found the problem. When there are no plug-ins installed the line in extensions.prefs is "plugin: {}" but it needs to be changed to "plugin:" once plug-ins are installed. I added this line to fix it.

    sed -i -e "s/^plugin:.*\$/plugin:/" "$FIXFILE"

    Thanks again for all your work on this!
    Heh. That makes sense.

    My apologies to all the perl coders who are getting queasy watching us hack on prefs files from bash.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •