diff --git a/packages/addons/service/snapclient/changelog.txt b/packages/addons/service/snapclient/changelog.txt new file mode 100644 index 0000000000..ffbebe8438 --- /dev/null +++ b/packages/addons/service/snapclient/changelog.txt @@ -0,0 +1,2 @@ +100 +- Initial addon diff --git a/packages/addons/service/snapclient/icon/icon.png b/packages/addons/service/snapclient/icon/icon.png new file mode 100644 index 0000000000..b764a02395 Binary files /dev/null and b/packages/addons/service/snapclient/icon/icon.png differ diff --git a/packages/addons/service/snapclient/package.mk b/packages/addons/service/snapclient/package.mk new file mode 100644 index 0000000000..f152b1d6ad --- /dev/null +++ b/packages/addons/service/snapclient/package.mk @@ -0,0 +1,47 @@ +################################################################################ +# This file is part of LibreELEC - https://libreelec.tv +# Copyright (C) 2018-present Team LibreELEC +# +# LibreELEC is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# LibreELEC is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with LibreELEC. If not, see . +################################################################################ + +PKG_NAME="snapclient" +PKG_VERSION="0.13.0" +PKG_REV="100" +PKG_ARCH="any" +PKG_LICENSE="GPLv3" +PKG_DEPENDS_TARGET="toolchain snapcast" +PKG_SECTION="service" +PKG_SHORTDESC="Snapclient: Synchronous multi-room audio client" +PKG_LONGDESC="Snapclient ($PKG_VERSION) is a Snapcast client. Snapcast is a multi-room client-server audio system, where all clients are time synchronized with the server to play perfectly synced audioplays." +PKG_AUTORECONF="no" + +PKG_IS_ADDON="yes" +PKG_ADDON_NAME="Snapclient" +PKG_ADDON_TYPE="xbmc.service.library" +PKG_MAINTAINER="Anton Voyl (awiouy)" + +make_target() { + : +} + +makeinstall_target() { + : +} + +addon() { + mkdir -p "$ADDON_BUILD/$PKG_ADDON_ID/bin" + cp "$(get_build_dir snapcast)/client/snapclient" \ + "$ADDON_BUILD/$PKG_ADDON_ID/bin" +} diff --git a/packages/addons/service/snapclient/source/addon.py b/packages/addons/service/snapclient/source/addon.py new file mode 100644 index 0000000000..4775b5397b --- /dev/null +++ b/packages/addons/service/snapclient/source/addon.py @@ -0,0 +1,40 @@ +################################################################################ +# This file is part of LibreELEC - https://libreelec.tv +# Copyright (C) 2018-present Team LibreELEC +# +# LibreELEC is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# LibreELEC is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with LibreELEC. If not, see . +################################################################################ + +import os.path +import subprocess +import xbmcaddon +import xbmcgui + +SNAPCLIENT = os.path.join( + xbmcaddon.Addon().getAddonInfo('path'), 'bin', 'snapclient') + +card = '' +cards = [] +lines = subprocess.check_output([SNAPCLIENT, '--list']).splitlines() + +for line in lines: + if line != '': + card = card + ' ' + line + else: + cards.append(card) + card = '' + +dialog = xbmcgui.Dialog() +dialog.select(xbmcaddon.Addon().getLocalizedString(30015), cards) +del dialog diff --git a/packages/addons/service/snapclient/source/bin/snapclient.start b/packages/addons/service/snapclient/source/bin/snapclient.start new file mode 100644 index 0000000000..5901fb9295 --- /dev/null +++ b/packages/addons/service/snapclient/source/bin/snapclient.start @@ -0,0 +1,51 @@ +#!/bin/sh +################################################################################ +# This file is part of LibreELEC - https://libreelec.tv +# Copyright (C) 2018-present Team LibreELEC +# +# LibreELEC is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# LibreELEC is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with LibreELEC. If not, see . +################################################################################ + +. /etc/profile +oe_setup_addon service.snapclient + +. /etc/os-release +case "$LIBREELEC_ARCH" in + RPi*.arm) + if [ "$sc_a" == "true" ]; then + ALSA="/proc/asound/ALSA" + if [ ! -e "$ALSA" ]; then + echo "Starting Raspberry Pi onboard audio" + dtparam audio=on + sleep 1 + fi + if [ -e "$ALSA" ]; then + echo "Setting Raspberry Pi onboard audio playback route" + index="$(readlink $ALSA)" + index="${index##*card}" + amixer -c "$index" cset name="PCM Playback Route" "$sc_r" + fi + fi + ;; +esac + +[ -n "$sc_h" ] && sc_H="--hostID $sc_h" +[ -n "$sc_s" ] && sc_S="--soundcard $sc_s" + +snapclient \ + --daemon "$sc_n" \ + $sc_H \ + --latency "$sc_l" \ + --port "$sc_p" \ + $sc_S diff --git a/packages/addons/service/snapclient/source/default.py b/packages/addons/service/snapclient/source/default.py new file mode 100644 index 0000000000..bfdd4981a5 --- /dev/null +++ b/packages/addons/service/snapclient/source/default.py @@ -0,0 +1,70 @@ +################################################################################ +# This file is part of LibreELEC - https://libreelec.tv +# Copyright (C) 2018-present Team LibreELEC +# +# LibreELEC is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# LibreELEC is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with LibreELEC. If not, see . +################################################################################ + +import subprocess +import xbmc +import xbmcaddon + + +def systemctl(command): + subprocess.call( + ['systemctl', command, xbmcaddon.Addon().getAddonInfo('id')]) + + +class Monitor(xbmc.Monitor): + + def __init__(self, *args, **kwargs): + xbmc.Monitor.__init__(self) + self.player = Player() + + def onSettingsChanged(self): + self.player.start('restart') + + +class Player(xbmc.Player): + + def __init__(self): + super(Player, self).__init__(self) + self.start('start') + + def onPlayBackEnded(self): + if xbmcaddon.Addon().getSetting('sc_k') == 'true': + xbmc.sleep(500) + if not self.isPlaying(): + systemctl('start') + + def onPlayBackStarted(self): + if xbmcaddon.Addon().getSetting('sc_k') == 'true': + systemctl('stop') + + def onPlayBackStopped(self): + if xbmcaddon.Addon().getSetting('sc_k') == 'true': + systemctl('start') + + def start(self, command): + if xbmcaddon.Addon().getSetting('sc_k') == 'true': + if self.isPlaying(): + systemctl('stop') + else: + systemctl(command) + else: + systemctl(command) + + +if __name__ == '__main__': + Monitor().waitForAbort() diff --git a/packages/addons/service/snapclient/source/resources/language/English/strings.po b/packages/addons/service/snapclient/source/resources/language/English/strings.po new file mode 100644 index 0000000000..12eb6aa994 --- /dev/null +++ b/packages/addons/service/snapclient/source/resources/language/English/strings.po @@ -0,0 +1,70 @@ +# Kodi Media Center language file +# Addon Name: snapclient +# Addon id: service.snapclient +# Addon Provider: Team LibreELEC +msgid "" +msgstr "" + +msgctxt "#30000" +msgid "Snapclient" +msgstr "" + +msgctxt "#30001" +msgid "List sound cards" +msgstr "" + +msgctxt "#30002" +msgid "Sound card" +msgstr "" + +msgctxt "#30003" +msgid "Host ID" +msgstr "" + +msgctxt "#30004" +msgid "Port" +msgstr "" + +msgctxt "#30005" +msgid "Priority" +msgstr "" + +msgctxt "#30006" +msgid "Latency" +msgstr "" + +msgctxt "#30007" +msgid "Kodi" +msgstr "" + +msgctxt "#30008" +msgid "Stop Snapclient when Kodi plays" +msgstr "" + +msgctxt "#30009" +msgid "Rasperry Pi" +msgstr "" + +msgctxt "#30010" +msgid "Manage onboard audio" +msgstr "" + +msgctxt "#30011" +msgid "Onboard audio playback route" +msgstr "" + +msgctxt "#30012" +msgid "Autodetect" +msgstr "" + +msgctxt "#30013" +msgid "Jack" +msgstr "" + +msgctxt "#30014" +msgid "HDMI" +msgstr "" + +msgctxt "#30015" +msgid "Available sound cards" +msgstr "" diff --git a/packages/addons/service/snapclient/source/resources/settings.xml b/packages/addons/service/snapclient/source/resources/settings.xml new file mode 100644 index 0000000000..fdbdf00ddf --- /dev/null +++ b/packages/addons/service/snapclient/source/resources/settings.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/packages/addons/service/snapclient/source/settings-default.xml b/packages/addons/service/snapclient/source/settings-default.xml new file mode 100644 index 0000000000..21bb0b094a --- /dev/null +++ b/packages/addons/service/snapclient/source/settings-default.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/packages/addons/service/snapclient/source/system.d/service.snapclient.service b/packages/addons/service/snapclient/source/system.d/service.snapclient.service new file mode 100644 index 0000000000..3d472614c6 --- /dev/null +++ b/packages/addons/service/snapclient/source/system.d/service.snapclient.service @@ -0,0 +1,11 @@ +[Unit] +Description=Snapclient +After=kodi.service network-online.target sound.target +Requires=kodi.service network-online.target sound.target + +[Service] +Type=forking +ExecStart=/bin/sh /storage/.kodi/addons/service.snapclient/bin/snapclient.start + +[Install] +WantedBy=kodi.target