# Maintainer (arch): Maxime Gauduin <alucryd@archlinux.org>
# Contributor: Stéphane Gaudreault <stephane@archlinux.org>
# Contributor: BlackEagle <ike.devolder@gmail.com>
# Contributor: Dany Martineau <dany.luc.martineau@gmail.com>
# Contributor: André Silva <emulatorman@hyperbola.info>
# Contributor: Márcio Silva <coadde@hyperbola.info>
# Maintainer: Omar Vega Ramos <ovruni@gnu.org.pe>
# Contributor: Kete <kete@ninthfloor.org>


# parabola changes and rationale:
#  - replaced nonfree nyancat artwork with moognu
#  - removed spotify support


pkgname=clementine
pkgver=1.4.0rc1+495+g10bf5dc17
pkgrel=2
pkgrel+=.parabola1
pkgdesc='A modern music player and library organizer'
pkgdesc+=', without nonfree artwork and Spotify support'
url=https://www.clementine-player.org/
license=(GPL)
arch=(x86_64)
arch+=(i686 armv7h)
depends=(chromaprint gst-plugins-base-libs libcdio libgpod liblastfm-qt5 libmtp libmygpo-qt5
         taglib protobuf qt5-x11extras projectm alsa-lib libpulse crypto++ hicolor-icon-theme)
makedepends=(boost cmake qt5-tools sparsehash)
optdepends=(
  'gst-plugins-base: "Base" plugin libraries'
  'gst-plugins-good: "Good" plugin libraries'
  'gst-plugins-bad: "Bad" plugin libraries'
  'gst-plugins-ugly: "Ugly" plugin libraries'
  'gst-libav: Libav plugin'
  'gvfs: Various devices support'
)
source=("https://github.com/clementine-player/Clementine/releases/download/${pkgver//+/-}/$pkgname-${pkgver//+/-}.tar.xz")
source+=(remove-nonfree-artwork-and-spotify.patch
         moognu.png)

sha256sums=('b61c7051b6282af3a5717a4d9e755e1b53e08a04339c6eb4b6df77521606cc03')
sha256sums+=('d9b19730e792e15d026cc4b89019be032c4c4843aace421df418b8111fc5e79f'
             'c6918617769152f3617c61f721819e69d03f671b85760b11cfe45abd53955bc4')

prepare() {
  sed -e 's|CRYPTOPP cryptopp|CRYPTOPP libcryptopp|' -i $pkgname-${pkgver//+/-}/CMakeLists.txt # Fix crypto++ detection

  mkdir -p build

  cd "$pkgname-${pkgver//+/-}"

  # remove nonfree artwork for the Nyan Cat plugin
  # https://labs.parabola.nu/issues/329
  rm -v data/nyancat.png

  # remove nonfree artwork and Spotify references
  patch -Np1 -i ../remove-nonfree-artwork-and-spotify.patch

  # remove Spotifyblob files
  rm -rv ext/{$pkgname-spotifyblob,lib${pkgname}-spotifyblob}

  # remove Spotify files
  rm -rv src/internet/spotify
  rm -v data/icons/svg/spotify.svg
  rm -v data/providers/{22x22,32x32,48x48}/spotify.png
  rm -v data/spotify-attribution.png
  rm -v data/clementine-spotify-public.pem
  rm -v cmake/SpotifyVersion.cmake
  rm -v data/schema/schema-30.sql
  rm -v src/globalsearch/spotifysearchprovider.{cpp,h}

  # move free Nyan Cat replacement mascot (MooGNU) to the source code
  # https://labs.parabola.nu/issues/329
  install -m644 -v ../moognu.png data

  # create an empty file because it's a dependency for Clementine
  touch data/schema/schema-30.sql
}

build() {
  cmake -B build -S $pkgname-${pkgver//+/-} \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DUSE_SYSTEM_PROJECTM=ON \
    -DUSE_SYSTEM_TAGLIB=ON
  cmake --build build
}

package() {
  DESTDIR="$pkgdir" cmake --install build
}
