From 230882d79435535be5e411055c88916fd305215b Mon Sep 17 00:00:00 2001 From: Sumit112192 Date: Tue, 11 Jul 2023 19:57:27 +0530 Subject: [PATCH] Changed the ytview file corresponding to change on youtube html source code --- ytview/ytview | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/ytview/ytview b/ytview/ytview index 7ed56364..51e05b18 100755 --- a/ytview/ytview +++ b/ytview/ytview @@ -142,6 +142,9 @@ channelview() mkdir -p "$HOME"/.cache/ytview/channels/"$channel" || return 1 httpGet "https://www.youtube.com/user/$channel/videos?hl=en" | 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}' | sed s/'''/"'"/g | sed s/'&'/'and'/g | sed s/\"\;/\"/g > "$HOME"/.cache/ytview/channels/"$channel"/titles.txt || return 1 + httpGet "https://www.youtube.com/results?search_query=$search" | grep -oP '"videoRenderer":{[^}]*}[^}]*}[^}]*}[^}]*}[^}]*}}}' | grep -oP '"label":"[^"]*' | sed 's/\"label\":\"//' | cat -n > "$HOME"/.cache/ytview/searches/"$search"/titles.txt || return 1 + + # Get the video urls httpGet "https://www.youtube.com/user/$channel/Videos?hl=en" | 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 @@ -164,12 +167,18 @@ searchview() mkdir -p "$HOME"/.cache/ytview/searches/"$search" #Get video titles - httpGet "https://www.youtube.com/results?hl=en&search_query=$search" | grep "Duration" | grep "watch?v=" | awk '{print $13 " " $14 " " $15 " " $16 " " $17 " " $18 " " $19 " " $20 " " $21 " " $22 " " $23 " " $23}' | sed 's/aria-describedby="description-id.*//g' | sed s/title=// | sed 's/"//g' | sed s/spf-link// | sed 's/data-session-link=itct*.//' | sed s/spf-prefetch//g | sed 's/rel=//g' | sed 's/"//' | awk '{printf "%s.\t%s\n",NR,$0}' | sed s/'''/"'"/g | sed s/'&'/'and'/g | sed s/\"\;/\"/g > "$HOME"/.cache/ytview/searches/"$search"/titles.txt || return 1 + #httpGet "https://www.youtube.com/results?hl=en&search_query=$search" | grep "Duration" | grep "watch?v=" | awk '{print $13 " " $14 " " $15 " " $16 " " $17 " " $18 " " $19 " " $20 " " $21 " " $22 " " $23 " " $23}' | sed 's/aria-describedby="description-id.*//g' | sed s/title=// | sed 's/"//g' | sed s/spf-link// | sed 's/data-session-link=itct*.//' | sed s/spf-prefetch//g | sed 's/rel=//g' | sed 's/"//' | awk '{printf "%s.\t%s\n",NR,$0}' | sed s/'''/"'"/g | sed s/'&'/'and'/g | sed s/\"\;/\"/g > "$HOME"/.cache/ytview/searches/"$search"/titles.txt || return 1 + + + httpGet "https://www.youtube.com/results?search_query=$search" | grep -oP '"videoRenderer":{[^}]*}[^}]*}[^}]*}[^}]*}[^}]*}}}' | grep -oP '"label":"[^"]*' | sed 's/\"label\":\"//' | cat -n > "$HOME"/.cache/ytview/searches/"$search"/titles.txt || return 1 #Get video urls - httpGet "https://www.youtube.com/results?hl=en&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 + #httpGet "https://www.youtube.com/results?hl=en&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 + + + httpGet "https://www.youtube.com/results?search_query=$search" | grep -oP '"videoRenderer":{[^}]*}[^}]*}[^}]*}[^}]*}[^}]*}}}' | grep -oP '"videoId":"[^"]*' | sed 's/\"videoId\":\"/https:\/\/www.youtube.com\/watch?v=/' > "$HOME"/.cache/ytview/searches/"$search"/urls.txt || return 1 #Print 20 first video titles for the user to choose from - cat "$HOME"/.cache/ytview/searches/"$search"/titles.txt || return 1 + head -20 "$HOME"/.cache/ytview/searches/"$search"/titles.txt || return 1 #Let the user choose the video number read -p "Choose a video: " titlenumber @@ -179,7 +188,8 @@ searchview() fi #Play the video with your favorite player - $player $(sed -n $(echo "$titlenumber")p < "$HOME"/.cache/ytview/searches/"$search"/urls.txt | awk '{print $2}') > /dev/null 2>&1 & + $player $(sed -n $(echo "$titlenumber")p < "$HOME"/.cache/ytview/searches/"$search"/urls.txt) > /dev/null 2>&1 & + #$player $(sed -n $(echo "$titlenumber")p < "$HOME"/.cache/ytview/searches/"$search"/urls.txt | awk '{print $2}') > /dev/null 2>&1 & } usage() @@ -194,7 +204,7 @@ Usage: ytview [flag] [string] or ytview [videoToSearch] -h Show the help -v Get the tool version Examples: - ytview -s Family Guy Chicken Fight + ytview -s "Family Guy Chicken Fight" ytview -c Numberphile EOF } @@ -205,7 +215,7 @@ getConfiguredClient || exit 1 while getopts "vuc:s:h*:" option; do case "${option}" in s) if [[ $flag != "channel" ]]; then - search=$(printf '%s ' "$@") + search="$OPTARG" flag="search" else echo "Error: search and channel options are mutually exclusive" >&2