From 7317fbbe53c81a04d80e5a93fef864743c24904b Mon Sep 17 00:00:00 2001 From: Alex Epstein Date: Mon, 3 Jul 2017 20:04:32 -0400 Subject: [PATCH] Title can have spaces in it now --- ytview/ytview | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/ytview/ytview b/ytview/ytview index a6062f8..c47c856 100755 --- a/ytview/ytview +++ b/ytview/ytview @@ -1,5 +1,6 @@ #!/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 player="" @@ -125,15 +126,15 @@ getConfiguredPlayer() 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 + 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 || return 1 # 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 - 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 read -p "Choose a video: " titlenumber @@ -146,16 +147,16 @@ channelview() searchview() { - search=$(echo $search |sed -e "s/ /+/") + search=$(echo $search | tr " " + ) mkdir -p $HOME/.cache/ytview/searches/$search #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 - 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 - 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 read -p "Choose a video: " titlenumber @@ -183,7 +184,7 @@ do case "${option}" in s) if [[ $flag != "channel" ]];then - search=${OPTARG} + search=$(printf '%s ' "$@") flag="search" else echo "Error: search and channel options are mutually exclusive" @@ -192,7 +193,7 @@ do ;; c) if [[ $flag != "search" ]];then - channel=${OPTARG} + channel="$OPTARG" flag="channel" else echo "Error: search and channel options are mutually exclusive" @@ -212,10 +213,10 @@ elif [[ $1 == "help" ]];then elif [[ $1 == "update" ]]; then update elif [[ $flag == "search" ]]; then - searchview + searchview || exit 1 elif [[ $flag == "channel" ]]; then - channelview + channelview || exit 1 else - search="$@" - searchview + search=$(printf '%s ' "$@") + searchview || exit 1 fi