import os,sys,re,urllib
#NZB_ = {'Details':[], 'Genre':[], 'Year':[], 'Tagline':[], 'Plot':[], 'Rating':[], 'Runtime':[], 'Actor':[], 'Alias':[]}
def Title(url):
IMDb_ = {'Title':[]}
title = re.compile(r'
.*')
in_title = re.compile(r'(.*?)')
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'
')
in_director = re.compile(r'.*?">(.*?)Writing credits')
in_writer = re.compile(r'.*?">(.*?).*? (.*?)
')
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'Genre:')
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'.*')
in_details = re.compile(r'">(.*?)
')
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'.*(.*?)')
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'Tagline:.*')
in_tagline = re.compile(r"(.*)")
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'Plot Outline:.*')
in_plot = re.compile(r"(.*?).*/.*.*')
in_rating = re.compile(r"(.*?)/.* .*")
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'.*.*')
in_cast = re.compile(r'.*?/">(.*?)(.*?) | .*?')
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'Country:')
in_country = re.compile(r'.*?.*?')
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'Language:')
in_language = re.compile(r'.*?.*?')
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 title
language = Language("http://www.imdb.com/title/tt0317219/")
print language
country = Country("http://www.imdb.com/title/tt0317219/")
print country
cast = Cast("http://www.imdb.com/title/tt0317219/")
print cast
detail = Details("http://www.imdb.com/title/tt0317219/plotsummary")
print detail
genre = Genre("http://www.imdb.com/title/tt0317219/")
print genre
director = 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 writer
year = Year("http://www.imdb.com/title/tt0317219/")
print year
tagline = Tagline("http://www.imdb.com/title/tt0317219/")
print tagline
plot = Plot("http://www.imdb.com/title/tt0317219/")
print plot
rating = Rating("http://www.imdb.com/title/tt0317219/")
print rating
runtime = Runtime("http://www.imdb.com/title/tt0317219/")
print runtime