├── .gitignore ├── README.md ├── dmenyt └── myyt /.gitignore: -------------------------------------------------------------------------------- 1 | YT_API_KEY 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # myyt 2 | 3 | Script I wrote to search youtube with command line easily. 4 | 5 | ## Requirements 6 | 7 | You need to set the environment variable `YT_API_KEY` to the value of the token. 8 | 9 | See [tutorial](https://elfsight.com/blog/2016/12/how-to-get-youtube-api-key-tutorial/) on the API key if you need help, or [start directly in the console](https://console.developers.google.com/apis/library?filter=category:youtube) if you are familiar with the platform. 10 | 11 | Install the required programs: `fzf`, `dmenu`, `mpv` `jq`, `awk` and `youtube-dl`. 12 | 13 | [See video for futher detail](https://www.youtube.com/watch?v=gghEFDO3Tbc) 14 | -------------------------------------------------------------------------------- /dmenyt: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ -z "$1" ]]; then 4 | printf "Search query: "; 5 | query=$( echo | dmenu -p "Search YT Video:" ) 6 | else 7 | query="$1" 8 | fi 9 | 10 | query="${query// /+}" 11 | echo "$query" 12 | 13 | # YT_API_KEY location 14 | YT_API_KEY="$( cat "${HOME}"/.api_keys/YT_API_KEY )" 15 | urlstring="https://www.googleapis.com/youtube/v3/search?part=snippet&q=${query}&type=video&maxResults=20&key=${YT_API_KEY}" 16 | 17 | mpv "https://$( curl -s "${urlstring}" \ 18 | | jq -r '.items[] | "\(.snippet.channelTitle) => \(.snippet.title) => youtu.be/\(.id.videoId)"' \ 19 | | dmenu -i -p 'Select Video -' -l 20 \ 20 | | awk '{print $NF}' \ 21 | )" 22 | -------------------------------------------------------------------------------- /myyt: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ -z "$1" ]]; then 4 | read -rp "Search query: " query 5 | else 6 | query="$1" 7 | fi 8 | 9 | query="${query// /+}" 10 | echo "$query" 11 | 12 | # YT_API_KEY location 13 | YT_API_KEY="$( cat "${HOME}"/.api_keys/YT_API_KEY )" 14 | urlstring="https://www.googleapis.com/youtube/v3/search?part=snippet&q=${query}&type=video&maxResults=20&key=${YT_API_KEY}" 15 | 16 | mpv "https://$( curl -s "${urlstring}" \ 17 | | jq -r '.items[] | "\(.snippet.channelTitle) => \(.snippet.title) youtu.be/\(.id.videoId)"' \ 18 | | fzf --with-nth='1..-2' +m \ 19 | | awk '{print $NF}' \ 20 | )" 21 | --------------------------------------------------------------------------------