#!/bin/sh
mugen_host=${MUGEN_HOST:-https://kara.moe}
kara_api="${MUGEN_KARA_API:-$mugen_host/api/karas}"
karamedia="${MUGEN_KARAOKEMEDIA:-$mugen_host/downloads}"

# karaoke medias and lyrics directories
medias="$karamedia/medias"
lyrics="$karamedia/lyrics"

kid=$ROFI_INFO

if [ -z "$@" ]; then
    /usr/bin/printf "\0prompt\x1fkaraoke search\n"
    exit 0
else
    if [ -z "$kid" ]; then
        /usr/bin/printf "\0prompt\x1fmugen\n"
        query="$(echo "$@" | tr " " "+")"
        curl "https://kara.moe/api/karas/search?collections=dbcf2c22-524d-4708-99bb-601703633927,c7db86a0-ff64-4044-9be4-66dd1ef1d1c1,2fa2fe3f-bb56-45ee-aa38-eae60e76f224,efe171c0-e8a1-4d03-98c0-60ecf741ad52&filter=$query&size=100" | jq -r '.content | .[] | "\(.mediafile)\u0000info\u001f\(.kid)"'
    fi
fi

# choose karaoke
[ -z "$kid" ] && exit

umpv "https://kara.moe/kara/$kid" > /dev/null 2>&1 &
exec 1>&-
