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 0706f63..f9947e1 100755 --- a/dmenyt +++ b/dmenyt @@ -1,21 +1,31 @@ #!/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 +# if query was given, replace any spaces with '+' to match YouTube's search syntax +[ -z "${query}" ] && echo "No query given. Exiting." && exit 1 query="${query// /+}" -echo "$query" -# YT_API_KEY location -YT_API_KEY="$( cat "${HOME}"/.api_keys/YT_API_KEY )" +# 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}/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}" -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 -i -p 'Select Video -' -l 20 \ + | dmenu -b -i -p "Select Video -" -l 20 \ | awk '{print $NF}' \ )" + +[ -z "${video}" ] && echo "No video selected. Exiting." && exit 1 +video="https://${video}" + +mpv --no-terminal -- "${video}" diff --git a/myyt b/myyt index 1a55ad3..f6c8ea6 100755 --- a/myyt +++ b/myyt @@ -1,20 +1,29 @@ #!/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 +# if query was given, replace any spaces with '+' to match YouTube's search syntax +[ -z "${query}" ] && echo "No query given. Exiting." && exit 1 query="${query// /+}" -echo "$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}" -mpv "https://$( curl -s "${urlstring}" \ +# 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 \ + | fzf --with-nth='1..-2' +m --height=82% \ | awk '{print $NF}' \ )" + +[ -z "${video}" ] && echo "No video selected. Exiting." && exit 1 +video="https://${video}" + +mpv --no-terminal -- "${video}" diff --git a/rofyt b/rofyt new file mode 100755 index 0000000..4d35ca0 --- /dev/null +++ b/rofyt @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +# if the query isn't provided as an arg, grab it with 'rofi' +if [[ -z "$1" ]]; then + query=$( rofi -dmenu -mesg "Search YouTube" ) +else + query="$1" +fi + +# if query was given, replace any spaces with '+' to match YouTube's search syntax +[ -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}/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 -i \ + | awk '{print $NF}' \ +)" + +[ -z "${video}" ] && echo "No video selected. Exiting." && exit 1 +video="https://${video}" + +mpv --no-terminal -- "${video}"