pystardust / ytfzf Goto Github PK
View Code? Open in Web Editor NEWA posix script to find and watch youtube videos from the terminal. (Without API)
License: GNU General Public License v3.0
A posix script to find and watch youtube videos from the terminal. (Without API)
License: GNU General Public License v3.0
I just installed ytfzf from the AUR via yay -s ytfzf
.
First attempt to run it got me an error message that fzf is missing. So I installed the optional fzf and ueberzug, since thumbnails seem nice to have.
Downloading thumbnails and selecting a video via the fuzzy search and arrow keys works great, but as I hit enter I get this:
$ ytfzf -t rickroll
Downloading Thumbnails............................
mpv 0.33.0-dirty Copyright © 2000-2020 mpv/MPlayer/mplayer2 projects
built on UNKNOWN
FFmpeg library versions:
libavutil 56.51.100
libavcodec 58.91.100
libavformat 58.45.100
libswscale 5.7.100
libavfilter 7.85.100
libswresample 3.7.100
FFmpeg version: n4.3.1
Usage: mpv [options] [url|path/]filename
Basic options:
--start=<time> seek to given (percent, seconds, or hh:mm:ss) position
--no-audio do not play sound
--no-video do not play video
--fs fullscreen playback
--sub-file=<file> specify subtitle file to use
--playlist=<file> specify playlist file
--list-options list all mpv options
--h=<string> print options which contain the given string in their name
I am on arch and using ytfzf from bash in xfce4-terminal emulator.
$ uname -a
Linux archws 5.11.1-arch1-1 #1 SMP PREEMPT Tue, 23 Feb 2021 14:05:30 +0000 x86_64 GNU/Linux
I'm on Catalina(still) and had been a user of the one liner version of the script. I upgraded to the newer style and now when I try and view videos i get this:
➜ ytfzf git:(master) ytfzf "nintendo"
2021-03-03 11:38:20.166 mpv[80733:9519816] This NSLayoutConstraint is being configured with a constant that exceeds internal limits. A smaller value will be substituted, but this problem should be fixed. Break on BOOL _NSLayoutConstraintNumberExceedsLimit(void) to debug. This will be logged only once. This may break in the future.
Playing: h
[file] Cannot open file 'h': No such file or directory
Failed to open h.Playing:
[file] Cannot open file '': No such file or directory
Failed to open .Playing: ps://www.you
No protocol handler found to open URL ps://www.you
The protocol is either unsupported, or was disabled at compile-time.Playing: ube.com/wa
[file] Cannot open file 'ube.com/wa': No such file or directory
Failed to open ube.com/wa.Playing: ch?v=Super Smash Bros. Ul
[file] Cannot open file 'ch?v=Super Smash Bros. Ul': No such file or directory
Failed to open ch?v=Super Smash Bros. Ul.Playing: ima
[file] Cannot open file 'ima': No such file or directory
Failed to open ima.Playing: e - Mr. Sakurai Presen
[file] Cannot open file 'e - Mr. Sakurai Presen': No such file or directory
Failed to open e - Mr. Sakurai Presen.Playing: s
[file] Cannot open file 's': No such file or directory
Failed to open s.Exiting... (Errors when loading file)
ERROR[#3]: Couldn't play the video/audio using the current player: mpv
Try updating youtube-dl
Check for new versions and report at: https://github.com/pystardust/ytfzf
I've tried it on both iTerm and the vanilla Terminal program. I've also tried both bash and zsh. I used the MacOS install instructions listed in the README file.
It lets me browse and select videos. But once I select one it errors out as above.
EDIT
It looks like the error is coming from mpv(0.33.0).
main
doing in lines 43
and 68-69
? Is that really necessary?*_len
variables if it isn't required if I use your -a
flag to autoplay stuff, since I'm not displaying the names. Are any of these required nonetheless for searching the video or playing it, or can I just remove them? (I removed the fzf parts already btw)maybe an option check subtitles ?
Output currently playing video info so another status indicator can extract and show it
Below is my poor way of doing that
#PLAY
current_playing_info=~/.cache/ytfzf_cur # File location
printf "%s" "$selected_data" > "$current_playing_info" ; # Write data to the file
[ -n "$preferred_format" ] &&...
...
#QUIT
printf "" > "$current_playing_info"; # Blank the file when quit player
[ $save_history -eq 1 ] && printf "%s\n" "$selected_data" >> "$history_file" ;
Just to make you aware of this, preview of thumbnails doesn't work on macOS. The script download the images were it should, but it doesn't show them. It looks like the problem has to do with Überzug. I also tried to run fontpreview-ueberzug which won't work either. But I might also be wrong so if other people have mac they might be helpful. I also tried to used Überzug to preview images in ranger and It doesn't work. In ranger they use a preview for that works with iTerm terminal emulator. An example is imgcat
Thanks for the script, it is really cool!
Would it be possible to implement to dump the video stream into a file?
Is there a website for this project? If not, will you make it?
It's pretty simple these days:
pystardust.github.io
Github Pages
sectionChoose Theme
README.md
to index.md
in the newly created gh-pages
branchIf you don't want to or can't invest too much time into this, then I can do it. I want to contribute more but since I can't code sh
very well, I can at least do this simple thing :3
I think if you just do steps 2-4 (for both this repo and pystardust.github.io
) then I can fork the gh-pages
branch, do the rest, then make a pull request if you want.
Please include in the search result also videos from Sepia Search (PeerTube) as a alternative way to find great FLOSS Videos.
Thumbnails do not display in Wayland using a normal terminal emulator due to ueberzug relying on X. This is obviously an upstream issue but something I feel is worth mentioning. For example gnome-terminal does not work.
I tested in kittyhowever, which has its own image protocol and it does work, but in 99% of terminals it will likely not work by default.
MacOS "ytfzf -H" "/usr/local/bin/ytfzf: line 596: tac: command not found"
Since there is no "tac" in MacOS, replacing line number 596
hist_data="$(tac "$history_file")"
with
hist_data="$(tail -r "$history_file")"
fix the issue.
Also there is "tac" in line number 534, but I'm not sure if fixing this will brake the functionality or not.
Could you please test it?
Thanks!
I am getting the following error when using the -t option
ytfzf -t funny
Downloading Thumbnails................................
invalid preview window layout: left:50%:noborder:wrap
I tried it in mate-terminal and guake. Same error
thank you for taking a moment to read this.
I love the script, but at least for me, YT API is way faster than using only youtube-dl. It would be lovely to have an option like that or even just enabling it in the script itself.
Hi! Is it possible to add standard input (if not already done) to be used in other scripts?
Great project btw :-)
➜ ~ ytfzf test
[ytdl_hook] ERROR: QZ36oaXHkOU: YouTube said: Unable to extract video data
[ytdl_hook] youtube-dl failed: unexpected error occurred
Failed to recognize file format.
Exiting... (Errors when loading file)
ERROR[#3]: Couldn't play the video/audio using the current player: mpv
Try updating youtube-dl
Check for new versions and report at: https://github.com/pystardust/ytfzf
I just installed this program after I saw its showcase on reddit.com/r/unixporn
I followed all the installation instructions and installed all of the dependencies. I also got the most up to date verison of youtube-dl.
Not sure what the error means.
Here is the video I was trying to watch: https://www.youtube.com/watch?v=mAFMJ1LnQu8
Downloading Thumbnails................................
[ytdl_hook] ERROR: mAFMJ1LnQu8: YouTube said: Unable to extract video data
[ytdl_hook] youtube-dl failed: unexpected error occurred
Failed to recognize file format.
Exiting... (Errors when loading file)
ERROR[#3]: Couldn't play the video/audio using the current player: mpv
Try updating youtube-dl
Check for new versions and report at: https://github.com/pystardust/ytfzf
Hi
Thank you for making ytfzf. Really enjoying it!
Subscriptions would make it even more powerful. Could be a simple text file with channels in it and a command to view the latest videos.
Cheers
Johannes
I edited line 259 to
preview window "left"
After which I now have tab view but the thumbnail preview won't work.
Here's some extra info
I have ueberzug running I'm using it with ranger. Also tried it with the ueberzug script and it works.
Any help is appreciated.
I am on bspwm. MX linux debian buster 10. I have no swallow like behaviour.
Tried in urxvt,termite,roxterm and xfce4-terminal
Don't you think it is "too arch specific"?? And the whole world is not running Arch alone.So , please.
Oh Btw, appreciate your effort.
Specifically change the functionality of "pup" to equivalent generic thing.
Just a thought.
Amazing script.
the -D -t switch doesn't work.
I guess thats too much for dmenu.
Also uberzug has this bug that the thumbnail doesnt get deleted or updated once it was cached.
Have a look at lfimg and lf-ueberzug here in git they found a solution for the file manager lf + ueberzug.
hmmm was a one time thing I guess ... not doing it anymore ... you are very fast :)
I usually want to show thumbnails, so i aliased ytfzf="ytfzf -t"
in my .zshrc to not always having to add the -t
. Now it always takes up 1-2s to download them, even when I run ytfzf with -a
, which is useless. It would be nice if ytfzf would download the thumbnails only when a fzf menu is going to be opened.
Liked your project very much.
Can you add caption feature ?
I have the habit of reading through the comments after watching a video.
Would it be possible to add this option? Perhaps put the comments into stout or a file? That would be a real game-changer for me. Thanks for the AMAZING work!
Line 352, doesn't parse "\n"s which results in exporting empty lines to ytfzf_hst ytfzf_cur
selected_data="$(echo "$selected_data" | sed 1d )"
Working (in both dash and bash under linux) solution is to change the 'echo' to 'printf' OR to use 'echo -e' whenever backslash escapes need to be parsed.
Hi, I'd like to be able to do something like this (to only have one shortcut to invoke rofi
):
rofi -modi run,file-browser,"CALC:qalc +u8","youtube:/usr/bin/ytfzf -D" \
-show run \
-display-drun "Run" \
-display-file-browser FILES \
-display-run SHELL \
-columns 2
As I am switching modes I get an error message for ytfzf
"Do not launch..". I am not sure if it's possible to achieve this functionality but it would be great if that's possible. Thanks.
By default the maximum results I get are around 30 to 40. How do I increase this list number?
some videos won't play:
[ytdl_hook] ERROR: requested format not available
[ytdl_hook] youtube-dl failed: unexpected error occurred
Failed to recognize file format.
Exiting... (Errors when loading file)
ERROR[#3]: Couldn't play the video/audio using the current player.
Try updating youtube-dl
Hi, great project.
Could i use this on Windows machine ?
Currently, the default number of search results seems to be some number less than 40. I think an option in conf.sh
could be added to include a user-defined number of search results.
Currently the previews are on the left and fzf on right. An option to swap the two would be nice. Thanks!
Hi everyone, I need some suggestions and help to implement thumbnails.
Here is what I am able to do so far
Drawbacks : It doesn't look clean, as it is using 2 separate windows.
Feel free to share you ideas on how you would like thumnails implemented.
I can always fallback to a filemanager (like ranger, lf) which will make life much easier.
It would be nice if the dependencies are available in standard debian and arch repos.
Hello there. This is a real nice script, but I'd like to have it play the first result automatically without me needing to press enter (assume that I'm satisfied with the first result, regardless of accuracy). Can this be done currently via flags (I don't see it in the docs) or via some shell syntax magic? If so then could you please let me know how?
I only tried ytfz -m <search-query> <<< printf "\n"
and that didn't work (I thought it'd automatically press Enter after search).
PS: I use zsh
but I have bash
installed for scripts, so either syntax suggestion is welcome. Thank you.
Thumbnails do not show properly if more than one session with thumbnails enabled exists on the system.
The issue probably originates from the hard-coded variables for ueberzug (line 230-232).
I've got ytfzf from AUR and this is the output:
ytfzf -D starboy
usage: dmenu [-bvcfsxF] [-l lines] [-p prompt] [-fn font] [-m monitor]
[-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]
[-bw width] [-hb color] [-hf color] [-hp items] [-h height]
[-nhb color] [-nhf color] [-shb color] [-shf color]
Usage: ytfzf
ytfzf -h # to show help text
Hi. First, thank you for sharing your ytfzf script.
It would be useful to be able to return to the search result after the video is over.
That way we dont have to send search request to youtube over and over for the same search.
Same like yt does it.
Optional: run ytfzf with rofi/dmenu. Would be nice to be able to use ytfzf with rofi or dmenu.
I like using the following in my default opts: FZF_DEFAULT_OPTS="--bind=ctrl-a:select-all,ctrl-d:deselect-all,ctrl-t:toggle-all"
, but I noticed they weren't taking when I added them to the script. $FZF_DEFAULT_OPTS
needs to be referenced in the following functions:
format_menu () {
if [ $is_ext_menu -eq 0 ]; then
dep_ck "fzf"
++ prompt_menu='fzf -m --bind change:top --tabstop=1 --layout=reverse --delimiter="$(printf "\t")" --nth=1,2 $FZF_DEFAULT_OPTS'
-- prompt_menu='fzf -m --bind change:top --tabstop=1 --layout=reverse --delimiter="$(printf "\t")" --nth=1,2'
video_menu_img () {
title_len=400
format_awk | fzf -m --tabstop=1 --bind change:top --delimiter="$(printf "\t")" --nth=1,2 \
--layout=reverse --preview "sh $0 -U {}" \
++ --preview-window "left:50%:noborder:wrap" $FZF_DEFAULT_OPTS
-- --preview-window "left:50%:noborder:wrap" $FZF_DEFAULT_OPTS
}
Under "Currently Playing" section the file location should be
~/.cache/ytfzf/ytfzf_cur
instead ~/.cache/ytfzf/ytfzf_hst
I'm running. Ubuntu 20.04. The column command doesn't have an 'o' flag it seems. I even checked the man pages. I'm not sure how you got this working that case. Maybe consider using awk instead?
column: invalid option -- 'o'
usage: column [-txne] [-c columns] [-s sep] [file ...]
No results found. Try different keywords.
Check for new versions and report at: https://github.com/pystardust/ytfzf
I want to add a cooler looking gif to the readme.
I am not very good at ricing.
It would be really nice if someone with a really cool rice makes a gif 😎
@westofer
Please consider adding a flag to loop the currently playing song until the user presses q
to quit mpv
. mpv
has a --loop
flag for that, so I'm assuming you need only to call that flag in your script when passed a custom loop flag.
Could an option to configure the video player be added? I am using devour to swallow the terminal window of mpv. So being able to do something like ytfzf -p "devour mpv"
would be fantastic. Thanks!
Hi,
really great work! I like it! :)
I was playing around with mpc, and I got the following command:
youtube-dl -f bestaudio -g uIphNGLBeZQ | mpc add
It works, with mpc play
it plays the song.
But I can not find the way to use it with ytfzf. Could you help?
Thx,
Thomas
What is the last colume F=$url [0jfa008004eh] displayed for?
Very nice script by the way, Thanks
This is not an issue: just an appreciation. I can now watch YT on repeat without leaving my work.
You guys are Gods among men!
Much appreciated!
May I know is it supposed to work for win10 WSL? :)
After many dependency installations, when I type ytfzf
then I got this output.
Only ytfzf -h
works for me.
Getting the following error on macOS 10.14.6
$> ytfzf test string
parse error: Invalid numeric literal at line 1, column 17
No results found. Try different keywords.
Check for new versions and report at: https://github.com/pystardust/ytfzf
Don't have enough experience to debug further. Would appreciate some help.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.