aboutsummaryrefslogtreecommitdiff
path: root/misc/.local/bin/omniopen
blob: 2e78f94b95039d01d55bfa936d18c06b43bb92cc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash

# Work-in-progress omni-launcher based on @Gotbletu's urlportal
#
#   https://github.com/gotbletu/dotfiles_v2/raw/master/normal_user/scripts/.scripts/urlportal
#

BROWSER="firefox-bin"
FALLBACK="$BROWSER"
NITTER_INSTANCE="https://nitter.snopyta.org"
VIDEO_PLAYER_CLIP="mpv --loop --really-quiet"
### long videos like youtube
#VIDEO_QUEUE="tsp mpv --ontop --no-border --force-window --autofit=500x280 --geometry=-15-53"
### short videos/animated gif clips
#IMAGEGUI="feh -. -x -B black -g 900x600-15+60"
#TORRENTCLI="transmission-remote --add"

# enable case-insensitive matching
shopt -s nocasematch

URL="$1"
case "$URL" in
    *.jpg|*.png|*.gif|*bibliogram.*/imageproxy?url=*)
        TEMP=`mktemp`
        curl -s "$URL" > "$TEMP"
        WIN=`xdotool getwindowfocus`
        WIDTH=`xdotool getwindowgeometry --shell $WIN | sed -n 's/^WIDTH=\([[:digit:]]\+\)/\1/p'`
        HEIGHT=`xdotool getwindowgeometry --shell $WIN | sed -n 's/^HEIGHT=\([[:digit:]]\+\)/\1/p'`
        sxiv -p -b -a -e $WIN -g "$WIDTH"x"$HEIGHT" "$TEMP"
        rm -f "$TEMP"
        ;;
    *reddit.com/r/*/comments/*)
        $SCRIPTS/reddit_comments.sh "$URL"
        ;;
    #*imgur.com/a/*)
    #    WIN=`xdotool getwindowfocus`
    #    URLS=`w3m -dump_source "$URL" | sed -n 's|.*<div id=\"\([[:alnum:]]\+\)\" class=\"post-image-container.*|https://i.imgur.com/\1.png|p'`
    #    #echo "There are "
    #    echo "$URLS"
    #    sleep 5
    #    ;;
    *v.redd.it/*)
        WIN=`xdotool getwindowfocus`
        $VIDEO_PLAYER_CLIP --wid="$WIN" $URL
        ;;
    *reddit.com/link/*/video/*/player)
        URL=`echo "$URL" | sed "s|^.*reddit\.com/link/.*/video/\(.*\)/player$|https://v.redd.it/\1|"`
        WIN=`xdotool getwindowfocus`
        $VIDEO_PLAYER_CLIP --wid="$WIN" $URL
        ;;
    *twitter.com/*)
        URL=`echo "$URL" | sed "s|^https\?://\(www.\)\?twitter\.com|$NITTER_INSTANCE|"`
        $FALLBACK "$URL"
        ;;
#    *gfycat.com/*|*streamable.com/*)
#        nohup $VIDEO_CLIP "${url/.gifv/.webm}" > /dev/null 2>&1 &
#        ;;
#    *v.redd.it/*|*video.twimg.com/*|*dailymotion.com*)
#        nohup $VIDEO_CLIP "$url" > /dev/null 2>&1 &
#        ;;
#    *youtube.com/watch*|*youtu.be/*|*clips.twitch.tv/*)
#        $VIDEO_QUEUE "$url"
#        ;;
#    *twitch.tv/*)
#        $LIVEFEED "$url"
#        ;;
#    *reddit.com/r/*)
#        tmux new-window -n rtv && tmux send-keys "rtv -l $url && tmux kill-pane" 'Enter'
#        ;;
#    *i.imgur.com/*.gifv|*i.imgur.com/*.mp4|*i.imgur.com/*.webm|*i.imgur.com/*.gif)
#        nohup $VIDEO_CLIP "$url" > /dev/null 2>&1 &
#        ;;
#    *i.imgur.com/*| *imgur.com/*.*)
#        # nohup $IMAGEGUI "$url" > /dev/null 2>&1 &
#        tmux new-window -n pixcli && tmux send-keys "$IMAGECLI '$url' && tmux kill-pane" 'Enter'
#        ;;
#    mailto:*)
#        tmux split-window -fv && tmux send-keys "mutt -- '$url' && tmux kill-pane" 'Enter'
#        ;;
#    *.pls|*.m3u)
#        tmux split-window -fv -p 20 && tmux send-keys "mpv '$url' && exit" 'Enter'
#        ;;
#    magnet:*|*.torrent)
#        $TORRENTCLI "$url"
#        ;;
#    *.jpg|*.jpeg|*.png|*:large)
#        tmux new-window -n pixcli && tmux send-keys "$IMAGECLI '$url' && tmux kill-pane" 'Enter'
#        # nohup $IMAGEGUI "$url" > /dev/null 2>&1 &
#        ;;
#    *.gif)
#        nohup $VIDEO_CLIP "${url/.gifv/.webm}" > /dev/null 2>&1 &
#        ;;
#    *.mp4|*.mkv|*.avi|*.wmv|*.m4v|*.mpg|*.mpeg|*.flv|*.ogm|*.ogv|*.gifv)
#        $VIDEO_QUEUE "$url"
#        ;;
#    *.mp3|*.m4a|*.wav|*.ogg|*.oga|*.flac)
#        # create queue fifo files if it does not exist
#        if [[ ! -p /tmp/mpvinput ]]; then
#            mkfifo /tmp/mpvinput
#        fi
#
#        # check if process mpv exist (e.g mpv --input-file=/tmp/mpvinput filename.mp3)
#        if pgrep -f mpvinput > /dev/null
#        then
#            # if mpv is already running then append new url/files to queue
#            # echo loadfile \"${url/'/\\'}\" append-play > /tmp/mpvinput
#            echo loadfile \"$url\" append-play > /tmp/mpvinput
#        # nohup $VIDEO_CLIP "${url/.gifv/.webm}" > /dev/null 2>&1 &
#        else
#            # if mpv is not running then start it (initial startup)
#            # mpv --no-video --input-file=/tmp/mpvinput "$1"
#            tmux split-window -fv -p 20 && tmux send-keys "mpv --no-video --input-file=/tmp/mpvinput \"$url\" && exit" 'Enter'
#        fi
#        # Note: use "<" or ">" hotkeys to skip between songs/audio queue list on mpv
#        ;;
    *)
        $FALLBACK "$URL"
        ;;
esac