# -*- coding: UTF-8 -*- # vi:si:et:sw=4:sts=4:ts=4 import re from oxlib.cache import getUrlUnicode from oxlib.html import stripTags from oxlib.net import getUrl from oxlib.text import findRe, removeSpecialCharacters import imdb 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): ''' >>> 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 = {} 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, "

(.*?)

") data["title"] = findRe(html, "

(.*?)

") data["director"] = findRe(html, "

(.*?)

") results = re.compile("

(.*?)

").findall(html) data["country"] = results[0] data["year"] = results[1] result = findRe(html, "
(.*?)
") data["synopsis"] = findRe(result, "

(.*?)

") result = findRe(html, "
(.*?)
") if 'Blu-Ray' in result or 'Essential Art House DVD' in result: result = re.compile("
(.*?)
", re.DOTALL).findall(html)[1] result = findRe(result, "") if not "/boxsets/" in result: data["posterUrl"] = result else: html_ = getUrlUnicode(result) result = findRe(html_, "(.*?)" % id) result = findRe(result, "src=\"(.*?)\"") data["posterUrl"] = result.replace("_w100", "") result = findRe(html, "\"Film>> getMovieData('Pierrot le fou', 'Jean-Luc Godard', '1965')['id'] '149' ''' data = {} if not imdbId: imdbId = imdb.getMovieId(title, director, year) id = getMovieId(imdbId = imdbId) if id: data_ = getData(id) data['id'] = data_['id'] data['posterUrl'] = data_['posterUrl'] data['synopsis'] = data_['synopsis'] return data