#Packager: Dimitris Tzemos <dijemos@gmail.com>

pkgname=stremio
pkgver=4.4.132
pkgrel=1dj
source=("$pkgname-$pkgver.tar.gz" "remove-node.patch")
url="https://www.stremio.com"
docs=('COPYING' 'Changelog' 'TODO')
options=('nosrcpack')

slackdesc=\
(
#|-----handy-ruler------------------------------------------------------|
"stremio (Movies, TV shows, series)"
"A one-stop hub for video content aggregation (Movies, TV shows,"
" series, live television or web channels)"
)

build() {
	cd $startdir/src/stremio
	grep -oPm1 'VERSION=\K.+' stremio.pro
	
	git submodule update --init
	make -f release.makefile clean
	
    patch -Np1 -i "${SRC}/remove-node.patch" || return 1
    
	make -f release.makefile PREFIX="$PKG" || return 1
	make -f release.makefile PREFIX="$PKG" install || return 1
	install -Dm644 smartcode-stremio.desktop "$PKG/opt/stremio/smartcode-stremio.desktop"
	 # binary and desktop file
    mkdir -p "${PKG}/usr/"{bin,share/applications}
    ln -s ../../opt/stremio/stremio "${PKG}/usr/bin/stremio"
    ln -s ../../../opt/stremio/smartcode-stremio.desktop "${PKG}/usr/share/applications/smartcode-stremio.desktop"
    
    # icons
    local _file
    local _res
    while read -r -d '' _file
    do
        _res="$(printf '%s' "$_file" | sed 's/\.png$//;s/^.*_//')"
        mkdir -p "${PKG}/usr/share/icons/hicolor/${_res}x${_res}/apps"
        ln -s ../../../../../../opt/stremio/icons/smartcode-stremio_${_res}.png \
              "${PKG}/usr/share/icons/hicolor/${_res}x${_res}/apps/smartcode-stremio.png"
        ln -s ../../../../../../opt/stremio/icons/smartcode-stremio-tray_${_res}.png \
              "${PKG}/usr/share/icons/hicolor/${_res}x${_res}/apps/smartcode-stremio-tray.png"
    done < <(find "${PKG}/opt/stremio/icons" -maxdepth 1 -type f -name 'smartcode-stremio_*.png' -print0)
}
