#!/bin/bash

if [[ $1 == "--length" ]]; then
    playerctl -p spotify metadata mpris:length
fi

if [[ $1 == "--open" ]]; then
    URL=$(playerctl -p spotify metadata xesam:url)
    echo "$URL?go=1&utm_medium=desktop"
fi

if [[ $1 == "--artist" ]]; then
   "$HOME/.config/eww/Main/scripts/music-artist"
fi

if [[ $1 == "--length-time" ]]; then
   "$HOME/.config/eww/Main/scripts/music-length"
fi

if [[ $1 == "--length-info" ]]; then
   "$HOME/.config/eww/Main/scripts/music-length-info"
fi

if [[ $1 == "--cover" ]]; then
   "$HOME/.config/eww/Main/scripts/music-art"
fi

if [[ $1 == "--album" ]]; then
   "$HOME/.config/eww/Main/scripts/music-album"
fi

if [[ $1 == "--current-volume" ]]; then
   VOLUME=$(playerctl -p spotify volume)
   echo $(python -c "print(float("$VOLUME")*100)")
fi

if [[ $1 == "--volume" ]]; then
   CURRENT_VOLUME=$2
   NOW_VOLUME=$(python -c "print(float($CURRENT_VOLUME)/100)")
   playerctl -p spotify volume "$NOW_VOLUME"
fi

if [[ $1 == "--shuffle" ]]; then
   if [[ $(playerctl -p spotify shuffle) == "On" ]]; then
      playerctl -p spotify shuffle off
   else
      playerctl -p spotify shuffle On
   fi
fi

if [[ $1 == "--current-pos" ]]; then
   playerctl -p spotify position --format '{{ duration(position) }}'
fi

if [[ $1 == "--launch-lyrics" ]]; then
   eww open --toggle lyrics
fi