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"'\'' {}' |\
|
||||
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}"
|
||||
|
||||
case "$url" in
|
||||
*"//invidious.*/"*) open-youtube "$url"; exit 0 ;;
|
||||
*//*.youtube.*/*) open-youtube "$url"; exit 0 ;;
|
||||
*"//videos.*"*) open-youtube "$url"; exit 0 ;;
|
||||
*"//invidious.*/"*) yt --url "$url"; exit 0 ;;
|
||||
*//*.youtube.*/*) yt --url "$url"; exit 0 ;;
|
||||
*"//videos.*"*) yt --url "$url"; exit 0 ;;
|
||||
*"//xkcd.com/"*) xkcd "$url"; exit 0 ;;
|
||||
"mailto:"*) neomutt "$url"; exit 0 ;;
|
||||
*) $browser "$url"; exit 0 ;;
|
||||
|
|
75
bin/.bin/yt
75
bin/.bin/yt
|
@ -2,10 +2,13 @@
|
|||
|
||||
# Requires:
|
||||
# * curl
|
||||
# * fzf
|
||||
# * fzf | rofi
|
||||
# * jq
|
||||
# * hq
|
||||
# * youtube-dl
|
||||
# * hq | pup (recomended, although optional)
|
||||
|
||||
rofi="auto"
|
||||
|
||||
ttyecho(){
|
||||
# Same as echo but always to tty
|
||||
echo "$@" > /dev/tty
|
||||
|
@ -42,7 +45,21 @@ forceread(){
|
|||
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(){
|
||||
if useRofi; then
|
||||
# Rofi can't reload the suggestions so just display a search box
|
||||
echo "" | rofi -dmenu -lines 0
|
||||
else
|
||||
# Uses fzf to get a search term
|
||||
# It will filter suggestions using youtube's autocomplete
|
||||
export -f getSearchSuggestions
|
||||
|
@ -51,6 +68,7 @@ getSearchTerm(){
|
|||
--header="Search Suggestions" \
|
||||
--phony \
|
||||
--height=50% --layout=reverse
|
||||
fi
|
||||
}
|
||||
|
||||
getSearchSuggestions(){
|
||||
|
@ -86,18 +104,35 @@ jq '..|.videoRenderer?' | sed '/^null$/d' |
|
|||
}
|
||||
|
||||
chooseVideo(){
|
||||
if useRofi; then
|
||||
( jq -r '[ .title, .channel, .views, .time, .age, .video ] | @tsv') |
|
||||
column -t -s" " | sed $'s/ \([^ ]\)/\u00a0\\1/g' |
|
||||
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(){
|
||||
if [ -n "$1" ]; then
|
||||
videoId="$1"
|
||||
else
|
||||
videoId="$(cat - | awk -F $'\u00a0' '{print $6}')"
|
||||
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/+$//')"
|
||||
|
||||
|
@ -107,12 +142,46 @@ chooseQuality(){
|
|||
esac
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
|
||||
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="$*"
|
||||
|
||||
[ -z "$searchTerm" ] && searchTerm="$(getSearchTerm)"
|
||||
|
||||
performSearch "$searchTerm" | extractVideoInfo | chooseVideo | chooseQuality
|
||||
|
||||
fi
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
|
|
@ -45,8 +45,8 @@ set searchurls.audio https://www.google.com/search?hl=en&ei=cSj3X5L0HYXykwXRpKvY
|
|||
""""""""""""""
|
||||
|
||||
command withUrl composite get_current_url |
|
||||
command openvid withUrl !s open-youtube
|
||||
command openvidLink composite hint -pipe a[href]:not([display="none"]):not([href=""]) href | !s open-youtube
|
||||
command openvid withUrl !s yt --url
|
||||
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 openwithbrave withUrl !s /usr/bin/brave
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue