cleanup
This commit is contained in:
parent
6b5656ce8f
commit
3a9da2a22a
3 changed files with 114 additions and 106 deletions
111
README.org
111
README.org
|
|
@ -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
|
||||||
|
|
||||||
|
|
@ -25,22 +27,22 @@ On the start of the script, it is checked if the dependencies are fulfilled.
|
||||||
missing_dependencies=false
|
missing_dependencies=false
|
||||||
if ! command -v jq &> /dev/null
|
if ! command -v jq &> /dev/null
|
||||||
then
|
then
|
||||||
echo -ne "\e[1mjq\e[0m was not found, please install it\n"
|
echo -ne "\e[1mjq\e[0m was not found, please install it\n"
|
||||||
missing_dependencies=true
|
missing_dependencies=true
|
||||||
fi
|
fi
|
||||||
if ! command -v mpv &> /dev/null
|
if ! command -v mpv &> /dev/null
|
||||||
then
|
then
|
||||||
echo -ne "\e[1mmpv\e[0m was not found, please install it\n"
|
echo -ne "\e[1mmpv\e[0m was not found, please install it\n"
|
||||||
missing_dependencies=true
|
missing_dependencies=true
|
||||||
fi
|
fi
|
||||||
if ! command -v youtube-dl &> /dev/null
|
if ! command -v youtube-dl &> /dev/null
|
||||||
then
|
then
|
||||||
echo -ne "\e[1myoutube-dl\e[0m was not found, please install it\n"
|
echo -ne "\e[1myoutube-dl\e[0m was not found, please install it\n"
|
||||||
missing_dependencies=true
|
missing_dependencies=true
|
||||||
fi
|
fi
|
||||||
if [ "$missing_dependencies" = true ]
|
if [ "$missing_dependencies" = true ]
|
||||||
then
|
then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
|
@ -203,27 +205,32 @@ If the interactive flag is present, show the first ten results and query for a v
|
||||||
#+begin_src bash
|
#+begin_src bash
|
||||||
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 "\nSelection: "
|
echo -ne " \e[1mq\e[0m: Quit\n"
|
||||||
read selection
|
echo -ne "\nSelection: "
|
||||||
while [[ ! "${selections[@]}" =~ "${selection}" ]]
|
|
||||||
do
|
|
||||||
echo -ne "Not valid, try again: "
|
|
||||||
read selection
|
read selection
|
||||||
done
|
while [[ ! "${selections[@]}" =~ "${selection}" ]]
|
||||||
echo ""
|
do
|
||||||
url=${urls[$selection]}
|
echo -ne "Not valid, try again: "
|
||||||
title=${titles[$selection]}
|
read selection
|
||||||
uploader=${uploaders[$selection]}
|
done
|
||||||
|
if [ "$selection" = "q" ]
|
||||||
|
then
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
url=${urls[$selection]}
|
||||||
|
title=${titles[$selection]}
|
||||||
|
uploader=${uploaders[$selection]}
|
||||||
else
|
else
|
||||||
url=${urls[$alternative]}
|
url=${urls[$alternative]}
|
||||||
title=${titles[$alternative]}
|
title=${titles[$alternative]}
|
||||||
uploader=${uploaders[$alternative]}
|
uploader=${uploaders[$alternative]}
|
||||||
fi
|
fi
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
|
@ -236,40 +243,38 @@ In interaction mode, another video is queried to be played.
|
||||||
|
|
||||||
#+begin_src bash
|
#+begin_src bash
|
||||||
function play {
|
function play {
|
||||||
echo -ne "Playing: \e[32m\e[1m$2\e[0m (\e[33m\e[1m$3\e[0m)\n"
|
echo -ne "Playing: \e[32m\e[1m$2\e[0m (\e[33m\e[1m$3\e[0m)\n"
|
||||||
if [ "$music" = true ]
|
if [ "$music" = true ]
|
||||||
then
|
then
|
||||||
mpv --no-video $1 &> /dev/null
|
mpv --no-video $1 &> /dev/null
|
||||||
else
|
else
|
||||||
mpv $1 &> /dev/null
|
mpv $1 &> /dev/null
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
play "$url" "$title" "$uploader"
|
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
|
|
||||||
echo -ne "\nSelect another or press [q] to quit: "
|
|
||||||
read selection
|
|
||||||
while [[ ! "${selections[@]}" =~ "${selection}" ]]
|
|
||||||
do
|
do
|
||||||
echo -ne "Not valid, try again: "
|
echo -ne "\nSelect another or enter [q] to quit: "
|
||||||
read selection
|
read selection
|
||||||
|
while [[ ! "${selections[@]}" =~ "${selection}" ]]
|
||||||
|
do
|
||||||
|
echo -ne "Not valid, try again: "
|
||||||
|
read selection
|
||||||
|
done
|
||||||
|
if [ ! "$selection" = "q" ]
|
||||||
|
then
|
||||||
|
echo ""
|
||||||
|
url=${urls[$selection]}
|
||||||
|
title=${titles[$selection]}
|
||||||
|
uploader=${uploaders[$selection]}
|
||||||
|
play "$url" "$title" "$uploader"
|
||||||
|
else
|
||||||
|
exit
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
if [ ! "$selection" = "q" ]
|
|
||||||
then
|
|
||||||
echo ""
|
|
||||||
url=${urls[$selection]}
|
|
||||||
title=${titles[$selection]}
|
|
||||||
uploader=${uploaders[$selection]}
|
|
||||||
play "$url" "$title" "$uploader"
|
|
||||||
else
|
|
||||||
quit=true
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
fi
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
|
||||||
BIN
images/screenshot.png
Normal file
BIN
images/screenshot.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 356 KiB |
109
tyt
109
tyt
|
|
@ -2,22 +2,22 @@
|
||||||
missing_dependencies=false
|
missing_dependencies=false
|
||||||
if ! command -v jq &> /dev/null
|
if ! command -v jq &> /dev/null
|
||||||
then
|
then
|
||||||
echo -ne "\e[1mjq\e[0m was not found, please install it\n"
|
echo -ne "\e[1mjq\e[0m was not found, please install it\n"
|
||||||
missing_dependencies=true
|
missing_dependencies=true
|
||||||
fi
|
fi
|
||||||
if ! command -v mpv &> /dev/null
|
if ! command -v mpv &> /dev/null
|
||||||
then
|
then
|
||||||
echo -ne "\e[1mmpv\e[0m was not found, please install it\n"
|
echo -ne "\e[1mmpv\e[0m was not found, please install it\n"
|
||||||
missing_dependencies=true
|
missing_dependencies=true
|
||||||
fi
|
fi
|
||||||
if ! command -v youtube-dl &> /dev/null
|
if ! command -v youtube-dl &> /dev/null
|
||||||
then
|
then
|
||||||
echo -ne "\e[1myoutube-dl\e[0m was not found, please install it\n"
|
echo -ne "\e[1myoutube-dl\e[0m was not found, please install it\n"
|
||||||
missing_dependencies=true
|
missing_dependencies=true
|
||||||
fi
|
fi
|
||||||
if [ "$missing_dependencies" = true ]
|
if [ "$missing_dependencies" = true ]
|
||||||
then
|
then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
function print_usage {
|
function print_usage {
|
||||||
|
|
@ -139,63 +139,66 @@ 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 "\nSelection: "
|
echo -ne " \e[1mq\e[0m: Quit\n"
|
||||||
read selection
|
echo -ne "\nSelection: "
|
||||||
while [[ ! "${selections[@]}" =~ "${selection}" ]]
|
|
||||||
do
|
|
||||||
echo -ne "Not valid, try again: "
|
|
||||||
read selection
|
read selection
|
||||||
done
|
while [[ ! "${selections[@]}" =~ "${selection}" ]]
|
||||||
echo ""
|
do
|
||||||
url=${urls[$selection]}
|
echo -ne "Not valid, try again: "
|
||||||
title=${titles[$selection]}
|
read selection
|
||||||
uploader=${uploaders[$selection]}
|
done
|
||||||
|
if [ "$selection" = "q" ]
|
||||||
|
then
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
url=${urls[$selection]}
|
||||||
|
title=${titles[$selection]}
|
||||||
|
uploader=${uploaders[$selection]}
|
||||||
else
|
else
|
||||||
url=${urls[$alternative]}
|
url=${urls[$alternative]}
|
||||||
title=${titles[$alternative]}
|
title=${titles[$alternative]}
|
||||||
uploader=${uploaders[$alternative]}
|
uploader=${uploaders[$alternative]}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
function play {
|
function play {
|
||||||
echo -ne "Playing: \e[32m\e[1m$2\e[0m (\e[33m\e[1m$3\e[0m)\n"
|
echo -ne "Playing: \e[32m\e[1m$2\e[0m (\e[33m\e[1m$3\e[0m)\n"
|
||||||
if [ "$music" = true ]
|
if [ "$music" = true ]
|
||||||
then
|
then
|
||||||
mpv --no-video $1 &> /dev/null
|
mpv --no-video $1 &> /dev/null
|
||||||
else
|
else
|
||||||
mpv $1 &> /dev/null
|
mpv $1 &> /dev/null
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
play "$url" "$title" "$uploader"
|
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
|
|
||||||
echo -ne "\nSelect another or press [q] to quit: "
|
|
||||||
read selection
|
|
||||||
while [[ ! "${selections[@]}" =~ "${selection}" ]]
|
|
||||||
do
|
do
|
||||||
echo -ne "Not valid, try again: "
|
echo -ne "\nSelect another or enter [q] to quit: "
|
||||||
read selection
|
read selection
|
||||||
|
while [[ ! "${selections[@]}" =~ "${selection}" ]]
|
||||||
|
do
|
||||||
|
echo -ne "Not valid, try again: "
|
||||||
|
read selection
|
||||||
|
done
|
||||||
|
if [ ! "$selection" = "q" ]
|
||||||
|
then
|
||||||
|
echo ""
|
||||||
|
url=${urls[$selection]}
|
||||||
|
title=${titles[$selection]}
|
||||||
|
uploader=${uploaders[$selection]}
|
||||||
|
play "$url" "$title" "$uploader"
|
||||||
|
else
|
||||||
|
exit
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
if [ ! "$selection" = "q" ]
|
|
||||||
then
|
|
||||||
echo ""
|
|
||||||
url=${urls[$selection]}
|
|
||||||
title=${titles[$selection]}
|
|
||||||
uploader=${uploaders[$selection]}
|
|
||||||
play "$url" "$title" "$uploader"
|
|
||||||
else
|
|
||||||
quit=true
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue