All pastes #74193 Raw Edit

IMDbLib

public python v1 · immutable
#74193 ·published 2006-06-28 19:31 UTC
rendered paste body
import os,sys,re,urllib#NZB_ = {'Details':[], 'Genre':[], 'Year':[], 'Tagline':[], 'Plot':[], 'Rating':[], 'Runtime':[], 'Actor':[], 'Alias':[]}def Title(url):    IMDb_ = {'Title':[]}    title = re.compile(r'<title>.*')    in_title = re.compile(r'<title>(.*?)</title>')    sock = urllib.urlopen(url)    page = sock.readlines()    sock.close()    for i in page:        if title.match(i) != None:            try:                IMDb_['Title'] = in_title.search(i).group(1).strip()            except:                IMDb_['Title'].append('None')    return str(IMDb_['Title'])def Director(url):    IMDb_ = {'Director':[]}    director = re.compile(r'<b class="blackcatheader">Directed by</b><br>')    in_director = re.compile(r'.*?">(.*?)</.*?')    sock = urllib.urlopen(url)    page = sock.readlines()    sock.close()            for i in range(len(page)):        if director.search(page[i]) != None:            i+=1            while in_director.search(page[i]) != None:                IMDb_['Director'].append(in_director.findall(page[i])) #.group(1))                i+=1        else:            i+=1    return str(IMDb_['Director'])[2:-2]def Writer(url):    IMDb_ = {'Writer':[]}    IMDb_ = {'Writer1':[]}    IMDb_ = {'Writer2':[]}    writer = re.compile(r'<b class="blackcatheader">Writing credits</b>')    in_writer = re.compile(r'.*?">(.*?)</.*?')    in_writer1 = re.compile(r'.*?">.*?</a> (.*?)<br>')    sock = urllib.urlopen(url)    page = sock.readlines()    sock.close()            for i in range(len(page)):        if writer.search(page[i]) != None:            i+=3            while in_writer.search(page[i]) != None:                IMDb_['Writer1'] = in_writer.findall(page[i])                i+=3            while in_writer1.search(page[i]) != None:                IMDb_['Writer2'] = in_writer.findall(page[i])                i+=3        else:            i+=3    if IMDb_['Writer1'][len(IMDb_['Writer1'])-1] == '(more)':        IMDb_['Writer1'].pop(len(IMDb_['Writer1'])-1)        #for a,b in zip(IMDb_['Writer1'],IMDb_['Writer2']):            #Writer = '%s as %s' % (a,b)            #IMDb_['Writer'].append(Writer)    return str(IMDb_['Writer1'])[1:-1]def Genre(url):    IMDb_ = {'Genre':[]}    genre = re.compile(r'<b class="ch">Genre:</b>')    in_genre = re.compile(r'.*?"/Sections/Genres/(.*?)/".*?')    sock = urllib.urlopen(url)    page = sock.readlines()    sock.close()            for i in range(len(page)):        if genre.search(page[i]) != None:            i+=1            while in_genre.search(page[i]) != None:                IMDb_['Genre'] = in_genre.findall(page[i])                i+=1        else:            i+=1    return str(IMDb_['Genre'])[1:-1]def Details(url):    IMDb_ = {'Details':[]}    details = re.compile(r'<p class="plotpar">.*')    in_details = re.compile(r'">(.*?)</p>')    sock = urllib.urlopen(url)    page = sock.readlines()    sock.close()    for i in page:        if details.match(i) != None:            try:                IMDb_['Details'].append(in_details.search(i).group(1).strip())            except:                IMDb_['Details'].append('None')    return str(IMDb_['Details'])[2:-2]def Year(url):    IMDb_ = {'Year':[]}    year = re.compile(r'.*<a href="/Sections/Years/.*')    in_year = re.compile(r'<a href="/Sections/Years/.*">(.*?)</a>')    sock = urllib.urlopen(url)    page = sock.readlines()    sock.close()    for i in page:        if year.match(i) != None:            try:                IMDb_['Year'].append(in_year.search(i).group(1).strip())            except:                IMDb_['Year'].append('None')    return str(IMDb_['Year'])[2:-2]def Tagline(url):    IMDb_ = {'Tagline':[]}    tagline = re.compile(r'<b class="ch">Tagline:</b>.*')    in_tagline = re.compile(r"</b>(.*)")    sock = urllib.urlopen(url)    page = sock.readlines()    sock.close()    for i in page:        if tagline.match(i) != None:            try:                IMDb_['Tagline'].append(in_tagline.search(i).group(1).strip())            except:                IMDb_['Tagline'].append('None')    return str(IMDb_['Tagline'])[2:-72]def Plot(url):    IMDb_ = {'Plot':[]}    plot = re.compile(r'<b class="ch">Plot Outline:</b>.*')    in_plot = re.compile(r"</b>(.*?)<a href")    sock = urllib.urlopen(url)    page = sock.readlines()    sock.close()    for i in page:        if plot.match(i) != None:            try:                IMDb_['Plot'].append(in_plot.search(i).group(1).strip())            except:                IMDb_['Plot'].append('None')    return str(IMDb_['Plot'])[2:-2]def Rating(url):    IMDb_ = {'Rating':[]}    rating = re.compile(r'<b>.*/.*</b>.*')    in_rating = re.compile(r"<b>(.*?)/.*</b> .*")    sock = urllib.urlopen(url)    page = sock.readlines()    sock.close()    for i in page:        if rating.match(i) != None:            try:                IMDb_['Rating'].append(in_rating.search(i).group(1).strip())            except:                IMDb_['Rating'].append('None')    return str(IMDb_['Rating'][0])def Runtime(url):    IMDb_ = {'Runtime':[]}    runtime = re.compile(r'(.*?) min')    in_runtime = re.compile(r"(.*?) min")    sock = urllib.urlopen(url)    page = sock.readlines()    sock.close()    for i in page:        if runtime.match(i) != None:            try:                IMDb_['Runtime'].append(in_runtime.search(i).group(1).strip())            except:                IMDb_['Runtime'].append('None')    return str(IMDb_['Runtime'][0]) + " min"def Cast(url):    IMDb_ = {'CastActor':[]}    IMDb_ = {'CastAlias':[]}    IMDb_ = {'Cast':[]}    cast = re.compile(r'.*<b class="blackcatheader">Cast overview, first billed only: </b>.*')    in_cast = re.compile(r'.*?/">(.*?)</.*?')    in_cast1 = re.compile(r'.*? .... </td><td valign="top">(.*?)</td>.*?')    sock = urllib.urlopen(url)    page = sock.readlines()    sock.close()    for i in page:        if cast.match(i) != None:            try:                IMDb_['CastActor'] = in_cast.findall(i)            except:                IMDb_['CastActor'].append('None')            try:                IMDb_['CastAlias'] = in_cast1.findall(i)            except:                IMDb_['CastAlias'].append('None')    for a,b in zip(IMDb_['CastActor'],IMDb_['CastAlias']):        Cast = '%s as %s' % (a,b)        IMDb_['Cast'].append(Cast)    return str(IMDb_['Cast'])def Country(url):    IMDb_ = {'Country':[]}    country = re.compile(r'<b class="ch">Country:</b>')    in_country = re.compile(r'.*?<a href="/Sections/Countries/(.*?)/">.*?')    sock = urllib.urlopen(url)    page = sock.readlines()    sock.close()            for i in range(len(page)):        if country.search(page[i]) != None:            i+=1            while in_country.search(page[i]) != None:                IMDb_['Country'] = in_country.findall(page[i])                i+=1        else:            i+=1    return str(IMDb_['Country'])[2:-2]def Language(url):    IMDb_ = {'Language':[]}    language = re.compile(r'<b class="ch">Language:</b>')    in_language = re.compile(r'.*?<a href="/Sections/Languages/(.*?)/">.*?')    sock = urllib.urlopen(url)    page = sock.readlines()    sock.close()            for i in range(len(page)):        if language.search(page[i]) != None:            i+=1            while in_language.search(page[i]) != None:                IMDb_['Language'] = in_language.findall(page[i])                i+=1        else:            i+=1    return str(IMDb_['Language'])[1:-1]title = Title("http://www.imdb.com/title/tt0317219/")print titlelanguage = Language("http://www.imdb.com/title/tt0317219/")print languagecountry = Country("http://www.imdb.com/title/tt0317219/")print countrycast = Cast("http://www.imdb.com/title/tt0317219/")print castdetail = Details("http://www.imdb.com/title/tt0317219/plotsummary")print detailgenre = Genre("http://www.imdb.com/title/tt0317219/")print genredirector = Director("http://www.imdb.com/title/tt0317219/")print director#writer = Writer("http://www.imdb.com/title/tt0441694/")writer = Writer("http://www.imdb.com/title/tt0317219/")print writeryear = Year("http://www.imdb.com/title/tt0317219/")print yeartagline = Tagline("http://www.imdb.com/title/tt0317219/")print taglineplot = Plot("http://www.imdb.com/title/tt0317219/")print plotrating = Rating("http://www.imdb.com/title/tt0317219/")print ratingruntime = Runtime("http://www.imdb.com/title/tt0317219/")print runtime