gotbletu-urlportal.sh (12199B)
1 #!/bin/bash 2 # _ _ _ _ 3 # __ _ ___ | |_| |__ | | ___| |_ _ _ 4 # / _` |/ _ \| __| '_ \| |/ _ \ __| | | | 5 #| (_| | (_) | |_| |_) | | __/ |_| |_| | 6 # \__, |\___/ \__|_.__/|_|\___|\__|\__,_| 7 # |___/ 8 # https://www.youtube.com/user/gotbletu 9 # https://twitter.com/gotbletu 10 # https://github.com/gotbletu 11 # gotbletu@gmail.com 12 13 # _ _ _ 14 # _ _ _ __| |_ __ ___ _ __| |_ __ _| | 15 # | | | | '__| | '_ \ / _ \| '__| __/ _` | | 16 # | |_| | | | | |_) | (_) | | | || (_| | | 17 # \__,_|_| |_| .__/ \___/|_| \__\__,_|_| 18 # |_| 19 # DESC: custom way to handle url (similar idea to xdg-open, mailcap) 20 # works with just about all programs (e.g w3m, rtv, newsboat, urlview ...etc) 21 # DEMO: https://www.youtube.com/watch?v=2jyfrmBYzVQ 22 # install: lynx youtube-dl task-spooler newsboat rtv w3m mpv urlview tmux feh plowshare streamlink curl coreutils 23 24 25 # newsboat: 26 # vim ~/.newsboat/config 27 # browser ~/.scripts/urlportal.sh 28 29 # rtv: 30 # vim ~/.bashrc 31 # export RTV_BROWSER=~/.scripts/urlportal.sh 32 33 # w3m: 34 # vim ~/.w3m/keymap 35 # open url under cursor (default: Esc+Shift+M); e.g 2+Esc+Shift+M 36 # keymap e EXTERN_LINK ~/.scripts/urlportal.sh 37 38 # urlview: 39 # vim ~/.urlview 40 # COMMAND ~/.scripts/urlportal.sh 41 42 # references: 43 # cirrusuk http://arza.us/paste/piper 44 # obosob https://github.com/michael-lazar/rtv/issues/78#issuecomment-125507472 45 # budlabs - mpv queue https://www.youtube.com/watch?v=-vbr3-mHoRs 46 # https://github.com/budlabs/youtube/blob/master/letslinux/032-queue-files-in-mpv/openvideo 47 # ji99 - mpv queue script https://www.reddit.com/r/commandline/comments/920p5d/bash_script_for_queueing_youtube_links_in_mpv/ 48 49 50 # BROWSERCLI="w3m" 51 # BROWSER="chromium" 52 # DEFAULT="xdg-open" 53 # DEFAULT="chromium --incognito" 54 # DEFAULT="w3m" 55 DEFAULT="$BROWSERCLI" 56 ## long videos like youtube 57 VIDEO_QUEUE="tsp mpv --ontop --no-border --force-window --autofit=500x280 --geometry=-15-53" 58 ## short videos/animated gif clips 59 VIDEO_CLIP="mpv --loop --quiet --ontop --no-border --force-window --autofit=900x600 --geometry=-15+60" 60 IMAGEGUI="feh -. -x -B black -g 900x600-15+60" 61 # IMAGECLI="w3m /usr/lib/w3m/cgi-bin/treat_as_url.cgi -o display_image=1 -o imgdisplay=/usr/lib/w3m/w3mimgdisplay" 62 IMAGECLI="w3m -o display_image=1 -o imgdisplay=w3mimgdisplay" 63 # IMAGECLI="fbi" 64 TORRENTCLI="transmission-remote --add" 65 # LIVEFEED='streamlink -p "mpv --cache 2048 --ontop --no-border --force-window --autofit=500x280 --geometry=-15-60"' 66 LIVEFEED="tsp streamlink" 67 DDL_PATH=~/Downloads/plowshare 68 DDL_QUEUE_FAST=~/.config/plowshare/queuefast.txt 69 70 71 # enable case-insensitive matching 72 shopt -s nocasematch 73 74 url="$1" 75 case "$url" in 76 *gfycat.com/*|*streamable.com/*) 77 nohup $VIDEO_CLIP "${url/.gifv/.webm}" > /dev/null 2>&1 & 78 ;; 79 *v.redd.it/*|*video.twimg.com/*|*dailymotion.com*) 80 nohup $VIDEO_CLIP "$url" > /dev/null 2>&1 & 81 ;; 82 *youtube.com/watch*|*youtu.be/*|*clips.twitch.tv/*) 83 $VIDEO_QUEUE "$url" 84 ;; 85 *twitch.tv/*) 86 $LIVEFEED "$url" 87 ;; 88 *pornhub.com/*|*xvideos.com/*) 89 # $VIDEO_QUEUE "$url" 90 nohup $VIDEO_CLIP "$url" > /dev/null 2>&1 & 91 ;; 92 *reddit.com/r/*) 93 tmux new-window -n rtv && tmux send-keys "rtv -l $url && tmux kill-pane" 'Enter' 94 ;; 95 *glodls.to/*|*eogli.org/*|*limetorrents.io/*|*limetorrents.cc/*|*pornoshara.tv/item*|*rustorrents.net/details*|*xxx-tracker.com/*) 96 tmux new-window -n browse && tmux send-keys "$BROWSERCLI '$url' && tmux kill-pane" 'Enter' 97 ;; 98 *thepiratebay.org/*|*torrentdownloads.me/*|*yourbittorrent2.com/*|*torlock2.com/*|*bt-scene.cc/*|*rarbg.to/*|*ettorrent.xyz/*) 99 tmux new-window -n browse && tmux send-keys "$BROWSERCLI '$url' && tmux kill-pane" 'Enter' 100 ;; 101 *22pixx.xyz/ia-i/*) 102 cleanurl="$(printf $url | sed 's/ia-i/i/g' | sed 's/\.html//g')" 103 tmux new-window -n pixcli && tmux send-keys "$IMAGECLI '$cleanurl' && tmux kill-pane" 'Enter' 104 ;; 105 *freebunker.com/*) 106 cleanurl="$(printf $url | sed 's@img\/@tn\/i@')" 107 tmux new-window -n pixcli && tmux send-keys "$IMAGECLI '$cleanurl' && tmux kill-pane" 'Enter' 108 ;; 109 *imagerar.com/t/*) 110 cleanurl="$(printf $url | sed 's@/t@/u@')" 111 tmux new-window -n pixcli && tmux send-keys "$IMAGECLI '$cleanurl' && tmux kill-pane" 'Enter' 112 ;; 113 *imagerar.com/imgy-u/*) 114 cleanurl="$(printf $url | sed 's/imgy-u/u/g' | sed 's/.html//g')" 115 tmux new-window -n pixcli && tmux send-keys "$IMAGECLI '$cleanurl' && tmux kill-pane" 'Enter' 116 ;; 117 *imageshtorm.com/upload/small/*|*hotimage.uk/upload/small/*|*hdmoza.com//upload/small/*|*nikapic.ru/upload/small/*|*imagedecode.com/upload/small/*|*trans.firm.in//upload/small/*) 118 # nohup $IMAGEGUI "$(printf $url | sed 's/small/big/')" > /dev/null 2>&1 & 119 cleanurl="$(printf $url | sed 's/small/big/')" 120 tmux new-window -n pixcli && tmux send-keys "$IMAGECLI '$cleanurl' && tmux kill-pane" 'Enter' 121 ;; 122 *imageshtorm.com/img*) 123 # nohup $IMAGEGUI "$(printf $url | sed 's/small/big/')" > /dev/null 2>&1 & 124 cleanurl="$(curl -s "$url" | grep onclick | grep -oP '<a href=\047\K[^\047]+')" 125 tmux new-window -n pixcli && tmux send-keys "$IMAGECLI '$cleanurl' && tmux kill-pane" 'Enter' 126 ;; 127 *freescreens.ru/allimage/*|*imgclick.ru/allimage/*|*money-pic.ru/allimage/*) 128 cleanurl="$(printf $url | sed 's/-thumb//')" 129 tmux new-window -n pixcli && tmux send-keys "$IMAGECLI '$cleanurl' && tmux kill-pane" 'Enter' 130 ;; 131 *freescreens.ru/*) 132 cleanurl="$(printf "$url/1/" | sed 's/freescreens.ru/picpic.online/')" 133 tmux new-window -n pixcli && tmux send-keys "$IMAGECLI '$cleanurl' && tmux kill-pane" 'Enter' 134 ;; 135 *pixcloud.ru/view*) 136 cleanurl="$(curl -s "$url" | grep -oP '<img id="photo" src="\K[^"]+')" 137 tmux new-window -n pixcli && tmux send-keys "$IMAGECLI '$cleanurl' && tmux kill-pane" 'Enter' 138 ;; 139 *money-pic.ru/*) 140 cleanurl="$(curl -s "$url/1/" | grep allimage | grep -oP '<img src="\K[^"]+')" 141 tmux new-window -n pixcli && tmux send-keys "$IMAGECLI '$cleanurl' && tmux kill-pane" 'Enter' 142 ;; 143 *imagecurl.com/viewer.php?file=*) 144 cleanurl="$(printf $url | sed 's@https://@https://cdn.@' | sed 's@/viewer.php?file=@/images/@')" 145 tmux new-window -n pixcli && tmux send-keys "$IMAGECLI '$cleanurl' && tmux kill-pane" 'Enter' 146 ;; 147 *img2share.com/*|*imgpeak.com/*|*damimage.com/img*|*imagedecode.com/img*|*picfuture.com/*|*imageteam.org/*|*imgsalem.com/*|*dimtus.com/img*|*imgstudio.org/img*|*imagehub.pro/img*|*trans.firm.in//img*|*pic.hotimg.site/img*) 148 # cleanurl="$(curl -s "$url" | grep -oP '<img class=\047centred\047 src=\047\K[^\047]+')" 149 cleanurl="$(curl -s "$url" | grep centred | grep -oP 'src=\047\K[^\047]+')" 150 tmux new-window -n pixcli && tmux send-keys "$IMAGECLI '$cleanurl' && tmux kill-pane" 'Enter' 151 ;; 152 *imgadult.com/img*|*imgdrive.net/*) 153 cleanurl="$(curl -s "$url" | grep -oP '<meta property="og:image" content="\K[^"]+' | sed 's/small/big/')" 154 tmux new-window -n pixcli && tmux send-keys "$IMAGECLI '$cleanurl' && tmux kill-pane" 'Enter' 155 ;; 156 *xxximagetpb.org/*|*img-central.com/*|*imgdone.com/image/*|*i.nmfiles.com/image/*|*i.imghost.top/image/*|*mstimg.com/image/*|*imagebam.com/image/*|*imgflip.com/i/*) 157 cleanurl="$(lynx -source "$url" | grep -oP '<meta property="og:image" content="\K[^"]+')" 158 tmux new-window -n pixcli && tmux send-keys "$IMAGECLI '$cleanurl' && tmux kill-pane" 'Enter' 159 ;; 160 *wallpaperspic.pw/*|*pornweb.xyz/*) 161 cleanurl="$(curl -s "$url" | grep imagebam | grep -oP '<p><img src="\K[^"]+')" 162 tmux new-window -n pixcli && tmux send-keys "$IMAGECLI '$cleanurl' && tmux kill-pane" 'Enter' 163 ;; 164 */imagetwist.com/*) 165 cleanurl="$(curl -s "$url" | grep -oP '<p style="display: block; text-align:center;"><img src="\K[^"]+')" 166 tmux new-window -n pixcli && tmux send-keys "$IMAGECLI '$cleanurl' && tmux kill-pane" 'Enter' 167 ;; 168 *imgtornado.com/img*|*placeimg.net/img*|*http://imgjazz.com/img*|*picmoza.com//img*|*xxxwebdlxxx.org/img*) 169 cleanurl="$(curl --data "imgContinue=Continue to image ..." --location "$url" | grep centred | grep -oP 'src=\047\K[^\047]+')" 170 tmux new-window -n pixcli && tmux send-keys "$IMAGECLI '$cleanurl' && tmux kill-pane" 'Enter' 171 ;; 172 *hotimage.uk/img*) 173 cleanurl="$(curl --data "imgContinue=Continue to image ..." --location "$(printf $url | sed 's@http://@https://www.@')" | grep centred | grep -oP 'src=\047\K[^\047]+')" 174 tmux new-window -n pixcli && tmux send-keys "$IMAGECLI '$cleanurl' && tmux kill-pane" 'Enter' 175 ;; 176 *i.imgur.com/*.gifv|*i.imgur.com/*.mp4|*i.imgur.com/*.webm|*i.imgur.com/*.gif) 177 nohup $VIDEO_CLIP "$url" > /dev/null 2>&1 & 178 ;; 179 *i.imgur.com/*| *imgur.com/*.*) 180 # nohup $IMAGEGUI "$url" > /dev/null 2>&1 & 181 tmux new-window -n pixcli && tmux send-keys "$IMAGECLI '$url' && tmux kill-pane" 'Enter' 182 ;; 183 *imgur.com/*) 184 # tmux split-window && tmux send-keys "lynx -source "$url" | grep post-image-container | grep -oP '<div id=\"\K[^\"]+' | while read line; do echo https://i.imgur.com/"\$line".png; done | urlview && tmux kill-pane" 'Enter' 185 multiurlextract="(lynx -source "$url" | grep post-image-container | grep -oP '<div id=\"\K[^\"]+' | while read line; do echo https://i.imgur.com/"\$line".png; done | urlview)" 186 tmux split-window && tmux send-keys "$multiurlextract && tmux kill-pane" 'Enter' 187 ;; 188 mailto:*) 189 tmux split-window -fv && tmux send-keys "mutt -- '$url' && tmux kill-pane" 'Enter' 190 ;; 191 *.pls|*.m3u) 192 tmux split-window -fv -p 20 && tmux send-keys "mpv '$url' && exit" 'Enter' 193 ;; 194 magnet:*|*.torrent) 195 $TORRENTCLI "$url" 196 ;; 197 *.jpg|*.jpeg|*.png|*:large) 198 tmux new-window -n pixcli && tmux send-keys "$IMAGECLI '$url' && tmux kill-pane" 'Enter' 199 # nohup $IMAGEGUI "$url" > /dev/null 2>&1 & 200 ;; 201 *.gif) 202 nohup $VIDEO_CLIP "${url/.gifv/.webm}" > /dev/null 2>&1 & 203 ;; 204 *zippyshare.com/*|*mediafire.com/file/*|*sendspace.com/file/*) 205 if pgrep -f $DDL_QUEUE_FAST > /dev/null 206 then 207 echo "$url" >> $DDL_QUEUE_FAST 208 else 209 echo "$url" >> $DDL_QUEUE_FAST 210 cat $DDL_QUEUE_FAST | awk '!x[$0]++' | sponge $DDL_QUEUE_FAST 211 tmux split-window -fv -p 20 && tmux send-keys "until [[ \$(cat $DDL_QUEUE_FAST | grep -v '#' | wc -l) -eq 0 ]]; do mkdir -p $DDL_PATH && cd $DDL_PATH && plowdown -m $DDL_QUEUE_FAST -o $DDL_PATH ; done" 'Enter' 212 fi 213 ;; 214 *.mp4|*.mkv|*.avi|*.wmv|*.m4v|*.mpg|*.mpeg|*.flv|*.ogm|*.ogv|*.gifv) 215 $VIDEO_QUEUE "$url" 216 ;; 217 *.mp3|*.m4a|*.wav|*.ogg|*.oga|*.flac) 218 # create queue fifo files if it does not exist 219 if [[ ! -p /tmp/mpvinput ]]; then 220 mkfifo /tmp/mpvinput 221 fi 222 223 # check if process mpv exist (e.g mpv --input-file=/tmp/mpvinput filename.mp3) 224 if pgrep -f mpvinput > /dev/null 225 then 226 # if mpv is already running then append new url/files to queue 227 # echo loadfile \"${url/'/\\'}\" append-play > /tmp/mpvinput 228 echo loadfile \"$url\" append-play > /tmp/mpvinput 229 # nohup $VIDEO_CLIP "${url/.gifv/.webm}" > /dev/null 2>&1 & 230 else 231 # if mpv is not running then start it (initial startup) 232 # mpv --no-video --input-file=/tmp/mpvinput "$1" 233 tmux split-window -fv -p 20 && tmux send-keys "mpv --no-video --input-file=/tmp/mpvinput \"$url\" && exit" 'Enter' 234 fi 235 # Note: use "<" or ">" hotkeys to skip between songs/audio queue list on mpv 236 ;; 237 *|*.html) 238 # $DEFAULT "$url" 239 tmux new-window -n browse && tmux send-keys "$DEFAULT '$url' && tmux kill-pane" 'Enter' 240 ;; 241 esac 242