65 lines
2.4 KiB
Python
65 lines
2.4 KiB
Python
# -*- 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.text import findRe, removeSpecialCharacters
|
|
|
|
import imdb
|
|
|
|
|
|
def getData(criterionId):
|
|
'''
|
|
>>> getData(348)['imdbId']
|
|
'0068205'
|
|
'''
|
|
data = {}
|
|
html = getUrlUnicode('http://criterion.com/asp/release.asp?id=%s' % criterionId)
|
|
data['criterionId'] = criterionId
|
|
data['posterUrl'] = getPosterUrl(criterionId)
|
|
data['synopsis'] = stripTags(findRe(html, '<h3>Synopsis</h3>(.*?)</div>'))
|
|
result = re.compile("<title>The Criterion Collection: (.*?) by (.*?)</title>").findall(html)
|
|
data['title'] = stripTags(result[0][0])
|
|
data['director'] = stripTags(result[0][1])
|
|
data['imdbId'] = imdb.getMovieId(data['title'], data['director'])
|
|
return data
|
|
|
|
def getCriterionIds():
|
|
html = getUrlUnicode('http://criterion.com/asp/list.asp?sort=spine')
|
|
return re.compile('release.asp\?id=(.*?)"').findall(html)
|
|
|
|
def getPosterUrl(criterionId):
|
|
return 'http://criterion.com/content/images/full_boxshot/%s_box_348x490.jpg' % criterionId
|
|
|
|
def getMovieId(title = '', director = '', imdbId = ''):
|
|
if not imdbId:
|
|
imdbId = imdb.getMovieId(title, director)
|
|
html = getUrlUnicode('http://criterion.com/asp/list.asp?sort=spine', timeout = 86400)
|
|
strings = findRe(html, '<table cellspacing="0" id="browse-all-table">(.*?)</table>').split('<tr>')
|
|
strings.pop(0)
|
|
for string in strings:
|
|
id = findRe(string, '"release.asp\?id=(.*?)"')
|
|
criterionTitle = findRe(string, 'class="title">(.*?)</a>')
|
|
criterionTitle = re.sub('(?<=\\w)<br>(?=\\w)', ' / ', criterionTitle)
|
|
criterionTitle = criterionTitle.replace('<br>', '')
|
|
criterionDirector = stripTags(findRe(string, '</a>.*?</td>(.*?)</td>')).strip()
|
|
if imdb.getMovieId(criterionTitle, criterionDirector) == imdbId:
|
|
return id
|
|
return ''
|
|
|
|
def getMovieData(title = '', director = '', imdbId = ''):
|
|
'''
|
|
>>> getMovieData('Le mepris', 'Jean-Luc Godard')['id']
|
|
'171'
|
|
'''
|
|
data = {}
|
|
if not imdbId:
|
|
imdbId = imdb.getMovieId(title, director)
|
|
id = getMovieId(imdbId = imdbId)
|
|
if id:
|
|
html = getUrlUnicode('http://criterion.com/asp/release.asp?id=%s' % id)
|
|
data['id'] = id
|
|
data['posterUrl'] = getPosterUrl(id)
|
|
data['synopsis'] = stripTags(findRe(html, '<h3>Synopsis</h3>(.*?)</div>'))
|
|
return data
|