BIN: Deletes open-youtube and puts functionality in yt
The yt script now accepts a --url option which will take a url as an option like yt --url youtube.com/watch?v=blar or echo youtube.com/watch?v=blar | yt --url It will also use rofi rather than fzf if not being run from a terminal or the --rofi flag is given I have updated the files that used to use open-youtube to reflect this
This commit is contained in:
parent
c619f884bd
commit
99736427be
5 changed files with 99 additions and 52 deletions
|
@ -20,5 +20,7 @@ url="$(curl https://ippsec.rocks/dataset.json 2>/dev/null |\
|
||||||
fzf -d ' ' --with-nth '3,2' --header-lines 1 --preview-window 'up:1' --preview 'bash -c '\''buildURL "$0"'\'' {}' |\
|
fzf -d ' ' --with-nth '3,2' --header-lines 1 --preview-window 'up:1' --preview 'bash -c '\''buildURL "$0"'\'' {}' |\
|
||||||
buildURL)"
|
buildURL)"
|
||||||
|
|
||||||
open-youtube "$url"
|
echo "$url"
|
||||||
|
|
||||||
|
yt "$url"
|
||||||
|
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
isxclient=$( readlink /dev/fd/2 | grep -q 'tty' && [[ -n $DISPLAY ]] ; echo $? )
|
|
||||||
if [[ ! -t 2 || $isxclient == "0" ]]; then
|
|
||||||
DMENU="rofi -dmenu -p"
|
|
||||||
else
|
|
||||||
DMENU="fzf --prompt"
|
|
||||||
fi
|
|
||||||
|
|
||||||
url="$1"
|
|
||||||
|
|
||||||
if [ -z "$url" ]; then
|
|
||||||
url=$($DMENU 'URL')
|
|
||||||
fi
|
|
||||||
|
|
||||||
code=$( ( youtube-dl "$url" -F; echo "bb Best of both") | sed -n '/format code/,$ p' | tail -n +2 | $DMENU "Quality " -m | awk '{print $1}')
|
|
||||||
|
|
||||||
code="$(echo "$code" | tr '\n' '+' | sed 's/+$//')"
|
|
||||||
|
|
||||||
case "$code" in
|
|
||||||
"bb") mpv "$url" --ytdl-format="bestvideo+bestaudio" ;;
|
|
||||||
*) mpv "$url" --ytdl-format="$code"
|
|
||||||
esac
|
|
||||||
|
|
|
@ -9,9 +9,9 @@ url="$1"
|
||||||
browser="${BROWSER:-firefox-developer-edition}"
|
browser="${BROWSER:-firefox-developer-edition}"
|
||||||
|
|
||||||
case "$url" in
|
case "$url" in
|
||||||
*"//invidious.*/"*) open-youtube "$url"; exit 0 ;;
|
*"//invidious.*/"*) yt --url "$url"; exit 0 ;;
|
||||||
*//*.youtube.*/*) open-youtube "$url"; exit 0 ;;
|
*//*.youtube.*/*) yt --url "$url"; exit 0 ;;
|
||||||
*"//videos.*"*) open-youtube "$url"; exit 0 ;;
|
*"//videos.*"*) yt --url "$url"; exit 0 ;;
|
||||||
*"//xkcd.com/"*) xkcd "$url"; exit 0 ;;
|
*"//xkcd.com/"*) xkcd "$url"; exit 0 ;;
|
||||||
"mailto:"*) neomutt "$url"; exit 0 ;;
|
"mailto:"*) neomutt "$url"; exit 0 ;;
|
||||||
*) $browser "$url"; exit 0 ;;
|
*) $browser "$url"; exit 0 ;;
|
||||||
|
|
113
bin/.bin/yt
113
bin/.bin/yt
|
@ -2,10 +2,13 @@
|
||||||
|
|
||||||
# Requires:
|
# Requires:
|
||||||
# * curl
|
# * curl
|
||||||
# * fzf
|
# * fzf | rofi
|
||||||
# * jq
|
# * jq
|
||||||
# * hq
|
|
||||||
# * youtube-dl
|
# * youtube-dl
|
||||||
|
# * hq | pup (recomended, although optional)
|
||||||
|
|
||||||
|
rofi="auto"
|
||||||
|
|
||||||
ttyecho(){
|
ttyecho(){
|
||||||
# Same as echo but always to tty
|
# Same as echo but always to tty
|
||||||
echo "$@" > /dev/tty
|
echo "$@" > /dev/tty
|
||||||
|
@ -42,15 +45,30 @@ forceread(){
|
||||||
echo "$answer"
|
echo "$answer"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useRofi(){
|
||||||
|
[ "$rofi" = "yes" ] && return 0
|
||||||
|
local isxclient=$( readlink /dev/fd/2 | grep -q 'tty' && [[ -n $DISPLAY ]] ; echo $? )
|
||||||
|
if [[ ! -t 2 || $isxclient == "0" ]]; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
getSearchTerm(){
|
getSearchTerm(){
|
||||||
# Uses fzf to get a search term
|
if useRofi; then
|
||||||
# It will filter suggestions using youtube's autocomplete
|
# Rofi can't reload the suggestions so just display a search box
|
||||||
export -f getSearchSuggestions
|
echo "" | rofi -dmenu -lines 0
|
||||||
export -f urlencodespecial
|
else
|
||||||
echo "" | fzf --bind 'change:reload:bash -c "getSearchSuggestions {q}" || true' \
|
# Uses fzf to get a search term
|
||||||
--header="Search Suggestions" \
|
# It will filter suggestions using youtube's autocomplete
|
||||||
--phony \
|
export -f getSearchSuggestions
|
||||||
--height=50% --layout=reverse
|
export -f urlencodespecial
|
||||||
|
echo "" | fzf --bind 'change:reload:bash -c "getSearchSuggestions {q}" || true' \
|
||||||
|
--header="Search Suggestions" \
|
||||||
|
--phony \
|
||||||
|
--height=50% --layout=reverse
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
getSearchSuggestions(){
|
getSearchSuggestions(){
|
||||||
|
@ -86,18 +104,35 @@ jq '..|.videoRenderer?' | sed '/^null$/d' |
|
||||||
}
|
}
|
||||||
|
|
||||||
chooseVideo(){
|
chooseVideo(){
|
||||||
(echo -e "Title\tChannel\tViews\tTime\tAge\tId"
|
if useRofi; then
|
||||||
jq -r '[ .title, .channel, .views, .time, .age, .video ] | @tsv') |
|
( jq -r '[ .title, .channel, .views, .time, .age, .video ] | @tsv') |
|
||||||
column -t -s" " | sed $'s/ \([^ ]\)/\u00a0\\1/g' |
|
column -t -s" " | sed $'s/ \([^ ]\)/\u00a0\\1/g' |
|
||||||
fzf --header-lines="1" --with-nth=1,2,3,4,5 --delimiter=$'\u00a0'
|
rofi -dmenu
|
||||||
|
else
|
||||||
|
(echo -e "Title\tChannel\tViews\tTime\tAge\tId"
|
||||||
|
jq -r '[ .title, .channel, .views, .time, .age, .video ] | @tsv') |
|
||||||
|
column -t -s" " | sed $'s/ \([^ ]\)/\u00a0\\1/g' |
|
||||||
|
fzf --header-lines="1" --with-nth=1,2,3,4,5 --delimiter=$'\u00a0'
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
chooseQuality(){
|
chooseQuality(){
|
||||||
videoId="$(cat - | awk -F $'\u00a0' '{print $6}')"
|
if [ -n "$1" ]; then
|
||||||
code="$( (
|
videoId="$1"
|
||||||
echo "bb Best of Both"
|
else
|
||||||
youtube-dl "$videoId" -F | sed -n '/format code/,$ p' | sed 1d;
|
videoId="$(cat - | awk -F $'\u00a0' '{print $6}')"
|
||||||
) | fzf --prompt "Quality " -m | cut -d ' ' -f 1 )"
|
fi
|
||||||
|
if useRofi; then
|
||||||
|
code="$( (
|
||||||
|
echo "bb Best of Both"
|
||||||
|
youtube-dl "$videoId" -F | sed -n '/format code/,$ p' | sed 1d;
|
||||||
|
) | rofi -dmenu -prompt "Quality " -m | cut -d ' ' -f 1 )"
|
||||||
|
else
|
||||||
|
code="$( (
|
||||||
|
echo "bb Best of Both"
|
||||||
|
youtube-dl "$videoId" -F | sed -n '/format code/,$ p' | sed 1d;
|
||||||
|
) | fzf --prompt "Quality " -m | cut -d ' ' -f 1 )"
|
||||||
|
fi
|
||||||
|
|
||||||
code="$(echo "$code" | tr '\n' '+' | sed 's/+$//')"
|
code="$(echo "$code" | tr '\n' '+' | sed 's/+$//')"
|
||||||
|
|
||||||
|
@ -107,12 +142,46 @@ chooseQuality(){
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
main(){
|
main(){
|
||||||
local searchTerm="$*"
|
local url=""
|
||||||
|
local videoID=""
|
||||||
|
local searchTerm=""
|
||||||
|
while [[ "$1" = -?* ]]; do
|
||||||
|
case "$1" in
|
||||||
|
-u|--url)
|
||||||
|
if [ -n "$2" ]; then
|
||||||
|
url="$2"
|
||||||
|
shift
|
||||||
|
else
|
||||||
|
url="$(cat -)"
|
||||||
|
fi
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--rofi)
|
||||||
|
rofi=yes
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
[ -z "$searchTerm" ] && searchTerm="$(getSearchTerm)"
|
if [ -n "$url" ]; then
|
||||||
|
case "$url" in
|
||||||
|
# If it contains an equals sign, let's assume it's a url
|
||||||
|
# Get the value of the v parameter
|
||||||
|
*=*) videoID="$(echo "$url" | grep -Eo '(\?|&)v=[^?&]*' | cut -d '=' -f 2)" ;;
|
||||||
|
# If there isn't an =, assume it is just the video ID
|
||||||
|
*) videoID="$url"
|
||||||
|
esac
|
||||||
|
chooseQuality "$videoID"
|
||||||
|
else
|
||||||
|
searchTerm="$*"
|
||||||
|
|
||||||
performSearch "$searchTerm" | extractVideoInfo | chooseVideo | chooseQuality
|
[ -z "$searchTerm" ] && searchTerm="$(getSearchTerm)"
|
||||||
|
|
||||||
|
performSearch "$searchTerm" | extractVideoInfo | chooseVideo | chooseQuality
|
||||||
|
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
|
|
|
@ -45,8 +45,8 @@ set searchurls.audio https://www.google.com/search?hl=en&ei=cSj3X5L0HYXykwXRpKvY
|
||||||
""""""""""""""
|
""""""""""""""
|
||||||
|
|
||||||
command withUrl composite get_current_url |
|
command withUrl composite get_current_url |
|
||||||
command openvid withUrl !s open-youtube
|
command openvid withUrl !s yt --url
|
||||||
command openvidLink composite hint -pipe a[href]:not([display="none"]):not([href=""]) href | !s open-youtube
|
command openvidLink composite hint -pipe a[href]:not([display="none"]):not([href=""]) href | !s yt --url
|
||||||
command testclickjacking withUrl !s $HOME/.config/tridactyl/scripts/clickjacking | nativeopen
|
command testclickjacking withUrl !s $HOME/.config/tridactyl/scripts/clickjacking | nativeopen
|
||||||
command openwithbrave withUrl !s /usr/bin/brave
|
command openwithbrave withUrl !s /usr/bin/brave
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue