Last active
February 11, 2018 02:43
-
-
Save metalx1000/74193a33c3aa3289b468f6bce25f1dd8 to your computer and use it in GitHub Desktop.
Get Recent Videos from a Youtube channel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#created by Kris Occhipinti https://filmsbykris.com | |
#Copyright Jan 20th 2018 | |
#License GPLv3 https://www.gnu.org/licenses/gpl-3.0.txt | |
goback="3day" | |
ytdir="$HOME/.ytsubs" | |
subs="$ytdir/ytsubs.lst" | |
current="$ytdir/current.lst" | |
viewed="$ytdir/viewed.lst" | |
tmpdir="/tmp/yttmp" | |
tmp="/tmp/ytsubs.lst" | |
tmp2="/tmp/ytsubs.tmp" | |
format="22" | |
func=$1 | |
length=0 | |
videos=() | |
#text Editor | |
editor="vim" | |
#max wait time while pulling video list | |
wait=15 | |
function main(){ | |
checkFiles | |
if [ "$func" == "get" ] | |
then | |
getCurrent | |
elif [ "$func" == "all" ] | |
then | |
all=true | |
showList | |
elif [ "$func" == "list" ] | |
then | |
$editor $subs | |
elif [ "$func" == "help" ] | |
then | |
help | |
else | |
showList | |
fi | |
} | |
function help(){ | |
echo -e "\e[7m Options: \e[0m" | |
echo -e "\e[32m$0 get \e[37m#updates video list" | |
echo -e "\e[32m$0 list \e[37m#edit list of subscriptions" | |
echo -e "" | |
echo -e "\e[7m Usefull: \e[0m" | |
echo -e "Add $0 to your conjobs" | |
echo "" | |
controls | |
} | |
function checkFiles(){ | |
if [ ! -d $ytdir ] | |
then | |
mkdir -p $ytdir | |
fi | |
if [ ! -f $subs ] | |
then | |
echo "metalx1000" > $subs | |
echo "BryanLunduke" >> $subs | |
fi | |
} | |
function getCurrent(){ | |
cat "$subs"|sort -u|while read user | |
do | |
echo "Getting Video List From $user..." | |
url1="https://www.youtube.com/user/$user/videos" | |
url2="https://www.youtube.com/c/$user/videos" | |
timeout $wait youtube-dl --get-id --dateafter=now-$goback "$url1" > "$tmpdir/$RANDOM" 2> /dev/null & | |
sleep 1 | |
timeout $wait youtube-dl --get-id --dateafter=now-$goback "$url2" > "$tmpdir/$RANDOM" 2> /dev/null & | |
for i in {30..01};do echo -en "\rWaiting for requests to finish $i";sleep 1; done | |
echo "" | |
done | |
cat "$tmpdir/*" > "$tmp2" | |
createList | |
} | |
function createList(){ | |
cat /tmp/ytsubs.tmp|\ | |
while read id; | |
do | |
v="https://www.youtube.com/watch?v=$id" | |
(youtube-dl --get-duration "$v";youtube-dl --get-title "$v")|\ | |
tr "\n" "-"; | |
echo "--$v"; | |
done > $current | |
} | |
function getCurrentOLD(){ | |
#remove old list | |
rm "$tmp" | |
echo "Saving to $current" | |
cat $subs|sort -u|while read sub;do | |
echo -n "Getting ${sub}'s Video List..." | |
timeout $wait youtube-dl -ciwgef $format --dateafter=now-$goback ytuser:$sub 2>/dev/null|\ | |
while read line | |
do | |
if [[ $line != *"http"* ]]; | |
then | |
echo "$sub - $line"|sed 's/&/and/g;s/\[//g;s/\]//g;s/\///g' >> "$tmp" | |
else | |
echo "$line" >> "$tmp" | |
fi | |
done | |
echo "" | |
timeout $wait youtube-dl -ciwgef $format --dateafter=now-$goback "http://youtube.com/c/$subs" 2>/dev/null|\ | |
while read line | |
do | |
if [[ $line != *"http"* ]]; | |
then | |
echo "$sub - $line"|sed 's/&/and/g;s/\[//g;s/\]//g;' >> "$tmp" | |
else | |
echo "$line" >> "$tmp" | |
fi | |
done | |
echo "" | |
done | |
mv "$tmp" "$current" | |
echo "$current updated." | |
} | |
function playVideo(){ | |
echo "Playing $1..." | |
echo "$1" >> $viewed | |
url="$(grep "$1" $current|tr "|" "-"|sed 's/---http/|http/g'|cut -d\| -f2)" | |
echo "$url" | |
mpv --fullscreen "$url" | |
} | |
function controls(){ | |
echo -e "\e[1m\e[4mKeys: w=up;s=down;e=select;q=quit\e[0m" | |
} | |
function removeViewed(){ | |
cp $current $tmp2 | |
cat $viewed|sort -u|grep -v '^http'|while read l; | |
do | |
sed -i "/$l/d" $tmp2 | |
done | |
grep -v '^http' $tmp2|sort -u | |
} | |
function showList(){ | |
if [ $all ] | |
then | |
IFS=$'\r\n' GLOBIGNORE='*' command eval 'videos=($(cat $current|tr "|" "-"|sed "s/---http/|http/g"|cut -d\| -f2))' | |
else | |
removeViewed | |
IFS=$'\r\n' GLOBIGNORE='*' command eval 'videos=($(removeViewed))' | |
fi | |
length="${#videos[@]}" | |
let x=0; | |
while [ 1 ] | |
do | |
clear | |
controls | |
for (( i=0; i<$length;i++ )); | |
do | |
if [ "$i" = "$x" ] | |
then | |
echo -e "\e[7m${videos[$i]}\e[0m" | |
else | |
echo "${videos[$i]}" | |
fi | |
done | |
read -rsn1 k | |
case $k in | |
"s") let x++;; | |
"w") let x--;; | |
"q") echo "Goodbye...";exit 0;; | |
"e") playVideo "${videos[$x]}";; | |
esac | |
if [ $x -lt 0 ] | |
then | |
let x=0; | |
elif [ $x -ge $length ] | |
then | |
let x=$length-1; | |
fi | |
done | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment