#!/usr/bin/env bash

# A script to open urls
# For example, open images with sxiv

# This is necesary becuase environment variables are lost when calling from newsboat for some reason

url="$1"
browser="${BROWSER:-firefox-developer-edition}"

case "$url" in
	*"//invidious.*/"*) yt --url "$url"; exit 0 ;;
	*//*.youtube.*/*) yt --url "$url"; exit 0 ;;
	*"//videos.*"*) yt --url "$url"; exit 0 ;;
	*.png|*.jpg)
		tmp="$(mktemp)"
		curl -s -o "$tmp" --user-agent blar "$url"
		sxiv "$tmp"
		rm "$tmp"
		;;
	*.mp3|*.wma)
		mpv "$url"
		;;
	*"//xkcd.com/"*) xkcd "$url"; exit 0 ;;
	"mailto:"*) neomutt "$url"; exit 0 ;;
	*) $browser "$url"; exit 0 ;;
	#*) notify-send "$url"; exit ;;
esac

exit 1