change Org Mode indentation
This commit is contained in:
parent
79964ec0dd
commit
3f5211e0b1
1 changed files with 160 additions and 160 deletions
78
README.org
78
README.org
|
|
@ -1,27 +1,27 @@
|
|||
* tyt
|
||||
:PROPERTIES:
|
||||
:header-args: :tangle tyt :shebang "#!/bin/sh"
|
||||
:END:
|
||||
:PROPERTIES:
|
||||
:header-args: :tangle tyt :shebang "#!/bin/sh"
|
||||
:END:
|
||||
|
||||
Terminal YouTube (*tyt*) is a small bash script that lets you play YouTube videos by query from the command line.
|
||||
It is created via literate programming, you can find the code below.
|
||||
Terminal YouTube (*tyt*) is a small bash script that lets you play YouTube videos by query from the command line.
|
||||
It is created via literate programming, you can find the code below.
|
||||
|
||||
** Script
|
||||
*** Dependencies
|
||||
|
||||
The dependencies of the script are:
|
||||
The dependencies of the script are:
|
||||
|
||||
- [[https://stedolan.github.io/jq/][jq]]
|
||||
- [[https://mpv.io/][mpv]]
|
||||
- [[https://ytdl-org.github.io/youtube-dl/][youtube-dl]]
|
||||
- [[https://stedolan.github.io/jq/][jq]]
|
||||
- [[https://mpv.io/][mpv]]
|
||||
- [[https://ytdl-org.github.io/youtube-dl/][youtube-dl]]
|
||||
|
||||
Please make sure those are available on your system.
|
||||
If you are using the [[https://nixos.org/][Nix]] package manager, you can run =nix-shell= in the project directory.
|
||||
This will drop you into a shell with all requirements fulfilled.
|
||||
Please make sure those are available on your system.
|
||||
If you are using the [[https://nixos.org/][Nix]] package manager, you can run =nix-shell= in the project directory.
|
||||
This will drop you into a shell with all requirements fulfilled.
|
||||
|
||||
On the start of the script, it is checked if the dependencies are fulfilled.
|
||||
On the start of the script, it is checked if the dependencies are fulfilled.
|
||||
|
||||
#+begin_src sh
|
||||
#+begin_src sh
|
||||
if ! command -v mpv &> /dev/null
|
||||
then
|
||||
echo -ne "\e[1mmpv\e[0m was not found, please install it"
|
||||
|
|
@ -31,29 +31,29 @@
|
|||
echo -ne "\e[1myoutube-dl\e[0m was not found, please install it"
|
||||
exit 1
|
||||
fi
|
||||
#+end_src
|
||||
#+end_src
|
||||
|
||||
*** Usage
|
||||
|
||||
This function prints the usage of the script.
|
||||
This function prints the usage of the script.
|
||||
|
||||
#+begin_src sh
|
||||
#+begin_src sh
|
||||
function print_usage {
|
||||
echo "tyt [ (-a* | --alternative) | (-i | --interactive) ] \"QUERY\""
|
||||
}
|
||||
#+end_src
|
||||
#+end_src
|
||||
|
||||
*** Arguments
|
||||
|
||||
At first we parse the arguments.
|
||||
We have the following flags:
|
||||
At first we parse the arguments.
|
||||
We have the following flags:
|
||||
|
||||
- =a*|alternative= :: Alternative video (optional); You can parse any amount of alternatives (e.g. =-aaa=)
|
||||
- =i|interactive= :: Interactive mode; Shows the first 10 results and queries for a selection; If this flag is set, =-a= is ignored
|
||||
- =a*|alternative= :: Alternative video (optional); You can parse any amount of alternatives (e.g. =-aaa=)
|
||||
- =i|interactive= :: Interactive mode; Shows the first 10 results and queries for a selection; If this flag is set, =-a= is ignored
|
||||
|
||||
Additionally we have exacly one mandatory quoted string as query.
|
||||
Additionally we have exacly one mandatory quoted string as query.
|
||||
|
||||
#+begin_src sh
|
||||
#+begin_src sh
|
||||
alternative=0
|
||||
format="flac"
|
||||
interactive=false
|
||||
|
|
@ -99,26 +99,26 @@
|
|||
fi
|
||||
|
||||
query="${other_arguments[0]}"
|
||||
#+end_src
|
||||
#+end_src
|
||||
|
||||
*** Greeter
|
||||
|
||||
If the arguments match, print a greeter.
|
||||
If the arguments match, print a greeter.
|
||||
|
||||
#+begin_src sh
|
||||
#+begin_src sh
|
||||
echo -ne "\n \e[1m\ /\e[0m\n"
|
||||
echo -ne " \e[1m=======\e[0m\n"
|
||||
echo -ne " \e[1m| \e[31mtyt\e[0m \e[1m|\e[0m\n"
|
||||
echo -ne " \e[1m=======\e[0m\n\n"
|
||||
#+end_src
|
||||
#+end_src
|
||||
|
||||
*** Get URL
|
||||
|
||||
To play a video, we need to get a valid URL.
|
||||
Since there are sometimes parsing errors of the JSON response, we use an endless loop to try until we get a valid response.
|
||||
The first /n/ URLs are saved if an alternative download is requested.
|
||||
To play a video, we need to get a valid URL.
|
||||
Since there are sometimes parsing errors of the JSON response, we use an endless loop to try until we get a valid response.
|
||||
The first /n/ URLs are saved if an alternative download is requested.
|
||||
|
||||
#+begin_src sh
|
||||
#+begin_src sh
|
||||
i=0
|
||||
|
||||
if [ "$interactive" = true ]
|
||||
|
|
@ -167,13 +167,13 @@
|
|||
titles=($titles)
|
||||
uploaders=($uploaders)
|
||||
IFS=$OLDIFS
|
||||
#+end_src
|
||||
#+end_src
|
||||
|
||||
*** Interactive selection
|
||||
|
||||
If the interactive flag is present, show the first ten results and query for a video to play.
|
||||
If the interactive flag is present, show the first ten results and query for a video to play.
|
||||
|
||||
#+begin_src sh
|
||||
#+begin_src sh
|
||||
if [ "$interactive" = true ]
|
||||
then
|
||||
echo ""
|
||||
|
|
@ -198,13 +198,13 @@
|
|||
title=${titles[$alternative]}
|
||||
uploader=${uploaders[$alternative]}
|
||||
fi
|
||||
#+end_src
|
||||
#+end_src
|
||||
|
||||
*** Play video
|
||||
|
||||
Finally the video is played via mpv.
|
||||
Finally the video is played via mpv.
|
||||
|
||||
#+begin_src sh
|
||||
#+begin_src sh
|
||||
echo -ne "Playing: \e[32m\e[1m$title\e[0m (\e[33m\e[1m$uploader\e[0m)\n"
|
||||
mpv $url &> /dev/null
|
||||
#+end_src
|
||||
#+end_src
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue