Last active
May 20, 2018 11:49
-
-
Save veez21/e8032efb416bbe8d26b114bd37f92383 to your computer and use it in GitHub Desktop.
Get notified with your favorite animes through emails ;_;. Use with cron for maximum laziness
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 | |
# by veez21 | |
# example: https://gist.githubusercontent.com/veez21/46513d21a677315917556d1d47482e95/raw/anime.list (this is mine, follow the format which should be easy af). Tt must be a permalink of a raw gist, google it. | |
ODB=https://gist.githubusercontent.com/veez21/46513d21a677315917556d1d47482e95/raw/anime.list | |
# This one is complete and always up to date | |
rsite="https://www2.gogoanime.se" | |
site="https://www2.gogoanime.se/category" | |
site_name=$(curl -s $rsite | grep site_name | sed 's/.*content=//;s/\/.*//' | tr -d '"') | |
# Your email address that will send the emails, edit this | |
your_mail=notify.veez21@gmail.com | |
# Don't edit below pls | |
wget -q -O anime.list $ODB || { echo "Invalid link"; exit; } | |
list=($(cat anime.list)) | |
epilist=episode.list | |
finlist=finished.list | |
if [[ "$1" == "test" ]]; then | |
emails=($(cat email.test)) | |
else | |
emails=($(cat email.list)) # email address that would be notified, just put it there in the file (and it can be multiple) | |
fi | |
x=0 | |
for i in ${list[@]}; do | |
name[$x]=$(echo $i | sed "s/\^=.*//g") | |
ext[$x]=$(echo $i | sed "s/\^=/ /g" | awk '{print $2}') | |
x=$((x+1)) | |
done | |
c=0 | |
for i in ${ext[@]}; do | |
_name=$(echo ${name[$c]} | sed "s/_/ /g") | |
[ -s $epilist ] && { | |
if [[ $(grep $i $epilist | wc -l) -gt 1 ]]; then | |
sed -i "0,/${i}\^=.*/{/${i}\^=.*/d;}" $epilist | |
fi | |
if grep "$i" $epilist | grep -q "=ignore"; then | |
echo "Skipping $_name" | |
c=$((c+1)) | |
continue | |
fi | |
} | |
lat_epi=$(curl -s $site/$i | grep ep_end | grep href | tail -n1 | sed 's/<\/.*//;s/.*>//;s/.*-//') | |
status=$(curl -s $site/$i | grep 'Status:' | sed 's/.*<\/span>//;s/<\/.*//') | |
download=$(curl -s $rsite/${i}-episode-${lat_epi} | grep 'Download') | |
[ "$status" == "Completed" ] && { | |
for a in ${emails[@]}; do | |
echo "To: $a | |
From: $your_mail | |
Subject: $_name Finished | |
Content-Type: text/html; | |
<html> | |
Seems that <b>$_name</b> was detected to be already done! RIP | |
<br>Last Episode: <b>$lat_epi</b> | |
<br>$download | |
</html>" | /usr/sbin/ssmtp $a | |
done | |
echo "$_name Finished!" | |
if [[ ! $(grep -q $i $epilist) ]] || [[ ! -s $epilist ]]; then | |
echo "${name[$c]}^=$i^=$lat_epi^=ignore" >> $epilist | |
else | |
line_no=$(grep -n $i $epilist | sed 's/:.*//g') | |
sed -i ${line_no}'s/$/\^=ignore/' $epilist | |
fi | |
c=$((c+1)) | |
continue | |
} | |
if ! grep -q ${name[$c]} $epilist; then | |
echo "$_name - new entry, updating $epilist" | |
echo "${name[$c]}^=$i^=$lat_epi" >> $epilist | |
for i in ${emails[@]}; do | |
( | |
echo -e "To: $i | |
From: $your_mail | |
Subject: $_name Added to Notify List | |
Content-Type: text/html; | |
<html> | |
<h3>$_name added!</h3> | |
Latest Episode: <b>$lat_epi</b> | |
<br>$download | |
<br><br> | |
<h3>Full list:</h3> | |
<ul>" | |
for i in $(cat $epilist | sed 's/\^=.*//'); do | |
echo "<li>$(echo $i | sed 's/_/ /g')</li>" | |
done | |
echo "</ul>" | |
echo "<br><br>NOTE: This only counts the videos that are present on <a href=\"$site\" target=\"_blank\">$site_name</a> and does not count specials. | |
<html>" | |
) | /usr/sbin/ssmtp $i | |
done | |
else | |
last_epi=$(grep "${name[$c]}^=" $epilist | tr '^=' ' ' | awk '{print $3}' | head -n1) | |
if [ "$lat_epi" -gt "$last_epi" ]; then | |
echo "$_name updated to Episode $lat_epi" | |
for y in ${emails[@]}; do | |
echo -e "To: $y | |
From: $your_mail | |
Subject: $_name Episode $lat_epi | |
Content-Type: text/html; | |
<html> | |
<h3>$_name Episode $lat_epi available.</h3> | |
<br>$download | |
<br><br> | |
<br>Latest episode fetched from <a href=\"$site/$i\" target=\"_blank\">here</a>. | |
<br>NOTE: This only counts the videos that are present on <a href=\"$site\" target=\"_blank\">$site_name</a> and does not count specials. | |
</html>" | /usr/sbin/ssmtp $y | |
echo "Email to $y - done" | |
done | |
sed -i "s/${name[$c]}\^=${ext[$c]}.*/${name[$c]}\^=${ext[$c]}\^=${lat_epi}/g" $epilist | |
else | |
echo "$_name not updated" | |
fi | |
fi | |
c=$((c+1)) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do this before running:
sudo apt-get install wget ssmtp
Setup your email address to ssmtp (which you can google)
And also setup your cron properly, cd to the directory of the script when executing it in a cronjob.
anime.list
format:[Anime_Name]^=[category in gogoanime]
e.g.
Naruto_Shippuden^=naruto_shippuden
In anime name, replace all spaces with
_
, and in category use the https://www2.gogoanime.se/category/**naruto_shippuden**