Created
May 18, 2016 14:49
-
-
Save agentd00nut/2321c3fceb5cd457ebea3871a5584cc5 to your computer and use it in GitHub Desktop.
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
find_episode_link(){ | |
root=$1 | |
page=$2 | |
show=$3 | |
ep=$4 | |
url="${root}?page=${page}" | |
thing=$(curl -s -L "$url" | egrep -o "\/watch\/${show}\/.*-${ep}-*.*'" | uniq | sed "s/'//g" ); | |
page=$((page+1)) | |
echo ${url} | |
if [ -z "$thing" ]; then | |
#thing=$(find_episode_link $root $page $show $ep) | |
find_episode_link $root $page $show $ep | |
fi | |
echo $thing | |
} | |
get_episode_total(){ | |
url=$1 | |
total=$(curl -s -L "$url" | egrep -o "(total: [0-9]*)" | sed "s/total: //g" | uniq) | |
echo $total | |
} | |
pad_episode_string(){ | |
ep=$1 | |
total_episodes=$2 | |
if [ "${#ep}" -lt "${#total_episodes}" ]; then | |
pad_chars=$(( ${#total_episodes} - ${#ep} )) | |
i=0 | |
while [ "$i" -lt "$pad_chars" ]; do | |
ep="0$ep" | |
i=$(( $i+1 )) | |
done | |
fi | |
echo "$ep" | |
} | |
scrub_bullshit_shownames(){ | |
name=$1 | |
echo ${name%-[0-9]} | |
} | |
anime(){ | |
show=$1 | |
clean_show=$(scrub_bullshit_shownames $1); | |
show_url="http://www.animeonhand.com/iam/$show" | |
total_episodes=$(get_episode_total ${show_url} ) | |
ep=$(pad_episode_string $2 ${total_episodes}) | |
episode_url="http://www.animeonhand.com/watch/$show/"$clean_show"-"$ep | |
alt_episode_url="http://www.animeonhand.com/watch/$show/"$clean_show"-"$2 | |
echo "Trying: $episode_url" | |
#URL=$(curl -s -L "$episode_url" | egrep -o "http\:\/\/cdn[0-9]+\.hostyourmediafiles\.com\/media\/[a-z]+\/[0-9]+\/[a-z\_]+\.mp4" | uniq ); | |
URL=$(curl -s -L "$episode_url" | egrep -o "http\:\/\/cdn[0-9]+\.hostyourmediafiles\.com.*\.mp4"); | |
if [ -z "$URL" ]; then | |
echo "Trying: $alt_episode_url" | |
URL=$(curl -s -L "$alt_episode_url" | egrep -o "http\:\/\/cdn[0-9]+\.hostyourmediafiles\.com.*\.mp4"); | |
fi | |
if [ -z "$URL" ]; then | |
episode_url=$(curl -s -L "http://www.animeonhand.com/iam/$show" | egrep -o "${1}\/.*${ep}'" | uniq | tail -n1 | sed "s/'//g" ); | |
if [ -z "$episode_url" ]; then | |
echo "Searching for this episode... this can take a long ass time." | |
episode_url=`find_episode_link "http://www.animeonhand.com/iam/$show" 2 $show $ep` | |
fi | |
episode_url="http://www.animeonhand.com/watch/$episode_url" | |
echo "Trying: $episode_url" | |
URL=$(curl -s -L $episode_url | egrep -o "http\:\/\/cdn[0-9]+\.hostyourmediafiles\.com\/media\/[a-z]+\/[0-9]+\/.*\.mp4"|uniq); | |
fi | |
echo "MEDIA: $URL"; | |
URL=$( echo "$URL" | sed 's/cdn[0-9]*/cdn18/g') | |
echo "EDITED MEDIA: $URL" | |
echo "Checking Response Code... "; | |
CODE=$(curl -s -o /dev/null -I -w "%{http_code}" ${URL}); | |
echo "Got: $CODE" | |
if [ "$CODE" == "404" ]; then | |
echo "Bogus media url, retrying... ${URL} ... ${CODE}"; | |
anime $1 $2 | |
fi | |
mpv $URL; | |
} | |
setup(){ | |
rm ~/watch_anime_list.txt | |
for letter in {0..9} ; do echo ${letter}; curl -s http://www.animeonhand.com/anime/list/${letter} | egrep -o "iam/.*\"" | sed 's/\"//g' | sed 's/iam\///g' | uniq >> ~/watch_anime_list.txt ; done | |
for letter in {A..Z} ; do echo ${letter}; curl -s http://www.animeonhand.com/anime/list/${letter} | egrep -o "iam/.*\"" | sed 's/\"//g' | sed 's/iam\///g' | uniq >> ~/watch_anime_list.txt ; done | |
} | |
show=$( echo "$1" | sed 's/ /-/g') | |
ep=$2 | |
if [ "$show" == "SETUP" ]; then | |
setup; | |
exit; | |
fi | |
if [ -z "$2" ]; then | |
echo "Please pass both a show name and episode number"; | |
exit; | |
fi | |
shows=(`grep "$show" ~/watch_anime_list.txt`) | |
if [ ${#shows[@]} -gt 1 ]; then | |
echo "${show} not found, did you mean..."; | |
i=0 | |
for match in "${shows[@]}"; | |
do | |
echo "$i: $match"; | |
i=$(($i+1)) | |
done | |
echo -n "Enter Search Number: " | |
read show | |
show=${shows[${show}]} | |
else | |
show=${shows[0]} | |
fi | |
if [ -z "$show" ]; then | |
echo "Could not find '$1'."; | |
exit; | |
fi | |
echo "${show} ${ep}"; | |
anime ${show} ${ep}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment