Youtube-Viewer (#26)

# Beta version of ytview

* Worked on some kinks, planning losing the lynx dependency

* Added unstable branch for curl

* Added install and uninstall scripts

* Added update scripts

* Merged branches

* Cleaned up a bit

* Added testing branch

* Made not player specific

* Updated README

* Update README.md

* Update README.md

* Added curl usability, but still very unstable and broken

* merged testing with unstable

* Finished curl youtubeviewer

* Added uninstall scripts

* Changed name, added a whole lot of stuff, made the requested fixes

* Fixed changes

* More changes

* removed bad folders

* Deleted testing and unstable

* Update install.sh

* Fixing install to line up with base repo

* Fixing uninstall to line up with base repo

* Fixing install to line up with base repo for v1.6.0

* Added search function

* Removed swp

* Removed more swp

* Update README.md

* Options must go in front of head command OSX

* Send the output of the player to null and run with &

* Fixing readme to align with basebranch

Removing ytview from readme until the component is complete

* Fixing readme to align with v1.6.0

* Adding back geo credit

* Fixing credit further

* Fixing readme to time of fork

* Still trying to fix conflict in readme

* Still...
This commit is contained in:
Linyos Torovoltos 2017-07-03 16:32:49 -04:00 committed by Alex Epstein
parent d9ba53065a
commit bf27d72057
1 changed files with 73 additions and 0 deletions

73
ytview/ytview Executable file
View File

@ -0,0 +1,73 @@
#!/bin/bash
# REQUIRED PACKAGES: curl
# USAGE: youtubeviewer [YouTube channel]
# EXAMPLE: youtubeviewer pewdiepie
rm -rf $HOME/.cache/ytview/
# Get the video titles
channelview() {
read -p "Choose your video player: " player
mkdir -p $HOME/.cache/ytview/channels/$channel
curl -s 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
# Get the video urls
curl -s 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
# Print 20 first video titles for the user to choose from
head -n 20 $HOME/.cache/ytview/channels/$channel/titles.txt
# Prompt the user for video number
read -p "Choose a video: " titlenumber
# Play the video with your player
$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() {
read -p "Choose your video player: " player
search=$(echo $search |sed -e "s/ /+/")
mkdir -p $HOME/.cache/ytview/searches/$search
#Get video titles
curl -s 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
#Get video urls
curl -s 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
#Print 20 first video titles for the user to choose from
head -n 20 $HOME/.cache/ytview/searches/$search/titles.txt
#Let the user choose the video number
read -p "Choose a video: " titlenumber
#Play the video with your favorite player
$player $(grep $titlenumber $HOME/.cache/ytview/searches/$search/urls.txt | awk '{print $2}') > /dev/null 2>&1 &
}
usage() {
echo "Usage: ytview [flag] [string]"
echo " -s Searches youtube"
echo " -c Shows the latest videos of a channel;"
}
while getopts c:s:h*: option
do
case "${option}" in
s) search=${OPTARG} && searchview ;;
c) channel=${OPTARG} && channelview ;;
h) usage ;;
*) usage ;;
esac
done