Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
mydyt
YT_API_KEY
24 changes: 17 additions & 7 deletions dmenyt
Original file line number Diff line number Diff line change
@@ -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}"
19 changes: 14 additions & 5 deletions myyt
Original file line number Diff line number Diff line change
@@ -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}"
31 changes: 31 additions & 0 deletions rofyt
Original file line number Diff line number Diff line change
@@ -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}"