#!/bin/sh

case "$1" in
    https://pbs.twimg.com/media/*.jpg*|https://0x0.st/*)
        curl "$1" | mpv --video-unscaled=downscale-big --pause --no-osc --no-fs - &
        ;;
    *.png|*.jpg|*.JPG)
        mpv --video-unscaled=downscale-big --pause --no-osc --no-fs "$1" &
        ;;
    *.gif|*.webm|*.mkv|*.mp4|*.MP4)
        mpv --video-unscaled=downscale-big --no-osc --no-fs "$1" &
        ;;
    https://youtu.be/*|https://www.youtube.com/watch*)
        umpv "$1" &
        ;;
    *.torrent|magnet:*)
        addtorrent "$1" &
        ;;
    *)
        browser=$(printf "browser\nchromium\nfirefox\nw3m\n" | dmenu)
        [ -z "$browser" ] && exit
        [ "$browser" = w3m ] && st -e w3m "$1" || $browser "$1" >/dev/null 2>&1 &
        ;;
esac
