add audio only

This commit is contained in:
Denis Lehmann 2021-03-15 02:13:32 +01:00
parent 3f5211e0b1
commit ac9aa8c0db
2 changed files with 54 additions and 14 deletions

View file

@ -39,7 +39,7 @@ This function prints the usage of the script.
#+begin_src sh
function print_usage {
echo "tyt [ (-a* | --alternative) | (-i | --interactive) ] \"QUERY\""
echo "tyt [ (-a* | --alternative) | (-i | --interactive) | (-m | --music) ] \"QUERY\""
}
#+end_src
@ -50,6 +50,7 @@ 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
- =m|music= :: Play only the audio track of the video
Additionally we have exacly one mandatory quoted string as query.
@ -57,6 +58,7 @@ Additionally we have exacly one mandatory quoted string as query.
alternative=0
format="flac"
interactive=false
music=false
help=false
for arg in "$@"
@ -75,6 +77,10 @@ Additionally we have exacly one mandatory quoted string as query.
interactive=true
shift
;;
-m|--music)
music=true
shift
;;
-h|--help)
help=true
shift
@ -104,12 +110,22 @@ Additionally we have exacly one mandatory quoted string as query.
*** Greeter
If the arguments match, print a greeter.
Another greeter is printed if the flag =-m= is set.
Make sure your terminal emulator supports Unicode to see the notes.
#+begin_src sh
if [ "$music" = false ]
then
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"
else
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"
fi
#+end_src
*** Get URL
@ -203,8 +219,14 @@ If the interactive flag is present, show the first ten results and query for a v
*** Play video
Finally the video is played via mpv.
If the =-m= flag is set, only the audio track is played.
#+begin_src sh
echo -ne "Playing: \e[32m\e[1m$title\e[0m (\e[33m\e[1m$uploader\e[0m)\n"
if [ "$music" = true ]
then
mpv --no-video $url &> /dev/null
else
mpv $url &> /dev/null
fi
#+end_src

30
tyt
View file

@ -10,12 +10,13 @@ then
fi
function print_usage {
echo "tyt [ (-a* | --alternative) | (-i | --interactive) ] \"QUERY\""
echo "tyt [ (-a* | --alternative) | (-i | --interactive) | (-m | --music) ] \"QUERY\""
}
alternative=0
format="flac"
interactive=false
music=false
help=false
for arg in "$@"
@ -34,6 +35,10 @@ do
interactive=true
shift
;;
-m|--music)
music=true
shift
;;
-h|--help)
help=true
shift
@ -59,10 +64,18 @@ fi
query="${other_arguments[0]}"
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"
if [ "$music" = false ]
then
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"
else
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"
fi
i=0
@ -139,4 +152,9 @@ else
fi
echo -ne "Playing: \e[32m\e[1m$title\e[0m (\e[33m\e[1m$uploader\e[0m)\n"
mpv $url &> /dev/null
if [ "$music" = true ]
then
mpv --no-video $url &> /dev/null
else
mpv $url &> /dev/null
fi