1
0
Fork 0

Add tool to send system now playing data to Tuna.

main
Icedream 2023-11-24 12:14:56 +01:00
parent a8b48eba1d
commit 0cd9c23299
Signed by: icedream
GPG Key ID: 468BBEEBB9EC6AEA
7 changed files with 455 additions and 6 deletions

View File

@ -30,6 +30,9 @@
{ {
"path": "icedreammusic/auto-restart-voicemeeter" "path": "icedreammusic/auto-restart-voicemeeter"
}, },
{
"path": "icedreammusic/np"
},
{ {
"path": "." "path": "."
} }

View File

@ -3,7 +3,7 @@ set -e
set -x set -x
set -u set -u
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
export GOOS=windows export GOOS=windows
export GOARCH=amd64 export GOARCH=amd64
export GOBIN="$SCRIPT_DIR"/bin/${GOOS}-${GOARCH} export GOBIN="$SCRIPT_DIR"/bin/${GOOS}-${GOARCH}
@ -11,23 +11,57 @@ ext=.exe
TARGET_TRIPLET=x86_64-w64-mingw32 TARGET_TRIPLET=x86_64-w64-mingw32
export CC="${TARGET_TRIPLET}"-gcc export CC="${TARGET_TRIPLET}"-gcc
export CXX="${TARGET_TRIPLET}"-g++ export CXX="${TARGET_TRIPLET}"-g++
export AR="${TARGET_TRIPLET}"-ar
export LD="${TARGET_TRIPLET}"-ld
export OBJCOPY="${TARGET_TRIPLET}"-objcopy
export RANLIB="${TARGET_TRIPLET}"-ranlib
export SIZE="${TARGET_TRIPLET}"-size
export STRIP="${TARGET_TRIPLET}"-strip
export PKG_CONFIG_PATH="${TARGET_TRIPLET}"/lib/pkgconfig export PKG_CONFIG_PATH="${TARGET_TRIPLET}"/lib/pkgconfig
thirdparty_includes="$SCRIPT_DIR"/include thirdparty_includes="$SCRIPT_DIR"/include
export CPATH="$thirdparty_includes:$thirdparty_includes/winfsp:/usr/${TARGET_TRIPLET}/include" export CPATH="$thirdparty_includes:$thirdparty_includes/winfsp:$thirdparty_includes/windows/splat/sdk/Include/10.0.22621:$thirdparty_includes/windows/splat/sdk/Include/10.0.22621/winrt:$thirdparty_includes/libnp/include:/usr/${TARGET_TRIPLET}/include"
# export CGO_CFLAGS="-I$thirdparty_includes -I$thirdparty_includes/winfsp -I/usr/${TARGET_TRIPLET}/include" # export CGO_CFLAGS="-I$thirdparty_includes -I$thirdparty_includes/winfsp -I/usr/${TARGET_TRIPLET}/include"
# export PATH="$GOBIN:$PATH" # export PATH="$GOBIN:$PATH"
export CGO_ENABLED=1 export CGO_ENABLED=1
mkdir -p "$thirdparty_includes" mkdir -p "$thirdparty_includes"
if [ ! -d "$thirdparty_includes/winfsp" ] if [ ! -d "$thirdparty_includes/libnp" ]; then
then wget -q -O libnp.zip https://github.com/delthas/libnp/archive/291aeb5d56d5b90f89ef8a271d0803a698488ca6.zip
7z x libnp.zip 'libnp-291aeb5d56d5b90f89ef8a271d0803a698488ca6/*' -o"$thirdparty_includes"/
rm libnp.zip
mv "$thirdparty_includes/libnp-291aeb5d56d5b90f89ef8a271d0803a698488ca6" "$thirdparty_includes/libnp"
(
cd "$thirdparty_includes/libnp/"
mkdir -p build
cd build
cmake \
-DCMAKE_SYSTEM_NAME=Windows \
-DCMAKE_SYSTEM_PROCESSOR= \
-DCMAKE_AR="$AR" \
-DCMAKE_ASM_COMPILER="$CC" \
-DCMAKE_C_COMPILER="$CC" \
-DCMAKE_CXX_COMPILER="$CXX" \
-DCMAKE_LINKER="$LD" \
-DCMAKE_OBJCOPY="$OBJCOPY" \
-DCMAKE_RANLIB="$RANLIB" \
-DCMAKE_SIZE="$SIZE" \
-DCMAKE_STRIP="$STRIP" \
-DCMAKE_C_FLAGS="-I$thirdparty_includes/windows/splat/sdk/Include/10.0.22621/winrt -I/usr/${TARGET_TRIPLET}/include" \
-DCMAKE_CXX_FLAGS="-I$thirdparty_includes/windows/splat/sdk/Include/10.0.22621/winrt -I/usr/${TARGET_TRIPLET}/include" \
-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER \
-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \
..
make
)
fi
if [ ! -d "$thirdparty_includes/winfsp" ]; then
wget -q -O winfsp.zip https://github.com/billziss-gh/winfsp/archive/release/1.2.zip wget -q -O winfsp.zip https://github.com/billziss-gh/winfsp/archive/release/1.2.zip
7z e winfsp.zip 'winfsp-release-1.2/inc/fuse/*' -o"$thirdparty_includes"/winfsp 7z e winfsp.zip 'winfsp-release-1.2/inc/fuse/*' -o"$thirdparty_includes"/winfsp
rm winfsp.zip rm winfsp.zip
fi fi
for bin in auto-restart-voicemeeter foobar2000 tunadish tunaposter prime4 for bin in auto-restart-voicemeeter foobar2000 tunadish tunaposter prime4 np; do
do
cd "$SCRIPT_DIR/$bin" cd "$SCRIPT_DIR/$bin"
go build -ldflags "-s -w" -o "$GOBIN/$bin$ext" -v go build -ldflags "-s -w" -o "$GOBIN/$bin$ext" -v
done done

1
icedreammusic/np/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
np

49
icedreammusic/np/go.mod Normal file
View File

@ -0,0 +1,49 @@
module github.com/icedream/livestream-tools/icedreammusic/np
go 1.19
replace (
github.com/icedream/livestream-tools/icedreammusic/metacollector => ../metacollector
github.com/icedream/livestream-tools/icedreammusic/tuna => ../tuna
)
require (
github.com/delthas/go-libnp v0.0.0-20221222161248-0e45ece1f878
github.com/dhowden/tag v0.0.0-20230630033851-978a0926ee25
github.com/gin-gonic/gin v1.9.1
github.com/icedream/livestream-tools/icedreammusic/metacollector v0.0.0-20230302143311-ad3e9704c029
github.com/icedream/livestream-tools/icedreammusic/tuna v0.0.0-20230302143311-ad3e9704c029
gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20191105091915-95d230a53780
)
require (
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.14.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/nicksnyder/go-i18n v1.10.1 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

105
icedreammusic/np/go.sum Normal file
View File

@ -0,0 +1,105 @@
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 h1:s6gZFSlWYmbqAuRjVTiNNhvNRfY2Wxp9nhfyel4rklc=
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE=
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s=
github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U=
github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY=
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams=
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/delthas/go-libnp v0.0.0-20221222161248-0e45ece1f878 h1:v8W8eW7eb2bHFXBA80UKcoe0TvEu46NlTHSDRvgAbMU=
github.com/delthas/go-libnp v0.0.0-20221222161248-0e45ece1f878/go.mod h1:aGVXnhWpDlt5U4SphG97o1gszctZKvBTXy320E8Buw4=
github.com/dhowden/tag v0.0.0-20230630033851-978a0926ee25 h1:simG0vMYFvNriGhaaat7QVVkaVkXzvqcohaBoLZl9Hg=
github.com/dhowden/tag v0.0.0-20230630033851-978a0926ee25/go.mod h1:Z3Lomva4pyMWYezjMAU5QWRh0p1VvO4199OHlFnyKkM=
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg=
github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js=
github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk=
github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/nicksnyder/go-i18n v1.10.1 h1:isfg77E/aCD7+0lD/D00ebR2MV5vgeQ276WYyDaCRQc=
github.com/nicksnyder/go-i18n v1.10.1/go.mod h1:e4Di5xjP9oTVrC6y3C7C0HoSYXjSbhh/dU0eUV32nB4=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k=
golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck=
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8=
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20191105091915-95d230a53780 h1:CEBpW6C191eozfEuWdUmIAHn7lwlLxJ7HVdr2e2Tsrw=
gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20191105091915-95d230a53780/go.mod h1:3HH7i1SgMqlzxCcBmUHW657sD4Kvv9sC3HpL3YukzwA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=

216
icedreammusic/np/main.go Normal file
View File

@ -0,0 +1,216 @@
package main
import (
"context"
"crypto/sha512"
"encoding/base64"
"fmt"
"log"
"net"
"net/http"
"net/url"
"os"
"os/signal"
"strings"
"syscall"
"time"
"github.com/delthas/go-libnp"
"github.com/dhowden/tag"
"github.com/gin-gonic/gin"
"gopkg.in/alecthomas/kingpin.v3-unstable"
"github.com/icedream/livestream-tools/icedreammusic/metacollector"
"github.com/icedream/livestream-tools/icedreammusic/tuna"
)
var (
cli = kingpin.New("np", "Transmit system now playing data to Tuna.")
argMetacollectorURL = cli.Arg("metacollector-url", "Metadata collector URL (service normally runs on port 8080)").Required().URL()
argDrive = cli.Arg("mountpoint", "The mountpoint to attach to.").Default("Z:").String()
)
func init() {
kingpin.MustParse(cli.Parse(os.Args[1:]))
}
func watchMetadata(ctx context.Context) <-chan *libnp.Info {
ticker := time.NewTicker(time.Second)
c := make(chan *libnp.Info)
go func(ticker *time.Ticker) {
for {
select {
case <-ctx.Done():
return
case <-ticker.C:
info, err := libnp.GetInfo(context.Background())
if err != nil {
os.Stderr.WriteString("WARNING: " + err.Error() + "\n")
continue
}
c <- info
}
}
}(ticker)
return c
}
func generateIDFromMetadata(metadata libnp.Info) [64]byte {
return sha512.Sum512([]byte(strings.Join(metadata.Artists, "|") + "||" + metadata.Title))
}
func main() {
ctx := context.Background()
ctx, cancel := signal.NotifyContext(ctx, os.Interrupt, syscall.SIGTERM)
defer cancel()
c := watchMetadata(ctx)
r := gin.Default()
r.GET("/cover/:base64Path", func(c *gin.Context) {
path := c.Params.ByName("base64Path")
pathBytes, err := base64.URLEncoding.DecodeString(path)
if err != nil {
c.JSON(500, map[string]string{"error": err.Error()})
return
}
path = string(pathBytes)
f, err := os.Open(path)
if err != nil {
c.JSON(500, map[string]string{"error": err.Error()})
return
}
defer f.Close()
// get cover if possible
fileMetadata, err := tag.ReadFrom(f)
if err != nil {
c.JSON(500, map[string]string{"error": err.Error()})
return
}
picture := fileMetadata.Picture()
if picture == nil {
c.JSON(404, map[string]string{"error": "this file has no picture"})
return
}
c.Header("Content-type", picture.MIMEType)
c.Writer.Write(picture.Data)
return
})
listener, err := net.Listen("tcp", ":0")
if err != nil {
panic(err)
}
apiAddr := &url.URL{
Scheme: "http",
Host: fmt.Sprintf("%s:%d", "127.0.0.1", listener.Addr().(*net.TCPAddr).Port),
Path: "/",
}
go http.Serve(listener, r)
func() {
tunaOutput := tuna.NewTunaOutput()
var lastCoverCheckPath [64]byte
lastCoverCheckResult := false
lastCoverCheckTime := time.Now()
metacollectorClient := metacollector.NewMetaCollectorClient(*argMetacollectorURL)
for metadata := range c {
log.Printf("New metadata: %+v", metadata)
tunaMetadata := &tuna.TunaData{
Status: tuna.Stopped,
}
if metadata != nil &&
(metadata.PlaybackType == libnp.PlaybackTypeMusic ||
metadata.PlaybackType != libnp.PlaybackTypeVideo) {
tunaMetadata.Status = tuna.Playing
id := generateIDFromMetadata(*metadata)
tunaMetadata.Title = metadata.Title
tunaMetadata.Artists = metadata.Artists
tunaMetadata.Duration = uint64(metadata.Length.Milliseconds())
// Check normal/other files against metacollector
hasChanged := lastCoverCheckPath != id
trackURL, err := url.Parse(metadata.URL)
if err == nil {
if strings.EqualFold(trackURL.Scheme, "file") {
fi, err := os.Stat(trackURL.Path)
if err == nil {
if !hasChanged {
hasChanged = fi.ModTime().Sub(lastCoverCheckTime) > 0
}
lastCoverCheckTime = fi.ModTime()
if hasChanged {
lastCoverCheckResult = false
lastCoverCheckPath = id
f, err := os.Open(trackURL.Path)
if err == nil {
// get cover if possible
fileMetadata, err := tag.ReadFrom(f)
if err == nil {
if fileMetadata.Picture() != nil {
lastCoverCheckResult = true
}
} else {
log.Printf("Warning while reading tags for %s: %s", trackURL.Path, err)
}
f.Close()
} else {
log.Printf("Warning while opening file %s: %s", trackURL.Path, err)
}
}
} else {
log.Printf("Warning while stat'ing file %s: %s", trackURL.Path, err)
}
if lastCoverCheckResult {
tunaMetadata.CoverURL = apiAddr.ResolveReference(&url.URL{
Path: fmt.Sprintf("cover/%s", base64.URLEncoding.EncodeToString([]byte(trackURL.Path))),
}).String()
}
}
}
}
go func() {
// enrich metadata with metacollector
req := metacollector.MetaCollectorRequest{
Artist: tunaMetadata.Artists[0],
Title: tunaMetadata.Title,
}
log.Printf("Trying to enrich metadata: %+v", req)
resp, err := metacollectorClient.GetTrack(req)
if err == nil {
log.Println("Enriching metadata:", resp)
if resp.CoverURL != nil {
tunaMetadata.CoverURL = (*argMetacollectorURL).ResolveReference(&url.URL{
Path: *resp.CoverURL,
}).String()
}
tunaMetadata.Label = resp.Publisher
} else {
log.Println("Failed to enrich metadata:", err)
}
err = tunaOutput.Post(tunaMetadata)
if err != nil {
log.Println(err)
} /*else {
log.Printf("Tuna has received the metadata: %+v", tunaMetadata)
}*/
}()
}
}()
}

View File

@ -0,0 +1,41 @@
package main
import (
"bytes"
"encoding/json"
"net/http"
"time"
)
type TunaOutput struct {
client *http.Client
}
type tunaData struct {
CoverURL string `json:"cover_url"`
Title string `json:"title"`
Artists []string `json:"artists"`
Status string `json:"status"`
Progress float64 `json:"progress"`
Duration float64 `json:"duration"`
}
func NewTunaOutput() *TunaOutput {
return &TunaOutput{
client: http.DefaultClient,
}
}
func (output *TunaOutput) Post(data *tunaData) (err error) {
body := new(bytes.Buffer)
json.NewEncoder(body).Encode(&struct {
Data *tunaData `json:"data"`
Hostname string `json:"hostname,omitempty"`
Date string `json:"date"`
}{
Data: data,
Date: time.Now().Format(time.RFC3339),
})
_, err = output.client.Post("http://localhost:1608", "application/json", body)
return
}