Skip to content

Instantly share code, notes, and snippets.

@BryantD
Created December 25, 2022 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BryantD/2e181d3144a480d92e7f8ea025e38367 to your computer and use it in GitHub Desktop.
Save BryantD/2e181d3144a480d92e7f8ea025e38367 to your computer and use it in GitHub Desktop.
Scarecrow Video CLI Search
#!/bin/zsh
# Requires htmlq <https://github.com/mgdm/htmlq>
# Only tested on Mac OS X
[[ $# -eq 0 ]] && echo "No title supplied" && exit 1
url=https://www.scarecrow.com/45/search.html?keywords=
tmp=/tmp/scare$$.html
search=$( echo $1 | /usr/bin/sed 's/ /+/g' )
url=${url}${search}
/usr/bin/curl --silent --user-agent 'Mozilla/5.0 (Linux; Android 12; SM-S906N Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/80.0.3987.119 Mobile Safari/537.36' $url > $tmp
typeset -a details
typeset -a sections
typeset -a locations
typeset -a titles
IFS=$'\n' details=( $( /bin/cat $tmp | /usr/local/bin/htmlq --text "span.film_year" | /usr/bin/sed -e '/^[[:blank:]]*$/ d; s/\xC2\xA0/ /g' ) )
IFS=$'\n' sections=( $( cat $tmp | /usr/local/bin/htmlq --text "span.film_year > a[href*='&sec=']" | /usr/bin/sed -e '/^[[:blank:]]*$/ d' ) )
IFS=$'\n' locations=( $( cat $tmp | /usr/local/bin/htmlq --text "span.film_year > a[href*='&loc=']" | /usr/bin/sed -e '/^[[:blank:]]*$/ d' ) )
IFS=$'\n' titles=( $( cat $tmp | /usr/local/bin/htmlq --text "div.film_details > h5" | /usr/bin/sed -e '/^[[:blank:]]*$/ d' ) )
for ((i = 1; i <= $#details; i++)); do
year=${${(s: :)details[$i]}[1]}
media=${${(s: :)details[$i]}[2]}
if [[ ${media} == "BLU-RAY" ]]; then
media="Blu-Ray"
fi
print "${titles[$i]} (${year}, ${media})"
print " ${(C)sections[$i]} / ${(C)locations[$i]}"
done
/bin/rm $tmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment