This commit is contained in:
Denis Lehmann 2021-03-29 23:00:43 +02:00
parent 6b5656ce8f
commit 3a9da2a22a
3 changed files with 114 additions and 106 deletions

View file

@ -6,6 +6,8 @@
Terminal YouTube (*tyt*) is a small bash script that lets you play YouTube videos by query from the command line. 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. It is created via literate programming, you can find the code below.
[[./images/screenshot.png]]
** Script ** Script
*** Dependencies *** Dependencies
@ -204,11 +206,12 @@ If the interactive flag is present, show the first ten results and query for a v
if [ "$interactive" = true ] if [ "$interactive" = true ]
then then
echo "" echo ""
selections=(0 1 2 3 4 5 6 7 8 9) selections=(0 1 2 3 4 5 6 7 8 9 q)
for i in ${selections[@]} for i in ${selections[@]}
do do
echo -ne " \e[1m$i\e[0m: ${titles[$i]} (\e[33m\e[1m${uploaders[$i]}\e[0m)\n" echo -ne " \e[1m$i\e[0m: ${titles[$i]} (\e[33m\e[1m${uploaders[$i]}\e[0m)\n"
done done
echo -ne " \e[1mq\e[0m: Quit\n"
echo -ne "\nSelection: " echo -ne "\nSelection: "
read selection read selection
while [[ ! "${selections[@]}" =~ "${selection}" ]] while [[ ! "${selections[@]}" =~ "${selection}" ]]
@ -216,6 +219,10 @@ If the interactive flag is present, show the first ten results and query for a v
echo -ne "Not valid, try again: " echo -ne "Not valid, try again: "
read selection read selection
done done
if [ "$selection" = "q" ]
then
exit
fi
echo "" echo ""
url=${urls[$selection]} url=${urls[$selection]}
title=${titles[$selection]} title=${titles[$selection]}
@ -249,11 +256,9 @@ In interaction mode, another video is queried to be played.
if [ "$interactive" = true ] if [ "$interactive" = true ]
then then
quit=false while :
selections=(0 1 2 3 4 5 6 7 8 9 q)
while [ ! "$quit" = true ]
do do
echo -ne "\nSelect another or press [q] to quit: " echo -ne "\nSelect another or enter [q] to quit: "
read selection read selection
while [[ ! "${selections[@]}" =~ "${selection}" ]] while [[ ! "${selections[@]}" =~ "${selection}" ]]
do do
@ -268,7 +273,7 @@ In interaction mode, another video is queried to be played.
uploader=${uploaders[$selection]} uploader=${uploaders[$selection]}
play "$url" "$title" "$uploader" play "$url" "$title" "$uploader"
else else
quit=true exit
fi fi
done done
fi fi

BIN
images/screenshot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 356 KiB

15
tyt
View file

@ -140,11 +140,12 @@ IFS=$OLDIFS
if [ "$interactive" = true ] if [ "$interactive" = true ]
then then
echo "" echo ""
selections=(0 1 2 3 4 5 6 7 8 9) selections=(0 1 2 3 4 5 6 7 8 9 q)
for i in ${selections[@]} for i in ${selections[@]}
do do
echo -ne " \e[1m$i\e[0m: ${titles[$i]} (\e[33m\e[1m${uploaders[$i]}\e[0m)\n" echo -ne " \e[1m$i\e[0m: ${titles[$i]} (\e[33m\e[1m${uploaders[$i]}\e[0m)\n"
done done
echo -ne " \e[1mq\e[0m: Quit\n"
echo -ne "\nSelection: " echo -ne "\nSelection: "
read selection read selection
while [[ ! "${selections[@]}" =~ "${selection}" ]] while [[ ! "${selections[@]}" =~ "${selection}" ]]
@ -152,6 +153,10 @@ then
echo -ne "Not valid, try again: " echo -ne "Not valid, try again: "
read selection read selection
done done
if [ "$selection" = "q" ]
then
exit
fi
echo "" echo ""
url=${urls[$selection]} url=${urls[$selection]}
title=${titles[$selection]} title=${titles[$selection]}
@ -176,11 +181,9 @@ play "$url" "$title" "$uploader"
if [ "$interactive" = true ] if [ "$interactive" = true ]
then then
quit=false while :
selections=(0 1 2 3 4 5 6 7 8 9 q)
while [ ! "$quit" = true ]
do do
echo -ne "\nSelect another or press [q] to quit: " echo -ne "\nSelect another or enter [q] to quit: "
read selection read selection
while [[ ! "${selections[@]}" =~ "${selection}" ]] while [[ ! "${selections[@]}" =~ "${selection}" ]]
do do
@ -195,7 +198,7 @@ then
uploader=${uploaders[$selection]} uploader=${uploaders[$selection]}
play "$url" "$title" "$uploader" play "$url" "$title" "$uploader"
else else
quit=true exit
fi fi
done done
fi fi