2008-07-06 18:12:30 +00:00
|
|
|
# -*- coding: UTF-8 -*-
|
|
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
|
|
|
|
|
|
|
import re
|
|
|
|
|
2009-10-12 15:18:59 +00:00
|
|
|
from oxlib.cache import readUrlUnicode
|
|
|
|
from oxlib import findRe
|
2008-07-06 18:12:30 +00:00
|
|
|
|
2009-07-13 21:12:06 +00:00
|
|
|
def getData(id):
|
2009-07-13 22:34:00 +00:00
|
|
|
'''
|
|
|
|
>>> getData('0060304')['posters'][0]
|
|
|
|
u'http://www.movieposterdb.com/posters/06_03/1967/0060304/l_99688_0060304_639fdd1e.jpg'
|
2009-08-20 18:29:34 +00:00
|
|
|
>>> getData('0123456')['posters']
|
|
|
|
[]
|
2009-07-13 22:34:00 +00:00
|
|
|
'''
|
2009-07-13 21:12:06 +00:00
|
|
|
data = {
|
|
|
|
"url": getUrl(id)
|
|
|
|
}
|
|
|
|
data["posters"] = getPostersByUrl(data["url"])
|
|
|
|
return data
|
|
|
|
|
|
|
|
def getId(url):
|
|
|
|
return url.split("/")[-2]
|
|
|
|
|
2009-08-20 18:29:34 +00:00
|
|
|
def getPostersByUrl(url, group=True):
|
2009-07-13 21:12:06 +00:00
|
|
|
posters = []
|
2009-10-12 11:47:43 +00:00
|
|
|
html = readUrlUnicode(url)
|
2009-08-20 18:29:34 +00:00
|
|
|
if url in html:
|
|
|
|
if group:
|
|
|
|
results = re.compile('<a href="(http://www.movieposterdb.com/group/.+?)\??">', re.DOTALL).findall(html)
|
|
|
|
for result in results:
|
|
|
|
posters += getPostersByUrl(result, False)
|
|
|
|
results = re.compile('<a href="(http://www.movieposterdb.com/poster/.+?)">', re.DOTALL).findall(html)
|
2009-08-20 18:04:08 +00:00
|
|
|
for result in results:
|
2009-10-12 11:47:43 +00:00
|
|
|
html = readUrlUnicode(result)
|
2009-08-20 18:29:34 +00:00
|
|
|
posters.append(findRe(html, '"(http://www.movieposterdb.com/posters/.+?\.jpg)"'))
|
2009-07-13 21:12:06 +00:00
|
|
|
return posters
|
|
|
|
|
|
|
|
def getUrl(id):
|
|
|
|
return "http://www.movieposterdb.com/movie/%s/" % id
|
2008-07-06 18:12:30 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2009-07-13 21:12:06 +00:00
|
|
|
print getData('0060304')
|
|
|
|
print getData('0133093')
|