name: spotifyd
adopt-info: spotifyd
summary: A spotify daemon
description: |
  An open source Spotify client running as a UNIX daemon. 
  Spotifyd streams music just like the official client, 
  but is more lightweight and supports more platforms. 
  Spotifyd also supports the Spotify Connect protocol 
  which makes it show up as a device that can be controlled 
  from the official clients.
  Spotifyd requires a Spotify Premium account

grade: stable
confinement: strict

parts:
  spotifyd:
    plugin: rust
    rust-channel: nightly
    source: .
    rust-features: ["pulseaudio_backend"]
    build-packages:
      - libssl-dev
      - libasound2-dev
      - libpulse-dev
      - pkg-config
    stage-packages:
      - libpulse0
    override-pull: |
      snapcraftctl pull
      last_committed_tag="$(git describe --tags --abbrev=0)"
      last_committed_tag_ver="$(echo ${last_committed_tag} | sed 's/v//')"
      last_released_tag="$(snap info spotifyd | awk '$1 == "beta:" { print $2 }')"
      # If the latest tag from the upstream project has not been released to
      # beta, build that tag instead of master.
      if [ "${last_committed_tag_ver}" != "${last_released_tag}" ]; then
        git fetch
        git checkout "${last_committed_tag}"
      fi
      snapcraftctl set-version "$(git describe --tags | sed 's/v//')"

apps:
  spotifyd:
    environment:
      LD_LIBRARY_PATH: "$SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/pulseaudio"
    command: bin/spotifyd 
    daemon: forking
    plugs:
      - network
      - network-bind
      - pulseaudio
