""" IMDbLib Movie Information Library:
Movie Information parsing from http://www.imdb.com
Written By:
--------
No1CaNTeL
AllTheKill
Special Thanks to AllTheKill for not just rewriting almost all of the code,
but for tutoring me through his coding, and making sure I have a full
understanding of what is being done.
Another Special thanks to Donno for having enough patience for my 1001
questions over the last year as I've been learning python.
(This doesn't mean he'll answer your 1001 questions! ;)
***Please open and read the "IMDbLib_Example1.py" for library usage***
To Do:
------
- Trailer Function
- Cast Icons
- Title Page Thumbs
"""
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)
titleReg = re.compile(r'
(.*)<.*?')
directorsReg = re.compile(r'.*?Directed by.*')
writersReg = re.compile(r'.*?Writing credits.*')
genresReg = re.compile(r'.*?Genre:.*')
yearReg = re.compile(r'.*?(.*?).*')
taglineReg = re.compile(r'.*?Tagline:(.*?)()?$')
plotReg = re.compile(r'.*?Plot Outline:(.*?).*)')
countriesReg = re.compile(r'.*?Country:.*')
languagesReg = re.compile(r'.*?Language:.*')
mpaaReg = re.compile(r'.*?/mpaa">MPAA:(.*?)
')
soundReg = re.compile(r'.*?Sound Mix:.*')
colorReg = re.compile(r'.*?Color:.*')
certReg = re.compile(r'.*?Certification:.*')
details = re.compile(r'(.*?)
')
cover = re.compile('src="(http://.*?m.jpg)" height="(.*?)" width="(.*?)">')
class IMDb:
def __init__(self,url):
self.Title = 'N/A'
self.Directors = 'N/A'
self.Writers = 'N/A'
self.Genres = 'N/A'
self.Year = 'N/A'
self.Tagline = 'N/A'
self.Plot = 'N/A'
self.Rating = 'N/A'
self.Runtime = 'N/A'
self.Cast = 'N/A'
self.Countries = 'N/A'
self.Languages = 'N/A'
self.MPAA = 'N/A'
self.Color = 'N/A'
self.Cert = 'N/A'
self.Sound = 'N/A'
self.Details = 'N/A'
self.CoverURL = 'N/A'
self.CoverSize = 'N/A'
self.Searchresults = 'N/A'
sock = urllib.urlopen(url)
page = sock.readlines()
sock.close()
i = 0
while i < len(page):
if titleReg.match(page[i]):
self.Title = titleReg.search(page[i]).group(1).strip()
if directorsReg.match(page[i]):
in_directors = re.compile(r'.*?">(.*?)(.*?)<')
i += 3
if in_writers.search(page[i]) != None:
self.Writers = in_writers.findall(page[i])
if genresReg.match(page[i]):
in_genres = re.compile(r'(.*?)<.*?(?:top|middle)">(.*?)')
self.Cast = {}
l = page[i].replace(' |
|
(.*?)')
i += 1
self.Countries = in_countries.findall(page[i])
if languagesReg.match(page[i]):
in_languages = re.compile(r'(.*?)')
i += 1
self.Languages = in_languages.findall(page[i])
if mpaaReg.match(page[i]):
self.MPAA = mpaaReg.search(page[i]).group(1).strip()
if colorReg.match(page[i]):
in_color = re.compile(r'">(.*?)')
i += 1
self.Color = in_color.findall(page[i])
if certReg.match(page[i]):
in_cert = re.compile(r'(.*?)')
i += 1
self.Cert = in_cert.findall(page[i])
if soundReg.match(page[i]):
in_sound = re.compile(r'">(.*?)')
i += 1
self.Sound = in_sound.findall(page[i])
if cover.match(page[i]):
self.CoverSize = {}
Cover = cover.findall(page[i])
for a in Cover:
self.CoverURL = a[0]
self.CoverSize[a[1]] = a[2]
i+=1
try:
sock = urllib.urlopen(url+'plotsummary')
page = sock.readlines()
sock.close()
except:
pass
for i in page:
match = details.search(i)
self.Details = []
if match != None:
self.Details = match.group(1).strip()
break
class IMDbSearch:
def __init__(self, find):
find = find.strip().translate(string.maketrans('',''),'~!@#$%^&*()_+`-={}|[]\:";\'<>?,./').replace(' ','+')
self.SearchResults = {}
sock = urllib.urlopen('http://www.imdb.com/find?s=tt&q=' + find)
page = sock.read()
sock.close()
search = re.compile('(.*?)((.*?))')
title = search.findall(page)
if title != None:
for a in title:
b = "%s%s" % (a[1],a[2])
url = "http://www.imdb.com/title/%s/" % (a[0])
Title = fix(str(b))
self.SearchResults[Title] = url
class IMDbGallery:
def __init__(self, url):
sock = urllib.urlopen(url)
page = sock.read()
sock.close()
self.Gal1_info = 'N/A'
self.Gal2_info = 'N/A'
lvl1 = re.compile(')
)