IMDB Search

By zenx on Jun 05, 2011

IMDB search

#!/bin/bash

wgeturl="`date`.html"
search="`echo $@ |sed 's/ /+/g'`"
wget "http://www.imdb.com/find?s=all&q=$search" -qO "$wgeturl"
tt="`cat "$wgeturl" |grep -m1 -oE "tt[0-9]{7}" |grep -m1 -E "(.*)"`"
rm "$wgeturl"
wget "http://www.imdb.com/title/$tt/" -qO "$tt.html"

title="`cat $tt.html |pcregrep -oMi "<title>(.*)</title>" |sed 's/<title>//g' |sed 's/<\/title>//g' | tr -d '\n' |sed 's/ - IMDb//' |sed 's/\ / /'`"
plot="`cat $tt.html |grep -E "<p>(.*)" -m 2 |sed 's/<p>//g' |tr -d '\n'`"
genre="`cat $tt.html |grep -oE '\/genre\/[a-zA-Z]+\"' |cut -d '/' -f3 |sed 's/\"$/ /' |sort |uniq |tr -d '\n'`"
language="`cat $tt.html |grep '\/language\/' |cut -d '>' -f2 |sed 's/<\/a//'`"
country="`cat $tt.html |grep '\/country\/' |cut -d '>' -f2 |sed 's/<\/a//'`"
keyword="`cat $tt.html |grep '\/keyword\/' |sed 's/<[^>]*>//g' |sed 's/\ / /'`"
rm "$tt.html"

if [[ "$tt" != "" ]]; then echo "http://www.imdb.com/title/$tt" ;fi
if [[ "$title" != "" ]]; then echo "Title: $title" ;fi
if [[ "$keyword" != "" ]]; then echo "Keyword: $keyword" ;fi
if [[ "$plot" != "" ]]; then echo "Plot: $plot" ;fi
if [[ "$genre" != "" ]]; then echo "Genre(s): $genre" ;fi
if [[ "$language" != "" ]]; then echo "Language: $language" ;fi
if [[ "$country" != "" ]]; then echo "Country: $country" ;fi

Comments

Sign in to comment.
zenx   -  Jul 23, 2011

Here's a snippet to download the poster from imdb (large)

!/bin/bash

search="echo $@ |sed 's/ /+/g'" ; ttlink="curl -s "http://www.imdb.com/find?s=all&q=$search" |grep -oiEm1 "\/title\/tt[0-9]+\/" |grep -m1 tt" ; imagelink="http://www.imdb.com`curl -s "http://www.imdb.com$ttlink" |grep -oE -m1 \/media\/[a-zA-Z0-9]+\/tt[0-9]+" ; image=curl -s "$imagelink" |grep -E "<img id=\"primary-img\"" |grep -oE "http\:\/\/[a-zA-Z]+.media-imdb.com\/images\/[a-zA-Z0-9]+\/[_.a-zA-Z0-9@,]+.jpg"; md5=echo "$ttlink" |cut -d '/' -f3 |md5sum |cut -d ' ' -f1` ; if [ -f "cache/$md5.jpg" ]; then echo "$md5.jpg - löytyy" ; else wget -qO "cache/$md5.jpg" "$image" ; echo "$md5.jpg - tallennettu" ;fi

 Respond  
Hawkee   -  Jun 06, 2011

@zenx Why not add it to the snippet?

 Respond  
zenx   -  Jun 06, 2011

@xbox_gamer1: This isnt mirc and i'm sure everyone knows how to execute this script.
@hawkee: grep -m1 -oE "<span class=\"rating-rating\">(.*)\/10<\/span><\/span>"

 Respond  
Wader   -  Jun 05, 2011

xbox_gamer1 why would you need to close a brace that isnt opened? there is only 1 set of braces and thats on line 6 in the regex pattern.

Also there is only 1 way to execute this script, as with most bash scripts.

 Respond  
xbox_gamer1   -  Jun 05, 2011

at that last line add this:

 } 

and in the Description put in how to use this script

 Respond  
Hawkee   -  Jun 05, 2011

Pretty neat, but it doesn't convert HTML special chars back to their ascii equivalents. It'd also be nice to have the average score show up.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.