Last active
October 8, 2017 23:27
-
-
Save stripedpurple/4d56e843bcdc02c41ce14fc702dd758d 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
#!/usr/bin/env bash | |
# Config | |
set -e | |
# Global variables | |
argv=( "$@" ) #places all args in an array. | |
arrayLength=${#argv[@]} #determines length of the array | |
i=0 #integer for running through the loops | |
query="$1" #the search query | |
epNumber="" #episode number | |
re='^[0-9]+$' #regular expression to denote whole number integers | |
# functions | |
function help () { | |
echo "usage: $(basename $0) <show name> <episode number>" | |
} | |
while [[ $i != $arrayLength ]]; do #cycles through the array of arguemnts | |
if [[ -z "$query" ]]; then #checks if query is empty to avoid adding uneeded plus sign to the final query | |
help | |
exit 1 | |
elif [[ ${argv[$i]} =~ $re ]] ; then #checks if arguement is an integer. This isolates the episode number | |
epNumber=${argv[$i]} #sets the value of epNumber | |
else | |
query=$query"+"${argv[$i]} #adds next argument to the query varible with a leading plus sign | |
fi | |
i=$((i+1)) #increments i. may be redundent | |
done | |
query=$query"+""episode""+"$epNumber #sets query's final value | |
string="$(curl -s "http://www.crunchyroll.com/search?from=&q=${query}" -o - | grep -m 1 "http://www.crunchyroll.com/")" #searches crunchyroll for the episode and extracts the url | |
url="$(echo ${string:21:-56})" #sets value of the url | |
streamlink --crunchyroll-username reddeath68@yahoo.com --crunchyroll-password ShellingFord-san1* $url?p480=1 480p #plays the stream at 480p quality |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment