All pastes #184613 Raw Edit

IMDbLib

public python v1 · immutable
#184613 ·published 2006-09-28 01:50 UTC
rendered paste body
import os, sys, re, urllib, stringreg = 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('<em>','').replace('</em>','').replace('<br>','')    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('</a> <i>',' ').replace('</i>','</a>')        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('<a href="/title/(.*?)/.*?">(.*?)</a>((.*?))</li>').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 Resultsdef Title(fromInfo):    title = re.compile('tle>(.*?)<').findall(fromInfo)    if title == []: return ['N/A']    else: return titledef Year(fromInfo):    year     = re.compile('ears/(.*?)"').findall(fromInfo)    if year == []: return ['N/A']    else: return yeardef MPAA(fromInfo):    mpaa     = re.compile(':</b>(.*?)<b').findall(fromInfo)    if mpaa == []: return ['N/A']    else: return mpaadef CoverURL(fromInfo):    cover     = re.compile('(http://.*?m.jpg)').findall(fromInfo)    if cover == []: return ['N/A']    else: return coverdef Genres(fromInfo):    genres     = re.compile('res/(.*?)/').findall(fromInfo)    if genres == []: return ['N/A']    else: return genresdef Details(fromDetails):    details     = re.compile('ar">(.*?)<').findall(fromDetails)    if details == []: return ['N/A']    else: return detailsdef Plot(fromInfo):    plot     = re.compile('tline:</b>(.*?)<').findall(fromInfo)    if plot == []: return ['N/A']    else: return plotdef Countries(fromInfo):    countries     = re.compile('ries/(.*?)/').findall(fromInfo)    if countries == []: return ['N/A']    else: return countriesdef Languages(fromInfo):    language = re.compile('uages/(.*?)/').findall(fromInfo)    if language == []: return ['N/A']    else: return languagedef Color(fromInfo):    color     = re.compile('o=.*?">(.*?)<').findall(fromInfo)    if color == []: return ['N/A']    else: return colordef SoundMix(fromInfo):    sound     = re.compile('x=.*?">(.*?)</a>').findall(fromInfo)    if sound == []: return ['N/A']    else: return sounddef Certificates(fromInfo):    certs     = re.compile('tes=.*?">(.*?)<').findall(fromInfo)    if certs == []: return ['N/A']    else: return certsdef Trivia(fromInfo):    trivia     = re.compile('ia:</b>\n(.*)').findall(fromInfo)    if trivia == []: return ['N/A']    else: return triviadef Goofs(fromInfo):    goofs     = re.compile('fs:</b>\n(.*)').findall(fromInfo)    if goofs == []: return ['N/A']    else: return goofsdef 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</b>\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('<b>(.*?)</b> (.*)').findall(fromInfo): Rating.append('%s %s' % (a[0],a[1]))    if Rating == []: return ['N/A']    else: return Ratingdef Tagline(fromInfo):    Tagline = []    for a in re.compile('gline:</b>(.*?)<').findall(fromInfo): Tagline.append(a.strip())    if Tagline == []: return ['N/A']    else: return Taglinedef Runtime(fromInfo):    Runtime = []    for a in re.compile('me:</b>\n(.*)').findall(fromInfo): Runtime.append(a.strip())    if Runtime == []: return ['N/A']    else: return Runtimedef Quotes(fromInfo):    Quotes = []    for a in re.compile('">(.*?)</a></b>:\n(.*?)<').findall(fromInfo): Quotes.append('%s: %s' % (a[0], a[1]))    if Quotes == []: return ['N/A']    else: return Quotesdef 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, CastAliasdef 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