mirror of
https://github.com/alexanderepstein/Bash-Snippets
synced 2018-11-08 02:59:35 +01:00
better user interaction with tool
This commit is contained in:
parent
82219534c4
commit
ca79fdcb83
@ -5,6 +5,7 @@ if [[ -d $HOME/.cache/ytview ]];then rm -rf $HOME/.cache/ytview/ ;fi
|
||||
player=""
|
||||
configuredClient=""
|
||||
currentVersion="1.7.0"
|
||||
flag=""
|
||||
|
||||
## This function determines which http get tool the system has installed and returns an error if there isnt one
|
||||
getConfiguredClient()
|
||||
@ -19,7 +20,6 @@ getConfiguredClient()
|
||||
echo "Error: This tool reqires either curl, wget, or fetch to be installed." >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
checkInternet()
|
||||
@ -95,7 +95,6 @@ update()
|
||||
echo "$repositoryName is already the latest version"
|
||||
fi
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
getConfiguredPlayer()
|
||||
@ -123,7 +122,8 @@ getConfiguredPlayer()
|
||||
|
||||
|
||||
# Get the video titles
|
||||
channelview() {
|
||||
channelview()
|
||||
{
|
||||
|
||||
mkdir -p $HOME/.cache/ytview/channels/$channel
|
||||
httpGet https://www.youtube.com/user/$channel/videos | grep "Duration" | awk '{print $10 " " $11 " " $12 " " $13 " " $14 " " $15 " " $16 " " $17 " " $18 " " $19 " " $20 " " $21 " " $22 " " $23 " " $24 " " $25 " " $26 " " $27 " " $29}' | sed 's/aria-describedby="description-id.*//' | sed s/title=// | sed 's/"//' | sed 's/"//' | awk '{printf "%s.\t%s\n",NR,$0}' > $HOME/.cache/ytview/channels/$channel/titles.txt
|
||||
@ -143,7 +143,8 @@ channelview() {
|
||||
$player $(grep $titlenumber $HOME/.cache/ytview/channels/$channel/urls.txt | awk '{print $2}') > /dev/null 2>&1 & # grep is not needed here but I'm lazy
|
||||
}
|
||||
|
||||
searchview() {
|
||||
searchview()
|
||||
{
|
||||
|
||||
search=$(echo $search |sed -e "s/ /+/")
|
||||
mkdir -p $HOME/.cache/ytview/searches/$search
|
||||
@ -166,7 +167,8 @@ searchview() {
|
||||
|
||||
}
|
||||
|
||||
usage() {
|
||||
usage()
|
||||
{
|
||||
echo "Usage: ytview [flag] [string]"
|
||||
echo " -s Searches youtube"
|
||||
echo " -c Shows the latest videos of a channel"
|
||||
@ -179,10 +181,41 @@ checkInternet || exit 1
|
||||
while getopts uc:s:h*: option
|
||||
do
|
||||
case "${option}" in
|
||||
s) search=${OPTARG} && searchview ;;
|
||||
c) channel=${OPTARG} && channelview ;;
|
||||
s)
|
||||
if [[ $flag != "channel" ]];then
|
||||
search=${OPTARG}
|
||||
flag="search"
|
||||
else
|
||||
echo "Error: search and channel options are mutually exclusive"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
c)
|
||||
if [[ $flag != "search" ]];then
|
||||
channel=${OPTARG}
|
||||
flag="channel"
|
||||
else
|
||||
echo "Error: search and channel options are mutually exclusive"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
h) usage ;;
|
||||
u) update ;;
|
||||
*) usage ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ $# == "0" ]]; then
|
||||
usage
|
||||
elif [[ $1 == "help" ]];then
|
||||
usage
|
||||
elif [[ $1 == "update" ]]; then
|
||||
update
|
||||
elif [[ $flag == "search" ]]; then
|
||||
searchview
|
||||
elif [[ $flag == "channel" ]]; then
|
||||
channelview
|
||||
else
|
||||
search="$@"
|
||||
searchview
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user