From ac9aa8c0db98e4f07d82cc2942fcade0016302c9 Mon Sep 17 00:00:00 2001 From: Denis Lehmann Date: Mon, 15 Mar 2021 02:13:32 +0100 Subject: [PATCH] add audio only --- README.org | 36 +++++++++++++++++++++++++++++------- tyt | 32 +++++++++++++++++++++++++------- 2 files changed, 54 insertions(+), 14 deletions(-) diff --git a/README.org b/README.org index b7a462a..9b556bc 100644 --- a/README.org +++ b/README.org @@ -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 "$@" @@ -71,10 +73,14 @@ Additionally we have exacly one mandatory quoted string as query. alternative=1 shift ;; - -i|--interactive) + -i|--interactive) 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 - 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 #+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" - mpv $url &> /dev/null + if [ "$music" = true ] + then + mpv --no-video $url &> /dev/null + else + mpv $url &> /dev/null + fi #+end_src diff --git a/tyt b/tyt index 735139a..7c39ed7 100755 --- a/tyt +++ b/tyt @@ -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 "$@" @@ -30,10 +31,14 @@ do alternative=1 shift ;; - -i|--interactive) + -i|--interactive) 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