64 lines
2.7 KiB
Python
64 lines
2.7 KiB
Python
# -*- 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
|
|
|
|
def getMovieData(allmovieId):
|
|
data = {}
|
|
html = getUrlUnicode("http://www.allmovie.com/cg/avg.dll?p=avg&sql=1:%s~T0" % allmovieId)
|
|
data['poster'] = findRe(html, '<img src="(http://image.*?)"')
|
|
data['year'] = findRe(html, '<a href="/cg/avg.dll\?p=avg&sql=24:\d{4}">(\d{4})</a>')
|
|
data['runtime'] = findRe(html, 'sql=24:\d{4}">.*?">(.*?)min.</td></tr></table>').strip()
|
|
data['rating'] = findRe(html, '" alt="(\d+?) Stars"')
|
|
data['country'] = findRe(html, '<a href="/cg/avg.dll\?p=avg&sql=24:D\|\|\|206">(.*?)</')
|
|
data['director'] = stripTags(findRe(html, '<td class="formed-sub"><a href="/cg/avg.dll\?p=avg&sql=2:\d+">(.*?)</td>')).split(', ')
|
|
data['genre'] = parseList(html, 'Genre / Type')
|
|
data['keywords'] = parseList(html, 'Keywords')
|
|
data['themes'] = parseList(html, 'Themes')
|
|
data['boxoffice'] = parseEntry(html, 'Box office')[1:].replace(',', '')
|
|
data['produced'] = parseEntry(html, 'Produced by')
|
|
data['releasedate'] = parseEntry(html, 'Release')[0:10].replace(' ', '-')
|
|
data['released'] = parseEntry(html, 'Released by')
|
|
data['synopsis'] = stripTags(findRe(html, 'Plot Synopsis</td>.*?<td colspan="2"><p>(.*?)</td>'))
|
|
html = getUrlUnicode("http://www.allmovie.com/cg/avg.dll?p=avg&sql=1:%s~T1" % allmovieId)
|
|
data['review'] = stripTags(findRe(html, 'Review</td>.*?<td colspan="2"><p>(.*?)</td>'))
|
|
html = getUrlUnicode("http://www.allmovie.com/cg/avg.dll?p=avg&sql=1:%s~T2" % allmovieId)
|
|
data['cast'] = map(
|
|
lambda x: map(
|
|
lambda x: stripTags(x).strip(),
|
|
x.split(' </td><td width="305"><i>-')
|
|
),
|
|
findRe(html, '<div id="results-table">(.*?)</table>').split('</td></tr>')[:-1]
|
|
)
|
|
html = getUrlUnicode("http://www.allmovie.com/cg/avg.dll?p=avg&sql=1:%s~T3" % allmovieId)
|
|
data['credits'] = map(
|
|
lambda x: map(
|
|
lambda x: stripTags(x).strip(),
|
|
x.split(' </TD><TD WIDTH=305><I>-')
|
|
),
|
|
findRe(html, '<div id="results-table">(.*?)</table>').split('</TD></TR>')[:-1]
|
|
)
|
|
return data
|
|
|
|
def getPosterUrl(allmovieId):
|
|
data = getMovieData(allmovieId)
|
|
if data:
|
|
return data['poster']
|
|
return ''
|
|
|
|
def getMoviePoster(allmovieId):
|
|
# deprecated, use getPosterUrl()
|
|
return getPosterUrl(allmovieId)
|
|
|
|
def parseEntry(html, title):
|
|
return stripTags(findRe(html, '<span>%s</span>(.*?)</table>' % title))
|
|
|
|
def parseList(html, title):
|
|
return map(lambda x: stripTags(x), findRe(html, '<span>%s</span>(.*?)</table>' % title).split('</li><li>'))
|
|
|
|
if __name__ == '__main__':
|
|
print getMovieData('177524')
|
|
|