python-ox/ox/web/criterion.py

95 lines
3.3 KiB
Python
Raw Normal View History

2010-07-07 23:25:57 +00:00
# -*- coding: UTF-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
import re
import ox.cache
from ox.cache import readUrlUnicode
from ox.html import stripTags
from ox.text import findRe, removeSpecialCharacters
import imdb
def getId(url):
return url.split("/")[-1]
def getUrl(id):
return "http://www.criterion.com/films/%s" % id
def getData(id):
'''
>>> getData('1333')['imdbId']
2010-09-03 21:19:19 +00:00
u'0060304'
2010-07-07 23:25:57 +00:00
>>> getData('236')['posters'][0]
2010-09-03 21:19:19 +00:00
u'http://criterion_production.s3.amazonaws.com/release_images/1586/ThirdManReplace.jpg'
2010-07-07 23:25:57 +00:00
>>> getData('786')['posters'][0]
2010-09-03 21:19:19 +00:00
u'http://criterion_production.s3.amazonaws.com/product_images/185/343_box_348x490.jpg'
2010-07-07 23:25:57 +00:00
'''
data = {
"url": getUrl(id)
}
try:
html = readUrlUnicode(data["url"])
except:
2010-07-19 10:05:58 +00:00
html = ox.cache.readUrl(data["url"])
2010-07-07 23:25:57 +00:00
data["number"] = findRe(html, "<p class=\"spinenumber\">(.*?)</p>")
2010-07-18 18:57:22 +00:00
data["title"] = findRe(html, "<meta property=['\"]og:title['\"] content=['\"](.*?)['\"]")
2010-07-07 23:25:57 +00:00
data["director"] = findRe(html, "<h2 class=\"director\">(.*?)</h2>")
2010-07-18 18:57:22 +00:00
results = findRe(html, '<div class="left_column">(.*?)</div>')
results = re.compile("<li>(.*?)</li>").findall(results)
2010-07-07 23:25:57 +00:00
data["country"] = results[0]
data["year"] = results[1]
2010-07-18 18:57:22 +00:00
data["synopsis"] = stripTags(findRe(html, "<p><strong>SYNOPSIS:</strong> (.*?)</p>"))
result = findRe(html, "<div class=\"purchase\">(.*?)</div>")
2010-07-07 23:25:57 +00:00
if 'Blu-Ray' in result or 'Essential Art House DVD' in result:
r = re.compile('<h3 class="section_title first">Other Editions</h3>(.*?)</div>', re.DOTALL).findall(html)
if r:
result = r[0]
2010-07-18 18:57:22 +00:00
result = findRe(result, "<a href=\"(.*?)\"")
2010-07-07 23:25:57 +00:00
if not "/boxsets/" in result:
data["posters"] = [result]
else:
html_ = readUrlUnicode(result)
2010-09-03 21:19:19 +00:00
result = findRe(html_, '<a href="http://www.criterion.com/films/%s.*?">(.*?)</a>' % id)
2010-07-07 23:25:57 +00:00
result = findRe(result, "src=\"(.*?)\"")
data["posters"] = [result.replace("_w100", "")]
result = findRe(html, "<img alt=\"Film Still\" height=\"252\" src=\"(.*?)\"")
if result:
data["stills"] = [result]
data["trailers"] = []
else:
data["stills"] = [findRe(html, "\"thumbnailURL\", \"(.*?)\"")]
data["trailers"] = [findRe(html, "\"videoURL\", \"(.*?)\"")]
2010-09-03 21:19:19 +00:00
2010-07-07 23:25:57 +00:00
data['imdbId'] = imdb.getMovieId(data['title'], data['director'], data['year'])
return data
def getIds():
ids = []
2011-02-23 10:12:37 +00:00
html = readUrlUnicode("http://www.criterion.com/library/expanded_view?m=dvd&p=1&pp=50&s=spine")
results = re.compile("\&amp;p=(\d+)\&").findall(html)
pages = max(map(int, results))
for page in range(1, pages):
2010-07-07 23:25:57 +00:00
for id in getIdsByPage(page):
ids.append(id)
return map(lambda id: str(id), sorted(map(lambda id: int(id), set(ids))))
def getIdsByPage(page):
ids = []
2011-02-23 10:12:37 +00:00
html = readUrlUnicode("http://www.criterion.com/library/expanded_view?m=dvd&p=%s&pp=50&s=spine" % page)
2010-07-18 18:39:26 +00:00
results = re.compile("films/(\d+)").findall(html)
2010-07-07 23:25:57 +00:00
for result in results:
ids.append(result)
results = re.compile("boxsets/(.*?)\"").findall(html)
for result in results:
html = readUrlUnicode("http://www.criterion.com/boxsets/" + result)
2010-07-18 18:39:26 +00:00
results = re.compile("films/(\d+)").findall(html)
2010-07-07 23:25:57 +00:00
for result in results:
ids.append(result)
return set(ids)
if __name__ == '__main__':
print getIds()