Skip to content

Commit

Permalink
feat #23, #24: librespot-java launcher script and snapserver template…
Browse files Browse the repository at this point in the history
… with crossfade

FIXME: do something about the default config.toml
  • Loading branch information
markferry committed Jun 28, 2023
1 parent 1e2d6d7 commit 78d7a62
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 2 deletions.
9 changes: 9 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"mpd_port": "6606"
},
"spotify": {
"crossfade_ms": "0",
"zeroconf": "39806"
},
"snapcast": {
Expand All @@ -59,6 +60,7 @@
"volume": 50
},
"spotify": {
"crossfade_ms": "0",
"zeroconf": "39807"
},
"streams": ["spotify", "airplay", "iris"]
Expand All @@ -82,6 +84,7 @@
"volume": 75
},
"spotify": {
"crossfade_ms": "0",
"zeroconf": "39808"
},
"announcer_streams": ["announcer"],
Expand All @@ -105,6 +108,7 @@
"volume": 75
},
"spotify": {
"crossfade_ms": "2000",
"zeroconf": "39809"
},
"announcer_streams": ["announcer"],
Expand All @@ -125,6 +129,7 @@
"volume": 80
},
"spotify": {
"crossfade_ms": "2000",
"zeroconf": "39810"
},
"announcer_streams": ["announcer"],
Expand All @@ -145,6 +150,7 @@
"volume": 65
},
"spotify": {
"crossfade_ms": "0",
"zeroconf": "39811"
},
"streams": ["spotify", "airplay", "iris"],
Expand All @@ -166,6 +172,7 @@
"volume": 80
},
"spotify": {
"crossfade_ms": "0",
"zeroconf": "39812"
},
"streams": ["spotify", "airplay", "iris"]
Expand All @@ -186,6 +193,7 @@
"volume": 90
},
"spotify": {
"crossfade_ms": "0",
"zeroconf": "39813"
},
"announcer_streams": ["announcer"],
Expand Down Expand Up @@ -222,6 +230,7 @@
"opts": ""
},
"spotify": {
"crossfade_ms": "2000",
"zeroconf": "39801"
},
"streams": ["spotify", "airplay", "iris"],
Expand Down
86 changes: 86 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
deviceId = "" ### Device ID (40 chars, leave empty for random) ###
clientToken = "" ### Client Token (168 bytes Base64 encoded) ###
deviceName = "librespot-java" ### Device name ###
deviceType = "SPEAKER" ### Device type (COMPUTER, TABLET, SMARTPHONE, SPEAKER, TV, AVR, STB, AUDIO_DONGLE, GAME_CONSOLE, CAST_VIDEO, CAST_AUDIO, AUTOMOBILE, WEARABLE, UNKNOWN_SPOTIFY, CAR_THING, UNKNOWN) ###
preferredLocale = "en" ### Preferred locale ###
logLevel = "TRACE" ### Log level (OFF, FATAL, ERROR, WARN, INFO, DEBUG, TRACE, ALL) ###

[auth] ### Authentication ###
strategy = "ZEROCONF" # Strategy (USER_PASS, ZEROCONF, BLOB, FACEBOOK, STORED)
username = "" # Spotify username (BLOB, USER_PASS only)
password = "" # Spotify password (USER_PASS only)
blob = "" # Spotify authentication blob Base64-encoded (BLOB only)
storeCredentials = false # Whether to store reusable credentials on disk (not a plain password)
credentialsFile = "credentials.json" # Credentials file (JSON)

[zeroconf] ### Zeroconf ###
listenPort = -1 # Listen on this TCP port (`-1` for random)
listenAll = true # Listen on all interfaces (overrides `zeroconf.interfaces`)
interfaces = "" # Listen on these interfaces (comma separated list of names)

[cache] ### Cache ###
enabled = true # Cache enabled
dir = "./cache/"
doCleanUp = true

[network] ### Network ###
connectionTimeout = 10 # If ping isn't received within this amount of seconds, reconnect

[preload] ### Preload ###
enabled = true # Preload enabled

[time] ### Time correction ###
synchronizationMethod = "NTP" # Time synchronization method (NTP, PING, MELODY, MANUAL)
manualCorrection = 0 # Manual time correction in millis

[player] ### Player ###
autoplayEnabled = true # Autoplay similar songs when your music ends
preferredAudioQuality = "NORMAL" # Preferred audio quality (NORMAL, HIGH, VERY_HIGH)
enableNormalisation = true # Whether to apply the Spotify loudness normalisation
normalisationPregain = +3.0 # Normalisation pregain in decibels (loud at +6, normal at +3, quiet at -5)
initialVolume = 65536 # Initial volume (0-65536)
volumeSteps = 64 # Number of volume notches
logAvailableMixers = true # Log available mixers
mixerSearchKeywords = "" # Mixer/backend search keywords (semicolon separated)
crossfadeDuration = 1000 # Crossfade overlap time (in milliseconds)
output = "MIXER" # Audio output device (MIXER, PIPE, STDOUT, CUSTOM)
outputClass = "" # Audio output Java class name
releaseLineDelay = 20 # Release mixer line after set delay (in seconds)
pipe = "" # Output raw (signed) PCM to this file (`player.output` must be PIPE)
retryOnChunkError = true # Whether the player should retry fetching a chuck if it fails
metadataPipe = "" # Output metadata in Shairport Sync format (https://github.com/mikebrady/shairport-sync-metadata-reader)
bypassSinkVolume = false # Whether librespot-java should ignore volume events, sink volume is set to the max
localFilesPath = "" # Where librespot-java should search for local files

[api] ### API ###
port = 24879 # API port (`api` module only)
host = "0.0.0.0" # API listen interface (`api` module only)

[proxy] ### Proxy ###
enabled = false # Whether the proxy is enabled
type = "HTTP" # The proxy type (HTTP, SOCKS)
ssl = false # Connect to proxy using SSL (HTTP only)
address = "" # The proxy hostname
port = 0 # The proxy port
auth = false # Whether authentication is enabled on the server
username = "" # Basic auth username
password = "" # Basic auth password

[shell] ### Shell ###
enabled = false # Shell events enabled
executeWithBash = false # Execute the command with `bash -c`
onContextChanged = ""
onTrackChanged = ""
onPlaybackEnded = ""
onPlaybackPaused = ""
onPlaybackResumed = ""
onPlaybackFailed = ""
onTrackSeeked = ""
onMetadataAvailable = ""
onVolumeChanged = ""
onInactiveSession = ""
onPanicState = ""
onConnectionDropped = ""
onConnectionEstablished = ""
onStartedLoading = ""
onFinishedLoading = ""
27 changes: 27 additions & 0 deletions librespot-api.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
cd "$(dirname "$0")"

# shifting so we can have a device name with spaces
zeroconf_port="$1"
shift
crossfade_ms="$1"
shift
cache_dir="$1"
shift
device_name="$*"

# TODO:
# - check shared cache_dir
# - parameterize jar location
#
java -jar librespot-api-1.6.3.jar \
--deviceName="$device_name" \
--logLevel="OFF" \
--player.crossfadeDuration="$crossfade_ms" \
--player.output="STDOUT" \
--player.enableNormalisation=false \
--player.initialVolume=32767 \
--player.preferredAudioQuality="NORMAL" \
--zeroconf.listenPort="$zeroconf_port" \
--cache.dir="$cache_dir" \

4 changes: 2 additions & 2 deletions templates/snapserver.template
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ stream = pipe:///tmp/mopidy.{{name}}?name={{name}}&sampleformat=48000:16:2&codec
# {{name}}
stream = pipe:///tmp/mopidy.{{name}}?name=- {{name}} iris&sampleformat=48000:16:2&codec=flac
stream = airplay:///shairport-sync?name=- {{name}} airplay&devicename={{Name}}&port={{airplay.port}}&params=--configfile={{path.config_root}}/shairport-sync.{{name}}.conf
stream = librespot:///librespot?name=- {{name}} spotify&devicename={{Name}}&bitrate=160&volume=50&onevent={{path.config_root}}/{{spotify.event}}%20{{name}}&params=--zeroconf-port%20{{spotify.zeroconf}}
stream = process:///{{path.config_root}}/librespot-api.sh?name=- {{name}} spotify&log_stderr=true&sampleformat=44100:16:2&params={{spotify.zeroconf}}%20{{spotify.crossfade_ms}}%20{{path.media_root}}/{{path.music_metadata}}/librespot-java%20{{Name}}

stream = meta:///{{#announcer_streams}}{{.}}/{{/announcer_streams}}{{#streams}}- {{name}} {{.}}/{{/streams}}{{#other_streams}}{{.}}/{{/other_streams}}?name={{Name}}

Expand All @@ -149,7 +149,7 @@ stream = meta:///{{#announcer_streams}}{{.}}/{{/announcer_streams}}{{#streams}}-
# {{Name}}
stream = pipe:///tmp/mopidy.{{name}}?name=- {{name}} iris&sampleformat=48000:16:2&codec=flac
stream = airplay:///shairport-sync?name=- {{name}} airplay&devicename={{Name}}&port={{airplay.port}}&params=--configfile={{path.config_root}}/shairport-sync.{{name}}.conf
stream = librespot:///librespot?name=- {{name}} spotify&devicename={{Name}}&bitrate=160&volume=50&onevent={{path.config_root}}/{{spotify.event}}%20{{name}}&params=--zeroconf-port%20{{spotify.zeroconf}}
stream = process://{{path.config_root}}/librespot-api.sh?name=- {{name}} spotify&log_stderr=true&sampleformat=44100:16:2&params={{spotify.zeroconf}}%20{{spotify.crossfade_ms}}%20{{path.media_root}}/{{path.music_metadata}}/librespot-java%20{{Name}}

stream = meta:///{{#announcer_streams}}{{.}}/{{/announcer_streams}}{{#streams}}- {{name}} {{.}}/{{/streams}}?name={{Name}}

Expand Down

0 comments on commit 78d7a62

Please sign in to comment.