From fd8ee04dd4bc549f1e799d966126fadd0d6f6c3e Mon Sep 17 00:00:00 2001 From: sudo-julia Date: Tue, 29 Dec 2020 16:35:14 -0800 Subject: [PATCH 1/3] rofi launcher added, theme removed from dmenu --- dmenyt | 14 +++++++++----- myyt | 7 +++++-- rofyt | 25 +++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 7 deletions(-) create mode 100755 rofyt diff --git a/dmenyt b/dmenyt index 0706f63..5198009 100755 --- a/dmenyt +++ b/dmenyt @@ -1,21 +1,25 @@ #!/usr/bin/env bash +# if the query isn't provided as an arg, grab it with 'dmenu' if [[ -z "$1" ]]; then - printf "Search query: "; - query=$( echo | dmenu -p "Search YT Video:" ) + query=$( printf | dmenu -b -p "Search YouTube:" ) else query="$1" fi +# in the query, replace any spaces with '+' to match YouTube's search syntax query="${query// /+}" -echo "$query" -# YT_API_KEY location +# set the variable below to your API key if desired. +# YT_API_KEY="" +# otherwise, set your YT_API_KEY file location below YT_API_KEY="$( cat "${HOME}"/.api_keys/YT_API_KEY )" urlstring="https://www.googleapis.com/youtube/v3/search?part=snippet&q=${query}&type=video&maxResults=20&key=${YT_API_KEY}" +# get the video url by filtering the search results with 'jq' and sending them to dmenu +# the video chosen is then given to 'mpv' a url to stream from mpv "https://$( curl -s "${urlstring}" \ | jq -r '.items[] | "\(.snippet.channelTitle) => \(.snippet.title) => youtu.be/\(.id.videoId)"' \ - | dmenu -i -p 'Select Video -' -l 20 \ + | dmenu -b -i -p "Select Video -" -l 20 \ | awk '{print $NF}' \ )" diff --git a/myyt b/myyt index 1a55ad3..24cfcb7 100755 --- a/myyt +++ b/myyt @@ -1,18 +1,21 @@ #!/usr/bin/env bash +# if the query isn't provided as an arg, grab it with 'read' if [[ -z "$1" ]]; then - read -rp "Search query: " query + read -rp "Search YouTube: " query else query="$1" fi +# in the query, replace any spaces with '+' to match YouTube's search syntax query="${query// /+}" -echo "$query" # YT_API_KEY location YT_API_KEY="$( cat "${HOME}"/.api_keys/YT_API_KEY )" urlstring="https://www.googleapis.com/youtube/v3/search?part=snippet&q=${query}&type=video&maxResults=20&key=${YT_API_KEY}" +# get the video url by filtering the search results with 'jq' and sending them to 'fzf' +# the video chosen is then given to 'mpv' a url to stream from mpv "https://$( curl -s "${urlstring}" \ | jq -r '.items[] | "\(.snippet.channelTitle) => \(.snippet.title) youtu.be/\(.id.videoId)"' \ | fzf --with-nth='1..-2' +m \ diff --git a/rofyt b/rofyt new file mode 100755 index 0000000..205f5de --- /dev/null +++ b/rofyt @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +# if the query isn't provided as an arg, grab it with 'rofi' +if [[ -z "$1" ]]; then + query=$( echo "Search YouTube:" | rofi -dmenu ) +else + query="$1" +fi + +# in the query, replace any spaces with '+' to match YouTube's search syntax +query="${query// /+}" + +# set the variable below to your API key if desired. +# YT_API_KEY="" +# otherwise, set your YT_API_KEY file location below +YT_API_KEY="$( cat "${HOME}"/.api_keys/YT_API_KEY )" +urlstring="https://www.googleapis.com/youtube/v3/search?part=snippet&q=${query}&type=video&maxResults=20&key=${YT_API_KEY}" + +# get the video url by filtering the search results with 'jq' and sending them to 'rofi' +# the video chosen is then given to 'mpv' a url to stream from +mpv "https://$( curl -s "${urlstring}" \ + | jq -r '.items[] | "\(.snippet.channelTitle) => \(.snippet.title) => youtu.be/\(.id.videoId)"' \ + | rofi -dmenu \ + | awk '{print $NF}' \ +)" From 637696cc9242723985b0ee9c68ddcd490981d815 Mon Sep 17 00:00:00 2001 From: sudo-julia Date: Wed, 30 Dec 2020 12:33:13 -0800 Subject: [PATCH 2/3] checks before querying and streaming with mpv --- .gitignore | 1 + dmenyt | 24 ++++++++++++++++++------ myyt | 22 +++++++++++++++++----- rofyt | 24 ++++++++++++++++++------ 4 files changed, 54 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 6dbfc50..89faa8b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +mydyt YT_API_KEY diff --git a/dmenyt b/dmenyt index 5198009..c1af09e 100755 --- a/dmenyt +++ b/dmenyt @@ -2,13 +2,17 @@ # if the query isn't provided as an arg, grab it with 'dmenu' if [[ -z "$1" ]]; then - query=$( printf | dmenu -b -p "Search YouTube:" ) + query=$( printf "" | dmenu -b -p "Search YouTube:" ) else query="$1" fi -# in the query, replace any spaces with '+' to match YouTube's search syntax -query="${query// /+}" +# if query was given, replace any spaces with '+' to match YouTube's search syntax +if [[ "${query}" ]]; then + query="${query// /+}" +else + echo "No query given. Exiting."; exit 1 +fi # set the variable below to your API key if desired. # YT_API_KEY="" @@ -16,10 +20,18 @@ query="${query// /+}" YT_API_KEY="$( cat "${HOME}"/.api_keys/YT_API_KEY )" urlstring="https://www.googleapis.com/youtube/v3/search?part=snippet&q=${query}&type=video&maxResults=20&key=${YT_API_KEY}" -# get the video url by filtering the search results with 'jq' and sending them to dmenu -# the video chosen is then given to 'mpv' a url to stream from -mpv "https://$( curl -s "${urlstring}" \ +# get the video url by filtering the search results with 'jq' and sending them to 'dmenu' +# the url of the video chosen is then given to 'mpv' +video="$( curl -s "${urlstring}" \ | jq -r '.items[] | "\(.snippet.channelTitle) => \(.snippet.title) => youtu.be/\(.id.videoId)"' \ | dmenu -b -i -p "Select Video -" -l 20 \ | awk '{print $NF}' \ )" + +if [[ "${video}" ]]; then + video="https://${video}" +else + echo "No video selected. Exiting."; exit 1 +fi + +mpv -- "${video}" diff --git a/myyt b/myyt index 24cfcb7..c3ae27e 100755 --- a/myyt +++ b/myyt @@ -7,17 +7,29 @@ else query="$1" fi -# in the query, replace any spaces with '+' to match YouTube's search syntax -query="${query// /+}" +# if query was given, replace any spaces with '+' to match YouTube's search syntax +if [[ "${query}" ]]; then + query="${query// /+}" +else + echo "No query given. Exiting."; exit 1 +fi # YT_API_KEY location YT_API_KEY="$( cat "${HOME}"/.api_keys/YT_API_KEY )" urlstring="https://www.googleapis.com/youtube/v3/search?part=snippet&q=${query}&type=video&maxResults=20&key=${YT_API_KEY}" # get the video url by filtering the search results with 'jq' and sending them to 'fzf' -# the video chosen is then given to 'mpv' a url to stream from -mpv "https://$( curl -s "${urlstring}" \ +# the url of the video chosen is then given to 'mpv' +video="$( curl -s "${urlstring}" \ | jq -r '.items[] | "\(.snippet.channelTitle) => \(.snippet.title) youtu.be/\(.id.videoId)"' \ - | fzf --with-nth='1..-2' +m \ + | fzf --with-nth='1..-2' +m --height=50% \ | awk '{print $NF}' \ )" + +if [[ "${video}" ]]; then + video="https://${video}" +else + echo "No video selected. Exiting."; exit 1 +fi + +mpv -- "${video}" diff --git a/rofyt b/rofyt index 205f5de..5c574d3 100755 --- a/rofyt +++ b/rofyt @@ -2,13 +2,17 @@ # if the query isn't provided as an arg, grab it with 'rofi' if [[ -z "$1" ]]; then - query=$( echo "Search YouTube:" | rofi -dmenu ) + query=$( rofi -dmenu -mesg "Search YouTube" -matching "fuzzy") else query="$1" fi -# in the query, replace any spaces with '+' to match YouTube's search syntax -query="${query// /+}" +# if query was given, replace any spaces with '+' to match YouTube's search syntax +if [[ "${query}" ]]; then + query="${query// /+}" +else + echo "No query given. Exiting."; exit 1 +fi # set the variable below to your API key if desired. # YT_API_KEY="" @@ -16,10 +20,18 @@ query="${query// /+}" YT_API_KEY="$( cat "${HOME}"/.api_keys/YT_API_KEY )" urlstring="https://www.googleapis.com/youtube/v3/search?part=snippet&q=${query}&type=video&maxResults=20&key=${YT_API_KEY}" -# get the video url by filtering the search results with 'jq' and sending them to 'rofi' -# the video chosen is then given to 'mpv' a url to stream from -mpv "https://$( curl -s "${urlstring}" \ +# get the video url by filtering the search results with 'jq' and sending them to dmenu +# the url of the video chosen is then given to 'mpv' +video="$( curl -s "${urlstring}" \ | jq -r '.items[] | "\(.snippet.channelTitle) => \(.snippet.title) => youtu.be/\(.id.videoId)"' \ | rofi -dmenu \ | awk '{print $NF}' \ )" + +if [[ "${video}" ]]; then + video="https://${video}" +else + echo "No video selected. Exiting."; exit 1 +fi + +mpv -- "${video}" From 7291cce1dc3f68c42047a67b2bc9eaaec25375a5 Mon Sep 17 00:00:00 2001 From: sudo-julia Date: Mon, 7 Jun 2021 13:24:40 -0700 Subject: [PATCH 3/3] if-statements condensed --- dmenyt | 18 ++++++------------ myyt | 20 +++++++------------- rofyt | 22 ++++++++-------------- 3 files changed, 21 insertions(+), 39 deletions(-) diff --git a/dmenyt b/dmenyt index c1af09e..f9947e1 100755 --- a/dmenyt +++ b/dmenyt @@ -8,16 +8,13 @@ else fi # if query was given, replace any spaces with '+' to match YouTube's search syntax -if [[ "${query}" ]]; then - query="${query// /+}" -else - echo "No query given. Exiting."; exit 1 -fi +[ -z "${query}" ] && echo "No query given. Exiting." && exit 1 +query="${query// /+}" # set the variable below to your API key if desired. # YT_API_KEY="" # otherwise, set your YT_API_KEY file location below -YT_API_KEY="$( cat "${HOME}"/.api_keys/YT_API_KEY )" +YT_API_KEY="$( cat "${HOME}/lib/api_keys/YT_API_KEY" )" urlstring="https://www.googleapis.com/youtube/v3/search?part=snippet&q=${query}&type=video&maxResults=20&key=${YT_API_KEY}" # get the video url by filtering the search results with 'jq' and sending them to 'dmenu' @@ -28,10 +25,7 @@ video="$( curl -s "${urlstring}" \ | awk '{print $NF}' \ )" -if [[ "${video}" ]]; then - video="https://${video}" -else - echo "No video selected. Exiting."; exit 1 -fi +[ -z "${video}" ] && echo "No video selected. Exiting." && exit 1 +video="https://${video}" -mpv -- "${video}" +mpv --no-terminal -- "${video}" diff --git a/myyt b/myyt index c3ae27e..f6c8ea6 100755 --- a/myyt +++ b/myyt @@ -8,28 +8,22 @@ else fi # if query was given, replace any spaces with '+' to match YouTube's search syntax -if [[ "${query}" ]]; then - query="${query// /+}" -else - echo "No query given. Exiting."; exit 1 -fi +[ -z "${query}" ] && echo "No query given. Exiting." && exit 1 +query="${query// /+}" # YT_API_KEY location -YT_API_KEY="$( cat "${HOME}"/.api_keys/YT_API_KEY )" +YT_API_KEY="$( cat "${HOME}/lib/api_keys/YT_API_KEY" )" urlstring="https://www.googleapis.com/youtube/v3/search?part=snippet&q=${query}&type=video&maxResults=20&key=${YT_API_KEY}" # get the video url by filtering the search results with 'jq' and sending them to 'fzf' # the url of the video chosen is then given to 'mpv' video="$( curl -s "${urlstring}" \ | jq -r '.items[] | "\(.snippet.channelTitle) => \(.snippet.title) youtu.be/\(.id.videoId)"' \ - | fzf --with-nth='1..-2' +m --height=50% \ + | fzf --with-nth='1..-2' +m --height=82% \ | awk '{print $NF}' \ )" -if [[ "${video}" ]]; then - video="https://${video}" -else - echo "No video selected. Exiting."; exit 1 -fi +[ -z "${video}" ] && echo "No video selected. Exiting." && exit 1 +video="https://${video}" -mpv -- "${video}" +mpv --no-terminal -- "${video}" diff --git a/rofyt b/rofyt index 5c574d3..4d35ca0 100755 --- a/rofyt +++ b/rofyt @@ -2,36 +2,30 @@ # if the query isn't provided as an arg, grab it with 'rofi' if [[ -z "$1" ]]; then - query=$( rofi -dmenu -mesg "Search YouTube" -matching "fuzzy") + query=$( rofi -dmenu -mesg "Search YouTube" ) else query="$1" fi # if query was given, replace any spaces with '+' to match YouTube's search syntax -if [[ "${query}" ]]; then - query="${query// /+}" -else - echo "No query given. Exiting."; exit 1 -fi +[ -z "${query}" ] && echo "No query given. Exiting." && exit 1 +query="${query// /+}" # set the variable below to your API key if desired. # YT_API_KEY="" # otherwise, set your YT_API_KEY file location below -YT_API_KEY="$( cat "${HOME}"/.api_keys/YT_API_KEY )" +YT_API_KEY="$( cat "${HOME}/lib/api_keys/YT_API_KEY" )" urlstring="https://www.googleapis.com/youtube/v3/search?part=snippet&q=${query}&type=video&maxResults=20&key=${YT_API_KEY}" # get the video url by filtering the search results with 'jq' and sending them to dmenu # the url of the video chosen is then given to 'mpv' video="$( curl -s "${urlstring}" \ | jq -r '.items[] | "\(.snippet.channelTitle) => \(.snippet.title) => youtu.be/\(.id.videoId)"' \ - | rofi -dmenu \ + | rofi -dmenu -i \ | awk '{print $NF}' \ )" -if [[ "${video}" ]]; then - video="https://${video}" -else - echo "No video selected. Exiting."; exit 1 -fi +[ -z "${video}" ] && echo "No video selected. Exiting." && exit 1 +video="https://${video}" -mpv -- "${video}" +mpv --no-terminal -- "${video}"