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 Sources:
def __init__(self, url, Info=False, Details=False, Gallery=False):
if Info == True:
fromInfo = urllib.urlopen(url).read()
self.fromInfo = fix(fromInfo).replace(' / ','').replace(' ',' ').replace('','')
if Details == True:
self.fromDetails = fix(urllib.urlopen(url + 'plotsummary').read())
if Gallery == True:
self.fromGallery = urllib.urlopen(url + 'photogallery').read()
def Search(find):
find = find.strip().translate(string.maketrans('',''),'~!@#$%^&*()_+`-={}|[]\:";\'<>?,./').replace(' ','+')
Results = {}
page = urllib.urlopen('http://www.imdb.com/find?s=tt&q=' + find).read()
title = re.compile('(.*?)((.*?))').findall(page)
for a in title: Results[fix("%s%s" % (a[1],a[2]))] = "http://www.imdb.com/title/%s/" % (a[0])
if Results == None: return 'N/A'
else: return Results
def Title(fromInfo):
title = re.compile('tle>(.*?)<').findall(fromInfo)
if title == []: return ['N/A']
else: return title
def Year(fromInfo):
year = re.compile('ears/(.*?)"').findall(fromInfo)
if year == []: return ['N/A']
else: return year
def MPAA(fromInfo):
mpaa = re.compile(':(.*?)(.*?)<').findall(fromDetails)
if details == []: return ['N/A']
else: return details
def Plot(fromInfo):
plot = re.compile('tline:(.*?)<').findall(fromInfo)
if plot == []: return ['N/A']
else: return plot
def Countries(fromInfo):
countries = re.compile('ries/(.*?)/').findall(fromInfo)
if countries == []: return ['N/A']
else: return countries
def Languages(fromInfo):
language = re.compile('uages/(.*?)/').findall(fromInfo)
if language == []: return ['N/A']
else: return language
def Color(fromInfo):
color = re.compile('o=.*?">(.*?)<').findall(fromInfo)
if color == []: return ['N/A']
else: return color
def SoundMix(fromInfo):
sound = re.compile('x=.*?">(.*?)').findall(fromInfo)
if sound == []: return ['N/A']
else: return sound
def Certificates(fromInfo):
certs = re.compile('tes=.*?">(.*?)<').findall(fromInfo)
if certs == []: return ['N/A']
else: return certs
def Trivia(fromInfo):
trivia = re.compile('ia:\n(.*)').findall(fromInfo)
if trivia == []: return ['N/A']
else: return trivia
def Goofs(fromInfo):
goofs = re.compile('fs:\n(.*)').findall(fromInfo)
if goofs == []: return ['N/A']
else: return goofs
def Directors(fromInfo):
directors = str(re.compile(' by.*\n(.*)').findall(fromInfo))
if directors == []: return ['N/A']
else: return re.compile('">(.*?)<').findall(directors)
def Writers(fromInfo):
writers = str(re.compile('ts\n.*\n.*\n(.*)').findall(fromInfo))
if writers == []: return ['N/A']
else: return re.compile('/">(.*?)<').findall(writers)
def Rating(fromInfo):
Rating = []
for a in re.compile('(.*?) (.*)').findall(fromInfo): Rating.append('%s %s' % (a[0],a[1]))
if Rating == []: return ['N/A']
else: return Rating
def Tagline(fromInfo):
Tagline = []
for a in re.compile('gline:(.*?)<').findall(fromInfo): Tagline.append(a.strip())
if Tagline == []: return ['N/A']
else: return Tagline
def Runtime(fromInfo):
Runtime = []
for a in re.compile('me:\n(.*)').findall(fromInfo): Runtime.append(a.strip())
if Runtime == []: return ['N/A']
else: return Runtime
def Quotes(fromInfo):
Quotes = []
for a in re.compile('">(.*?):\n(.*?)<').findall(fromInfo): Quotes.append('%s: %s' % (a[0], a[1]))
if Quotes == []: return ['N/A']
else: return Quotes
def Cast(fromInfo):
Cast = re.compile('d v.*?/">(.*?)<.*?e">(.*?)<').findall(fromInfo)
CastActor,CastAlias = [],[]
for a in Cast:
CastActor.append(a[0])
CastAlias.append(a[1])
if CastActor == [] or CastAlias == []: return ['N/A']
else: return CastActor, CastAlias
def Galleries(url,fromGallery):
in_gallery, in_thumb, in_pgLeft = re.compile('"(photogallery.*?)".*?j'), re.compile('y/.*?"><.*?"(.*?jpg)"'), re.compile('(.*?) images')
Gallery,Sources,Thumbs,pgLeft,all = [],[],[],[],[]
for a in in_gallery.findall(fromGallery): Gallery.append(a)
for a in in_thumb.findall(fromGallery): all.append(a)
for a in in_pgLeft.findall(fromGallery): pgLeft.append(a)
if all != []:
for a in all: Thumbs.append(a.replace('th-',''))
elif all == []:
gallery, thumbs = [], []
for i,a in enumerate(Gallery):
for cnt in range(0,int(pgLeft[i])+1,12): gallery.append(url + a[:-1] + str(cnt))
for a in gallery: Sources.append(urllib.urlopen(a).read())
for i,a in enumerate(Sources): thumbs.append(in_thumb.findall(a))
for cnt,a in enumerate(thumbs):
for i,a in enumerate(thumbs[cnt]): Thumbs.append(a.replace('th-',''))
if Thumbs == []: return ['N/A']
else: return Thumbs