mpv.sh - randomcrap - random crap programs of varying quality
 (HTM) git clone git://git.codemadness.org/randomcrap
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
       mpv.sh (890B)
       ---
            1 #!/bin/sh
            2 
            3 # match(str, regex)
            4 match() {
            5         printf '%s' "$1" | grep -qE "$2"
            6 }
            7 
            8 # movie(url)
            9 movie() {
           10         test -n "$1" && mpv "$1"
           11 }
           12 
           13 # specify as argument or use clipboard.
           14 text=""
           15 if [ x"$1" != x"" ]; then
           16         text="$1"
           17 else
           18         text=$(sselp)
           19 fi
           20 
           21 if match "$text" '^(http|https)://nos\.nl/'; then
           22         # extract unique video links, make them selectable.
           23         text=$(~/.config/scripts/plumb/nos.sh "$text")
           24 elif match "$text" '^(http|https)://.*reddit\.com/'; then
           25         # extract saner video url (than mpv / youtube-dl).
           26         text=$(~/.config/scripts/plumb/reddit.sh "$text")
           27 fi
           28 
           29 # if there is one line, just open immediately, else selectable.
           30 nlines=$(($(printf '%s\n' "$text" | wc -l) + 0))
           31 if test x"${nlines}" != x"1"; then
           32         text=$(printf '%s\n' "$text" | ~/.config/scripts/dmenu_urls.sh)
           33 else
           34         text=$(printf '%s\n' "$text" | sed -nE 's@^.*(http|https|gopher|gophers|ytdl)://(.*)$@\1://\2@p')
           35 fi
           36 
           37 movie "$text"