python-oxweb/oxweb/criterion.py

106 lines
3.9 KiB
Python
Raw Normal View History

# -*- coding: UTF-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
import re
2008-07-03 09:24:49 +00:00
from oxlib.cache import getUrlUnicode
from oxlib.html import stripTags
2009-07-04 10:25:24 +00:00
from oxlib.net import getUrl
2008-07-03 09:24:49 +00:00
from oxlib.text import findRe, removeSpecialCharacters
2008-07-03 09:21:18 +00:00
import imdb
2008-06-19 09:47:02 +00:00
2009-07-04 10:25:24 +00:00
def getIds():
ids = []
html = getUrlUnicode("http://www.criterion.com/library/dvd")
results = re.compile("page=(.*?)\"").findall(html)
pages = int(results[len(results) - 2])
for page in range(1, pages + 1):
html = getUrlUnicode("http://www.criterion.com/library/dvd?page=" + str(page))
results = re.compile("films/(.*?)\"").findall(html)
for result in results:
ids.append(result)
results = re.compile("boxsets/(.*?)\"").findall(html)
for result in results:
html = getUrlUnicode("http://www.criterion.com/boxsets/" + result)
results = re.compile("films/(.*?)\"").findall(html)
for result in results:
ids.append(result)
return map(lambda id: str(id), sorted(map(lambda id: int(id), set(ids))))
def getData(id):
'''
2009-07-04 10:25:24 +00:00
>>> getData('1333')['imdbId']
'0060304'
>>> getData('236')['posterUrl']
'http://criterion_production.s3.amazonaws.com/release_images/1586/ThirdManReplace.jpg'
>>> getData('786')['posterUrl']
'http://criterion_production.s3.amazonaws.com/product_images/185/343_box_348x490.jpg'
'''
data = {}
2009-07-04 10:25:24 +00:00
data['id'] = id
try:
html = getUrlUnicode("http://www.criterion.com/films/" + id)
except:
html = getUrl("http://www.criterion.com/films/" + id)
data["number"] = findRe(html, "<p class=\"spinenumber\">(.*?)</p>")
data["title"] = findRe(html, "<h2 class=\"movietitle\">(.*?)</h2>")
data["director"] = findRe(html, "<h2 class=\"director\">(.*?)</h2>")
results = re.compile("<p><strong>(.*?)</strong></p>").findall(html)
data["country"] = results[0]
data["year"] = results[1]
result = findRe(html, "<div class=\"synopsis contentbox lightgray\">(.*?)</div>")
data["synopsis"] = findRe(result, "<p>(.*?)</p>")
result = findRe(html, "<div class=\"editioninfo\">(.*?)</div>")
if 'Blu-Ray' in result or 'Essential Art House DVD' in result:
result = re.compile("<div class=\"editioninfo\">(.*?)</div>", re.DOTALL).findall(html)[1]
result = findRe(result, "<a href=\"(.*?)\">")
if not "/boxsets/" in result:
data["posterUrl"] = result
else:
html_ = getUrlUnicode(result)
result = findRe(html_, "<a href=\"http://www.criterion.com/films/%s\">(.*?)</a>" % id)
result = findRe(result, "src=\"(.*?)\"")
data["posterUrl"] = result.replace("_w100", "")
result = findRe(html, "<img alt=\"Film Still\" height=\"252\" src=\"(.*?)\"")
if result:
data["stillUrl"] = result
data["trailerUrl"] = ""
else:
data["stillUrl"] = findRe(html, "\"thumbnailURL\", \"(.*?)\"")
data["trailerUrl"] = findRe(html, "\"videoURL\", \"(.*?)\"")
data['imdbId'] = imdb.getMovieId(data['title'], data['director'], data['year'])
return data
2009-07-04 10:25:24 +00:00
def getPosterUrl(id):
data = getData(id)
return data['posterUrl']
2009-07-04 10:25:24 +00:00
def getMovieId(title = '', director = '', year = '', imdbId = ''):
2008-05-09 10:39:20 +00:00
if not imdbId:
2009-07-04 10:25:24 +00:00
imdbId = imdb.getMovieId(title, director, year)
ids = getIds()
for id in ids:
data = getData(id)
if imdb.getMovieId(data['title'], data['director'], data['year'] == imdbId):
2008-05-09 10:39:20 +00:00
return id
return ''
2009-07-04 10:25:24 +00:00
def getMovieData(title = '', director = '', year = '', imdbId = ''):
2008-07-25 12:15:55 +00:00
'''
2009-07-04 10:25:24 +00:00
>>> getMovieData('Pierrot le fou', 'Jean-Luc Godard', '1965')['id']
'149'
2008-07-25 12:15:55 +00:00
'''
2008-05-09 11:21:42 +00:00
data = {}
2008-05-09 10:39:20 +00:00
if not imdbId:
2009-07-04 10:25:24 +00:00
imdbId = imdb.getMovieId(title, director, year)
2008-05-09 10:39:20 +00:00
id = getMovieId(imdbId = imdbId)
if id:
2009-07-04 10:25:24 +00:00
data_ = getData(id)
data['id'] = data_['id']
data['posterUrl'] = data_['posterUrl']
data['synopsis'] = data_['synopsis']
2008-05-09 11:21:42 +00:00
return data