2018-02-03 00:34:17 -06:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Copyright (c) 2017 rehashedsalt/vintagesalt
|
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
|
|
# in the Software without restriction, including without limitation the rights
|
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
|
|
# furnished to do so, subject to the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be included in all
|
|
|
|
# copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
# SOFTWARE.
|
|
|
|
|
2018-07-14 17:43:43 -05:00
|
|
|
name="$(basename $0)"
|
|
|
|
|
2018-02-03 00:34:17 -06:00
|
|
|
if [ "$XDG_DATA_HOME" = "" ]; then
|
2018-07-14 17:43:43 -05:00
|
|
|
cachefile="$HOME/.local/share/$name.cache"
|
2018-02-03 00:34:17 -06:00
|
|
|
else
|
2018-07-14 17:43:43 -05:00
|
|
|
cachefile="$XDG_DATA_HOME/$name.cache"
|
2018-02-03 00:34:17 -06:00
|
|
|
fi
|
|
|
|
|
|
|
|
if ! [ -f "$cachefile" ]; then
|
|
|
|
touch $cachefile
|
|
|
|
fi
|
|
|
|
|
|
|
|
cachecontent="$(cat $cachefile)"
|
|
|
|
|
|
|
|
function video-play {
|
|
|
|
pkill -x xwinwrap
|
|
|
|
#xwinwrap -g 1920x1048+0+0 -ni -b -nf -o 0.5 -ov -- urxvt -bg rgba:2828/2828/2828/FFFF -embed WID -e cava
|
|
|
|
xwinwrap -ni -fs -b -nf -ov -- mpv -wid WID --title="Desktop Video" --loop-playlist=inf $1
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
function video-validate {
|
2018-06-22 20:09:21 -05:00
|
|
|
if youtube-dl -e $1; then
|
2018-02-03 00:34:17 -06:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
function cache-add {
|
|
|
|
if [[ "$cachecontent" == *"$1"* ]]; then
|
|
|
|
return 1
|
|
|
|
fi
|
2018-07-18 18:55:10 -05:00
|
|
|
name="$(youtube-dl -s $1)"
|
2018-02-03 00:34:17 -06:00
|
|
|
printf "$name\n$1\n" >> $cachefile
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
function cache-populate {
|
|
|
|
names="$(awk -F'\n' 'BEGIN{RS="\n\n"} {for (i=1;i<=NF;i+=2) print $i}' $cachefile)"
|
|
|
|
printf "$names"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
function cache-lookup-by-name {
|
|
|
|
url="$(awk -v URL="$1" -F'\n' 'BEGIN{RS="\n\n"} {for (i=1;i<=NF;i++) if (index($i, URL)) print $(i+1)}' $cachefile)"
|
|
|
|
if [ "$url" = "" ]; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
printf "$url\n"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
function input-get {
|
2018-07-14 17:43:43 -05:00
|
|
|
cache-populate | rofi -dmenu -p "$name"
|
2018-02-03 00:34:17 -06:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
function soft-notify {
|
2018-07-18 18:55:10 -05:00
|
|
|
notify-send -u low -t 3000 -a "$name" "$1" "$2"
|
2018-02-03 00:34:17 -06:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
function hard-notify {
|
2018-07-18 18:55:10 -05:00
|
|
|
notify-send -u normal -t 10000 -a "$name" "$1" "$2"
|
2018-02-03 00:34:17 -06:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
input="$(input-get | tr -d '\n')"
|
|
|
|
if [ "$input" = "" ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
printf "Input: $input\n"
|
|
|
|
|
|
|
|
if cache-lookup-by-name "$input"; then
|
|
|
|
input="$(cache-lookup-by-name "$input")"
|
2018-07-18 18:55:10 -05:00
|
|
|
printf "Lookup successful: $input\n"
|
2018-02-03 00:34:17 -06:00
|
|
|
fi
|
|
|
|
|
|
|
|
if ! video-validate $input; then
|
2018-07-14 17:43:43 -05:00
|
|
|
hard-notify "Unable to Find Video" "Please verify that the URL is a valid video and try again."
|
|
|
|
printf "Not a valid stream: $input\n" 1>&2
|
2018-02-03 00:34:17 -06:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
soft-notify "Found Video" "Video $1 has been found and is buffering. It will be embedded in the desktop shortly."
|
|
|
|
|
|
|
|
cache-add $input
|
|
|
|
video-play $input
|
|
|
|
|
|
|
|
exit 0
|