Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions ytview/ytview
Original file line number Diff line number Diff line change
Expand Up @@ -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/\&quot\;/\"/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

Expand All @@ -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/\&quot\;/\"/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/\&quot\;/\"/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
Expand All @@ -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()
Expand All @@ -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
}
Expand All @@ -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
Expand Down