2
0
mirror of https://github.com/alexanderepstein/Bash-Snippets synced 2018-11-08 02:59:35 +01:00

Title can have spaces in it now

This commit is contained in:
Alex Epstein 2017-07-03 20:04:32 -04:00
parent ca79fdcb83
commit 7317fbbe53

View File

@ -1,5 +1,6 @@
#!/bin/bash #!/bin/bash
# Author: Linyos Torovoltos https://github.com/linyostorovovoltos
# Modifications: Alexander Epstein https://github.com/alexanderepstein
if [[ -d $HOME/.cache/ytview ]];then rm -rf $HOME/.cache/ytview/ ;fi if [[ -d $HOME/.cache/ytview ]];then rm -rf $HOME/.cache/ytview/ ;fi
player="" player=""
@ -125,15 +126,15 @@ getConfiguredPlayer()
channelview() channelview()
{ {
mkdir -p $HOME/.cache/ytview/channels/$channel mkdir -p $HOME/.cache/ytview/channels/$channel || return 1
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 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 || return 1
# Get the video urls # Get the video urls
httpGet https://www.youtube.com/user/$channel/Videos | grep "watch?v=" | awk '{print $6}' | sed s/spf-link// | sed s/href=// | sed 's/"//' | sed 's/"//' | sed '/^\s*$/d' | sed 's/\//https:\/\/www.youtube.com\//' | awk '{printf "%s.\t%s\n",NR,$0}' > $HOME/.cache/ytview/channels/$channel/urls.txt httpGet https://www.youtube.com/user/$channel/Videos | grep "watch?v=" | awk '{print $6}' | sed s/spf-link// | sed s/href=// | sed 's/"//' | sed 's/"//' | sed '/^\s*$/d' | sed 's/\//https:\/\/www.youtube.com\//' | awk '{printf "%s.\t%s\n",NR,$0}' > $HOME/.cache/ytview/channels/$channel/urls.txt || return 1
# Print 20 first video titles for the user to choose from # Print 20 first video titles for the user to choose from
head -n 20 $HOME/.cache/ytview/channels/$channel/titles.txt head -n 20 $HOME/.cache/ytview/channels/$channel/titles.txt || return 1
# Prompt the user for video number # Prompt the user for video number
read -p "Choose a video: " titlenumber read -p "Choose a video: " titlenumber
@ -146,16 +147,16 @@ channelview()
searchview() searchview()
{ {
search=$(echo $search |sed -e "s/ /+/") search=$(echo $search | tr " " + )
mkdir -p $HOME/.cache/ytview/searches/$search mkdir -p $HOME/.cache/ytview/searches/$search
#Get video titles #Get video titles
httpGet https://www.youtube.com/results\?search_query\=$search | grep "Duration" | awk '{print $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/"//' | sed s/spf-link// | sed 's/data-sessionlink=itct*.//' | sed s/spf-prefetch// | tail -n 17 | sed 's/rel="//' | sed 's/"//' | awk '{printf "%s.\t%s\n",NR,$0}' > $HOME/.cache/ytview/searches/$search/titles.txt httpGet https://www.youtube.com/results\?search_query\=$search | grep "Duration" | awk '{print $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/"//' | sed s/spf-link// | sed 's/data-sessionlink=itct*.//' | sed s/spf-prefetch// | tail -n 17 | sed 's/rel="//' | sed 's/"//' | awk '{printf "%s.\t%s\n",NR,$0}' > $HOME/.cache/ytview/searches/$search/titles.txt || return 1
#Get video urls #Get video urls
httpGet https://www.youtube.com/results\?search_query\=$search | grep "watch?v=" | awk '{print $5}' | sed s/vve-check// | sed 's/href="/https:\/\/www.youtube.com/' | sed 's/"//' | sed s/class="yt-uix-tile-link"// |sed '/^\s*$/d' | awk '{printf "%s.\t%s\n",NR,$0}' > $HOME/.cache/ytview/searches/$search/urls.txt httpGet https://www.youtube.com/results\?search_query\=$search | grep "watch?v=" | awk '{print $5}' | sed s/vve-check// | sed 's/href="/https:\/\/www.youtube.com/' | sed 's/"//' | sed s/class="yt-uix-tile-link"// |sed '/^\s*$/d' | awk '{printf "%s.\t%s\n",NR,$0}' > $HOME/.cache/ytview/searches/$search/urls.txt || return 1
#Print 20 first video titles for the user to choose from #Print 20 first video titles for the user to choose from
head -n 20 $HOME/.cache/ytview/searches/$search/titles.txt head -n 20 $HOME/.cache/ytview/searches/$search/titles.txt || return 1
#Let the user choose the video number #Let the user choose the video number
read -p "Choose a video: " titlenumber read -p "Choose a video: " titlenumber
@ -183,7 +184,7 @@ do
case "${option}" in case "${option}" in
s) s)
if [[ $flag != "channel" ]];then if [[ $flag != "channel" ]];then
search=${OPTARG} search=$(printf '%s ' "$@")
flag="search" flag="search"
else else
echo "Error: search and channel options are mutually exclusive" echo "Error: search and channel options are mutually exclusive"
@ -192,7 +193,7 @@ do
;; ;;
c) c)
if [[ $flag != "search" ]];then if [[ $flag != "search" ]];then
channel=${OPTARG} channel="$OPTARG"
flag="channel" flag="channel"
else else
echo "Error: search and channel options are mutually exclusive" echo "Error: search and channel options are mutually exclusive"
@ -212,10 +213,10 @@ elif [[ $1 == "help" ]];then
elif [[ $1 == "update" ]]; then elif [[ $1 == "update" ]]; then
update update
elif [[ $flag == "search" ]]; then elif [[ $flag == "search" ]]; then
searchview searchview || exit 1
elif [[ $flag == "channel" ]]; then elif [[ $flag == "channel" ]]; then
channelview channelview || exit 1
else else
search="$@" search=$(printf '%s ' "$@")
searchview searchview || exit 1
fi fi