2008-07-04 13:56:02 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
|
|
|
import re
|
|
|
|
import time
|
|
|
|
|
|
|
|
from oxlib import stripTags, findRe
|
|
|
|
from oxlib.cache import getUrlUnicode
|
|
|
|
|
2009-07-13 22:25:07 +00:00
|
|
|
|
|
|
|
def getId(url):
|
|
|
|
return url.split("/")[-2]
|
|
|
|
|
|
|
|
def getData(id):
|
2009-07-13 22:34:00 +00:00
|
|
|
'''
|
|
|
|
>>> getData('129689')['cast'][1][1]
|
|
|
|
u'Marianne'
|
|
|
|
>>> getData('129689')['credits'][0][0]
|
|
|
|
u'Jean-Luc Godard'
|
|
|
|
>>> getData('129689')['posters'][0]
|
|
|
|
u'http://image.allmusic.com/00/adg/cov200/dru800/u812/u81260bbffr.jpg'
|
|
|
|
>>> getData('129689')['rating']
|
|
|
|
u'4.5'
|
|
|
|
'''
|
2009-07-13 22:25:07 +00:00
|
|
|
data = {
|
|
|
|
"url": getUrl(id)
|
|
|
|
}
|
|
|
|
html = getUrlUnicode(data["url"])
|
|
|
|
data['aka'] = parseList(html, 'AKA')
|
|
|
|
data['category'] = findRe(html, 'http://allmovie.com/explore/category/.*?">(.*?)</a>')
|
|
|
|
data['countries'] = parseList(html, 'Countries')
|
|
|
|
data['director'] = parseEntry(html, 'Director')
|
|
|
|
data['genres'] = parseList(html, 'Genres')
|
2008-07-25 14:06:50 +00:00
|
|
|
data['keywords'] = parseList(html, 'Keywords')
|
2009-07-13 22:25:07 +00:00
|
|
|
data['posters'] = [findRe(html, '<img src="(http://image\..*?)"')]
|
|
|
|
data['produced'] = parseList(html, 'Produced by')
|
|
|
|
data['rating'] = findRe(html, 'Stars" title="(.*?) Stars"')
|
2008-07-25 14:35:12 +00:00
|
|
|
data['released'] = parseEntry(html, 'Released by')
|
2009-07-13 22:25:07 +00:00
|
|
|
data['releasedate'] = parseEntry(html, 'Release')[0:10].replace(' ', '-')
|
|
|
|
data['runtime'] = findRe(html, '<td class="formed-sub" style="width: 86px;">(\d+) min.</td>')
|
|
|
|
data['set'] = parseEntry(html, 'Set In')
|
|
|
|
data['synopsis'] = parseText(html, 'Plot Synopsis')
|
|
|
|
data['themes'] = parseList(html, 'Themes')
|
|
|
|
data['types'] = parseList(html, 'Types')
|
|
|
|
data['year'] = findRe(html, '"http://allmovie.com/explore/year/(.*?)"')
|
|
|
|
html = getUrlUnicode("http://allmovie.com/work/%s/cast" % id)
|
|
|
|
data['cast'] = parseTable(html)
|
|
|
|
html = getUrlUnicode("http://allmovie.com/work/%s/credits" % id)
|
|
|
|
data['credits'] = parseTable(html)
|
|
|
|
html = getUrlUnicode("http://allmovie.com/work/%s/review" % id)
|
|
|
|
data['review'] = parseText(html, 'Review')
|
2008-07-25 11:54:20 +00:00
|
|
|
return data
|
2008-07-04 13:56:02 +00:00
|
|
|
|
2009-07-13 22:25:07 +00:00
|
|
|
def getUrl(id):
|
|
|
|
return "http://allmovie.com/work/%s/" % id
|
2008-07-04 13:56:02 +00:00
|
|
|
|
2008-07-25 14:35:12 +00:00
|
|
|
def parseEntry(html, title):
|
2009-07-13 22:25:07 +00:00
|
|
|
return stripTags(findRe(html, '<span>%s</span>(.*?)</table>' % title)).strip()
|
2008-07-25 14:35:12 +00:00
|
|
|
|
2008-07-25 14:06:50 +00:00
|
|
|
def parseList(html, title):
|
2009-07-13 22:25:07 +00:00
|
|
|
html = findRe(html, '<span>%s</span>(.*?)</table>' % title)
|
|
|
|
return map(lambda x: stripTags(x), re.compile('<li>(.*?)</li>', re.DOTALL).findall(html))
|
|
|
|
|
|
|
|
def parseTable(html):
|
|
|
|
return map(
|
|
|
|
lambda x: map(
|
|
|
|
lambda x: stripTags(x).strip().replace(' ', ''),
|
|
|
|
x.split('<td width="305">-')
|
|
|
|
),
|
|
|
|
findRe(html, '<div id="results-table">(.*?)</table>').split('</tr>')[:-1]
|
|
|
|
)
|
|
|
|
|
|
|
|
def parseText(html, title):
|
|
|
|
return stripTags(findRe(html, '%s</td>.*?<td colspan="2"><p>(.*?)</td>' % title)).strip()
|
2008-07-25 14:06:50 +00:00
|
|
|
|
2008-07-25 14:03:04 +00:00
|
|
|
if __name__ == '__main__':
|
2009-07-13 22:25:07 +00:00
|
|
|
print getData('129689')
|
|
|
|
# print getData('177524')
|
2008-07-25 14:03:04 +00:00
|
|
|
|