YouTube-Query.
Perform queries to youtube from the terminal.
Returns formatted output containing urls which can be used in scripts.
ytq <args> <query>
where:
- <args> : Arguments to
ytq
- <query> : Query string to send to YouTube.
Speed varies from 0.3 seconds to 0.5 seconds ( tested using
time
)
Default behavior is to simply list the first 15-20 results from youtube's search page.
To display in special formatting, for scripting however, as of now three options are available:
-
Raw (
-r
|--raw
)Format results in a handy way to be parsed by scripts. Lists results with a handy seperator (
┊
) that is less likely to appear in output. -
First only (
-f
|--first
)Useful when you don't want to process through the entire list and only want the first result.
-
No Title (
-not
|--no-title
)
Requirements:
- a menu selector (e.g GUI: dmenu, rofi, gmrun, etc , CLI: select, fzf, sk, etc)
Not required if you plan to use the
first-only
mode. - a media player (e.g mpv, vlc, etc)
EITHER: the media player being used needs streaming capabilities(especially the ability to stream from youtube)
OR: the video needs to be downloaded and then passed to the media player to run. A program like
youtube-dl
can be used to download the video.
Implementation:
-
Music Player ﱘ
Using
dmenu
+mpv
:Demonstration in progress :)
-
Video Streaming
Using
dmenu
+mpv
:Demonstration in progress :)
This is a simple program that fetches only the first 18 results and does not support multipage queries at the moment.
This program does not use the Google API to gather data, but rather relies on hacky html/json parsing to retrieve data and hence is limited in functionality and possibly prone to breaking if YouTube changes its response structure.
Why is it default behavior to list results in a non script friendly manner?
To verify if the internal parser is generating valid output.
So if any script breaks you can run ytq
with the same query to check,
if it is a problem with the script or the ytq
parser.
Why only 15-20 results? Why not more?
Under the hood ytq
does not use the Google API to get results, but rather relies on html that YouTube returns.
By default YouTube returns only 18 results and this is all that ytq
can parse at the moment.
Email me @ decentman
Happy querying !!!
-- decentman