import os, sys, re, urllib, string
reg = re.compile(r"[0-9]{1,3};")
def fix(s):
codes = reg.findall(s)
for i in codes:
s = s.replace(i,'%c'%(int(i.replace('','').replace(';','')))).replace('','').replace('','') #.replace('
','')
return(s)
class IMDb:
def __init__(self, url):
fromInfo = urllib.urlopen(url).read()
self.fromInfo = fix(fromInfo).replace(' / ','').replace(' ',' ').replace('','')
self.fromDetails = urllib.urlopen(url + 'plotsummary').read()
self.fromGallery = urllib.urlopen(url + 'photogallery').read()
def Title(fromInfo):
# Movie's Title fromInfo saved into a list
in_title = re.compile('
(.*)<.*?')
return in_title.findall(fromInfo)
def Year(fromInfo):
# Movie's Year fromInfo saved into a list
in_year = re.compile('/Sections/Years/([0-9]*)')
return in_year.findall(fromInfo)
def Directors(fromInfo):
# Movie's Directors fromInfo saved into a list
in_directors = re.compile('.*?Directed by.*\n(.*)')
get_directors = str(in_directors.findall(fromInfo))
from_directors = re.compile(']*>([^<]*)')
return from_directors.findall(get_directors)
def MPAA(fromInfo):
#Movie's MPAA Rating fromInfo saved into a list
in_mpaa = re.compile('MPAA:([^<]*)<')
return in_mpaa.findall(fromInfo)
def Tagline(fromInfo):
# Movie's Tagline fromInfo saved into a list
in_tagline = re.compile('Tagline:([^<]*)<')
Tagline = []
for a in in_tagline.findall(fromInfo):
Tagline.append(a.strip())
return Tagline
def Runtime(fromInfo):
# Movie's Runtime fromInfo saved into a list
in_runtime = re.compile('me:\n(.*)')
Runtime = []
for a in in_runtime.findall(fromInfo):
Runtime.append(a.strip())
return Runtime
def CoverURL(fromInfo):
# Movie's Cover Image URL fromInfo saved into a list
in_cover = re.compile('(http://.*?m.jpg)')
return in_cover.findall(fromInfo)
def Writers(fromInfo):
# Movie's Writers saved into a list
in_writers = re.compile('ts\n.*\n.*\n(.*)') #\n')
get_writers = str(in_writers.findall(fromInfo))
from_writers = re.compile('/">(.*?)<')
return from_writers.findall(get_writers)
def Rating(fromInfo):
# Movie's IMDb Rating fromInfo saved into a list
in_rating = re.compile('(.*?) (.*)')
Rating = []
for a in in_rating.findall(fromInfo):
Rating.append('%s %s' % (a[0],a[1]))
return Rating
def Genres(fromInfo):
in_genres = re.compile('res/(.*?)/')
return in_genres.findall(fromInfo)
def Details(fromDetails):
in_details = re.compile('ar">(.*?)<')
return in_details.findall(fromDetails)
def Plot(fromInfo):
in_plot = re.compile('tline:([^<]*)<')
return in_plot.findall(fromInfo)
def Cast(fromInfo):
# Movie's Actor & Alias names saved in separate lists
in_cast = re.compile('d valign=.*?/">(.*?)<.*?e">(.*?)<')
Cast = in_cast.findall(fromInfo)
CastActor = []
CastAlias = []
for a in Cast:
CastActor.append(a[0])
CastAlias.append(a[1])
return CastActor, CastAlias
def Countries(fromInfo):
in_countries = re.compile('ries/(.*?)/')
return in_countries.findall(fromInfo)
def Languages(fromInfo):
in_languages = re.compile('uages/(.*?)/')
return in_languages.findall(fromInfo)
def Color(fromInfo):
in_color = re.compile('o=.*?">(.*?)<')
return in_color.findall(fromInfo)
def SoundMix(fromInfo):
in_sound = re.compile('x=.*?">(.*?)')
return in_sound.findall(fromInfo)
def Certificates(fromInfo):
in_cert = re.compile('tes=.*?">(.*?)<')
return in_cert.findall(fromInfo)
def Trivia(fromInfo):
in_trivia = re.compile('ia:\n(.*)')
return in_trivia.findall(fromInfo)
def Goofs(fromInfo):
in_goofs = re.compile('fs:\n(.*)')
return in_goofs.findall(fromInfo)
def Quotes(fromInfo):
in_qoutes = re.compile('">(.*?):\n(.*?)<')
Quotes = []
for a in in_qoutes.findall(fromInfo):
Quotes.append('%s: %s' % (a[0], a[1]))
return Quotes
def Galleries(fromGallery, page='0'):
in_gallery = re.compile('"(photogallery.*?|/gallery/.*?)">)