bugswriter / myyt Goto Github PK
View Code? Open in Web Editor NEWScript I wrote to search youtube with command line easily.
Script I wrote to search youtube with command line easily.
Hi Bugswriter, thanks for the script!
When running ./dmenyt or ./myyt it prompts for the search query. Regardless of what I enter I receive the syntax error
$ ./myyt
Search query: test
./myyt: 9: Syntax error: redirection unexpected
Dependencies:
fzf is already the newest version (0.20.0-1).
mpv is already the newest version (0.32.0-1ubuntu1).
suckless-tools is already the newest version (44-1). [This contains dmenu]
youtube-dl is already the newest version (2020.03.24-1).
API key is properly inserted as variable in terminal,
output of echo:
user@desktop$: echo $YT_API_KEY
AIzaSyB-rGfbeC2w8dMxxxxxxx
I'll explain the title here. So when the script is invoked with the standard dmenu_run script, everything works fine but with my dmenu script which should basically work the same way as the former, I get this error from jq:
jq: error (at <stdin>:14): can't iterate over null (null)
How I found out about this bug is that if I run your two scripts in the terminal, it works as expected but when I put a key binding in the header file for dwm, I was getting empty prompts i.e. the search results weren't being displayed. And apparently that was happening because of the fq error.
The only workaround I have right now is to invoke the standard dmenu_run script, type your script's name and do the search from there.
Since this is a new project, the issues are expected. However, your script is very helpful. Thanks.
Also, please check this video.
All the requirements are fulfilled.
Since using Youtoube API for simple search seems like too much trouble (and is limited in the number of uses anyways), why not use a webpage scraper?
By a quick google, I found youtube-search (pip3 install youtube-search
), and I changed the bash script to use the following python script instead of querying youtube API:
#!/usr/bin/env python3
from youtube_search import YoutubeSearch
from sys import argv
search_terms = str(argv)
results=YoutubeSearch(search_terms, max_results=10).to_dict()
urlString = '\n'.join((r['title']+' '+r['id'] for r in results))
print(urlString)
main bash lines then become:
urlstring=$(./new_python_script_name.py "${query}")
mpv "https://youtu.be/$( echo "${urlstring}" \
| fzf --with-nth='1..-2' +m \
| awk '{print $NF}' \
)"
It works great for me. It does require some polishing regarding the location of both scripts which influences how you call python from bash etc. The two scripts could probably be even merged into one (heredocs in bash or use python to call fzf and mpv) for extra points :)
So I'm just leaving this idea here with you, if I ever foolproof it, I'l turn it into a merge request.
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.