#!/bin/bash # moviedata--Given a movie or TV title, returns a list of matches. If # the user specifies an IMDb numeric index number, however, returns # the synopsis of the film instead. Uses the Internet Movie Database. setglobal titleurl = '"http://www.imdb.com/title/tt'" setglobal imdburl = '"http://www.imdb.com/find?s=tt&exact=true&ref_=fn_tt_ex&q='" setglobal tempout = ""/tmp/moviedata.$Pid"" proc summarize_film { # Produce an attractive synopsis of the film. grep "" $tempout | sed 's/<[^>]*>//g;s/(more)//' grep --color=never -A2 '<h5>Plot:' $tempout | tail -1 | \ cut -d'<' -f1 | fmt | sed 's/^/ /' exit 0 } trap "rm -f $tempout" 0 1 15 if test $Argc -eq 0 { echo "Usage: $0 {movie title | movie ID}" > !2 exit 1 } ######### # Checks whether ’re asking for a title by IMDb title number. setglobal nodigits = $[echo $1 | sed 's/[[:digit:]]*//g] if test $Argc -eq 1 -a -z $nodigits { lynx -source "$titleurl$1/combined" > $tempout summarize_film exit 0 } ########## # It's not an IMDb title number, so let's go with the search... setglobal fixedname = $[echo $ifsjoin(Argv) | tr ' ' '+] # for the URL setglobal url = ""$imdburl$fixedname"" lynx -source $imdburl$fixedname > $tempout # No results? setglobal fail = $[grep --color=never '<h1 class="findHeader">No ' $tempout] # If there's more than one matching title... if test ! -z $fail { echo "Failed: no results found for $1" exit 1 } elif test ! -z $[grep '<h1 class="findHeader">Displaying' $tempout] { grep --color=never '/title/tt' $tempout | \ sed 's/</\ </g' | \ grep -vE '(.png|.jpg|>[ ]*$)' | \ grep -A 1 "a href=" | \ grep -v '^--$' | \ sed 's/<a href="\/title\/tt//g;s/<\/a> //' | \ awk '(NR % 2 == 1) { title=$0 } (NR % 2 == 0) { print title " " $0 }' | \ sed 's/\/.*>/: /' | \ sort } exit 0