Advertisement
metalx1000

YouTube Subscription Viewer for your Shell

Jan 9th, 2018
941
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.68 KB | None | 0 0
  1. #!/bin/bash
  2. #created by Kris Occhipinti https://filmsbykris.com
  3. #Copyright Jan 9th 2018
  4. #License GPLv3 https://www.gnu.org/licenses/gpl-3.0.txt
  5.  
  6. sublist="$HOME/.ytsublist"
  7. ua="Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:21.0) G    ecko/20100101 Firefox/21.0"
  8.  
  9. ytu="https://www.youtube.com/user/"
  10. ytc="https://www.youtube.com/channel/"
  11.  
  12. #check for sub list and create it if it does not exist
  13. if [ ! -f $sublist ]
  14. then
  15.   echo "metalx1000 FilmsByKris" > $sublist
  16.   echo "BryanLunduke BryanLunduke" >> $sublist
  17. fi
  18.  
  19.  
  20. function getSubs(){
  21.   mapfile -t subs < <(cat $sublist|awk '{print $1 " " $2}'|tr '\n' ' ' )
  22.   user="$(whiptail --title "Choose a Channel" --menu "MENU" 16 80 9 $subs 3>&2 2>&1 1>&3)"
  23.  
  24.   echo $user
  25. }
  26.  
  27. function getList(){
  28.   if [[ $user == UC* ]]
  29.   then
  30.     url="${ytc}${user}/videos"
  31.   else
  32.     url="${ytu}${user}/videos"
  33.   fi
  34.   wget -qO- --user-agent="$ua" "${url}/videos"|\
  35.     grep "yt-ui-ellipsis"|\
  36.     while read line
  37.     do
  38.       title="$(echo "$line"|cut -d\" -f8|\
  39.        sed 's/&quot;//g'|sed "s/&#39;/'/g"|tr ' ' '_')"
  40.       id="$(echo "$line"|cut -d\" -f14|cut -d\= -f2)"
  41.       if [ "$id" != "" ]
  42.       then
  43.         echo "\"$id\""
  44.         echo "\"$title\""
  45.       fi
  46.     done
  47.   }
  48.  
  49.   function vidMenu(){
  50.     vid="$(whiptail --title "Video Menu" --menu "Choose a Video" 16 80 9  \
  51.      $(getList) 3>&2 2>&1 1>&3)"
  52.     video="$(echo "$vid"|sed 's/"//g')"
  53.   }
  54.  
  55.   function main(){
  56.     getSubs
  57.     if [ "$user" = "" ];then exit;fi
  58.     while [ 1 ]
  59.     do
  60.       vidMenu
  61.       if [ "$video" = "" ];then break;fi
  62.      echo "$video"
  63.      mpv "https://www.youtube.com/watch?v=$video"
  64.    done
  65.  
  66.   }
  67.  
  68.   while [ 1 ]
  69.   do
  70.     main
  71.   done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement