A POSIX script that helps you find Youtube videos (without API) and opens/downloads them using mpv/youtube-dl
These links will take you where you want to go with the snap of a finger
Usage instruction
Features
Examples
Dependencies
Installation
Configuration
External menu command (dmenu / rofi)
Initially this used to be a single line script.
#!/bin/sh
[ -z "$*" ] || curl "https://www.youtube.com/results" -s -G --data-urlencode "search_query=$*" | pup 'script' | grep "^ *var ytInitialData" | sed 's/^[^=]*=//g;s/;$//' | jq '..|.videoRenderer?' | sed '/^null$/d' | jq '.title.runs[0].text,.longBylineText.runs[0].text,.shortViewCountText.simpleText,.lengthText.simpleText,.publishedTimeText.simpleText,.videoId'| sed 's/^"//;s/"$//;s/\\"//g' | sed -E -n "s/(.{60}).*/\1/;N;s/\n(.{30}).*/\n\1/;N;N;N;N;s/\n/\t|/g;p" | column -t -s "$(printf "\t")" | fzf --delimiter='\|' --nth=1,2 | sed -E 's_.*\|([^|]*)$_https://www.youtube.com/watch?v=\1_' | xargs -r -I'{}' mpv {}
Basic Usage: ytfzf [OPTIONS] <search-query>
OPTIONS:
-h, --help Show this help text
-t, --thumbnails Show thumbnails (requires ueberzug)
Doesn't work with -H -D
-D, --ext-menu Use external menu(default dmenu) instead of fzf
-H, --choose-from-history Choose from history
-x, --clear-history Delete history
-m, --audio-only <search-query> Audio only (for music)
-d, --download <search-query> Download to current directory
-f <search-query> Show available formats before proceeding
-a, --auto-play <search-query> Auto play the first result, no selector
-r --random-play <search-query> Auto play a random result, no selector
-n, --video-count= <video-count> To specify number of videos to select with -a or -r
-l, --loop <search-query> Loop: prompt selector again after video ends
-s <search-query> After the video ends make another search
-L, --link-only <search-query> Prints the selected URL only, helpful for scripting
Use - instead of <search-query> for stdin
To quit the script you can press
ESC
or^C
in the video selection prompt.
To use dmenu with a custom width
YTFZF_EXTMENU_LEN=250 ytfzf -D
Videos can be selected using fzf, dmenu or rofi.
- Thumbnails
- History support
- Download support
- Format selection (and default formats)
- Queue multiple tracks (using fzf multiselection)
-
Search with Thumbnails
Find and watch videos with thumbnail previews
ytfzf -t <query>
-
Search without Thumbnails
Find and watch videos without thumbnail previews (good if are on MacOS for example)
ytfzf <query>
-
You can use multiple options together, here are some examples
-
Stream audio (music), and prompt as the music finishes
ytfzf -ml <query>
-
Download a video from your history
ytfzf -dH
-
Open using dmenu in a certain format
ytfzf -fD
-
-
If you started watching a video and you wish to change format then first hit Q to save position and quit mpv, then choose your format using
ytfzf -faH
- Use
f
for full screen - Use
J
for subtitles (also works with audio, if the music video has subtitles) - Use
L
for single-loop
- Now ytfzf can queue videos using fzf multiselect option. Press tab to select a video. All the videos will be lined up in mpv. Use
>
and<
to traverse them. - Make continuous queries with
-s
- Thumbnails! Using Ueberzug. Inspired by
fontpreview-ueberzug
. - added MacOS support
- Stdin can be taken by using
ytfzf -
, for both fzf and external menu.
Fzf is optional, you can use an external menu (like dmenu) with the -D
option (no thumbnail support).
mpv
youtube-dl
fzf
(Optional) - for menujq
- to parse jsonueberzug
(Optional) - for thumbnails
Thumbnails only work with fzf and Ueberzug as of now.
-
sudo pacman -S jq mpv youtube-dl fzf
For thumbnails
sudo pacman -S ueberzug
-
sudo apt install jq mpv youtube-dl fzf
For thumbnails
pip install ueberzug
Note youtube-dl is usually outdated in debian repos, I suggest getting it from youtube-dl github
-
brew install jq mpv youtube-dl fzf
At the moment thumbnail previews aren't working on MacOS
-
git clone https://github.com/pystardust/ytfzf cd ytfzf
-
sudo make install
-
sudo make uninstall
-
-
Arch users can install ytfzf from the AUR
yay -S ytfzf-git
-
Gentoo users can install ytfzf from the nitratesky overlay
eselect repository enable nitratesky emerge -a1 net-misc/ytfzf
Default configuration can be set in the configuration file ~/.config/ytfzf/conf.sh
or with environment variables.
-
YTFZF_HIST=0 # history is on by default it can be set to -> 0 history off, 1: history on YTFZF_LOOP=1 # if set to 1 it is on but normally it is off by default. Can be turned on using option -l YTFZF_PREF="bestvideo[height<=?1080]+bestaudio/best" YTFZF_ENABLE_FZF_DEFAULT_OPTS=1 # fzf colors are going to be the one from your fzf configuration
-
export YTFZF_HIST=0 # history is on by default it can be set to -> 0 history off, 1: history on export YTFZF_LOOP=1 # if set to 1 it is on but normally it is off by default. Can be turned on using option -l export YTFZF_PREF="bestvideo[height<=?1080]+bestaudio/best" export YTFZF_ENABLE_FZF_DEFAULT_OPTS=1 # fzf colors are going to be the one from your fzf configuration
-
YTFZF_HIST=0 YTFZF_PREF="bestvideo[height<=?1080]+bestaudio/best" ytfzf <query>
-
The setting in the config will always override environment variables. This command wouldn't function as expected if
YTFZF_HIST=1
was mentioned in the config file. -
The example shown above will launch ytfzf without including the video in your history and it will only display the best resolution available at 1080p or lower.
-
-
YTFZF_CACHE=~/.cache/ytfzf
You can modify the file location by changing the cache directory
-
If you prefer to watch Youtube videos with certain options without being prompted every single time you can use the following setting.
YTFZF_PREF="22"
If the preferred format is not available then it will revert back to auto selection. Documentation for ytdl formats
The currently supported ones are (dmenu / rofi)
-
ytfzf -D
By default the external menu is set to dmenu
dmenu -i -l 30
. You can modify this to use rofi by using the following settingsYTFZF_EXTMENU=' rofi -dmenu -fuzzy -width 1500'
I don't use rofi much, I would love to hear from any rofi user on better defaults.
-
Depending on you screen resolution and font size this may need to be modified.
-
First option
YTFZF_EXTMENU_LEN=180
-
Second option
YTFZF_EXTMENU_LEN=180 ytfzf -D
-
WARNING : dmenu doesn't behave well with some fonts. Expect it to be slow with fonts you don't have.
YTFZF
is on
by default. Stores the details of the currently playing track. Empty when nothing is playing. This could be used in status bar modules.
-
YTFZF_CUR=0
It will be stored in the ytfzf cache directory as
ytfzf_cur
By default, ytfzf uses mpv
. Custom player should have the ability to launch youtube links.
# example: using devour
FZF_PLAYER="devour mpv"
YTFZF_PLAYER_FORMAT="devour mpv --ytdl-format="
- Playlists
- Comments
- Icons
- dwm with swallow patch: Images don't render when looped (ie, option -l)
- Sometimes thumbnails may not get previewed. This is likely an issue with ueberzug itself. Try deleting
.Xauthority
and relogging.