# -*- coding: UTF-8 -*- # vi:si:et:sw=4:sts=4:ts=4 from __future__ import print_function import re import ox.cache from ox.cache import read_url from ox.html import strip_tags, decode_html from ox.text import find_re from . import imdb def get_id(url): return url.split("/")[-1] def get_url(id): return "https://www.criterion.com/films/%s" % id def get_data(id, timeout=ox.cache.cache_timeout, get_imdb=False): ''' >>> get_data('1333').get('imdbId') '0060304' >>> get_data('236')['posters'][0] 'http://s3.amazonaws.com/criterion-production/release_images/1586/ThirdManReplace.jpg' >>> get_data('786')['posters'][0] 'http://s3.amazonaws.com/criterion-production/product_images/185/343_box_348x490.jpg' ''' data = { "id": id, "url": get_url(id) } try: html = read_url(data["url"], timeout=timeout, unicode=True) except: html = read_url(data["url"], timeout=timeout).decode('utf-8', 'ignore') data["number"] = find_re(html, "Spine #(\d+)") data["title"] = decode_html(find_re(html, "

(.*?)

")) data["title"] = data["title"].split(' \u2014 The Television Version')[0].strip() results = find_re(html, '') info = re.compile('
  • (.*?)
  • ', re.DOTALL).findall(results) info = {k: strip_tags(v).strip() for k, v in info} meta = re.compile('(.*?)', re.DOTALL).findall(results): if 'datePublished' in v: data['year'] = strip_tags(v).strip() elif 'duration' in v: data['duration'] = strip_tags(v).strip() data["synopsis"] = decode_html(strip_tags(find_re(html, "
    .*?

    (.*?)

    "))) result = find_re(html, "
    (.*?)
    ") if 'Blu-Ray' in result or 'Essential Art House DVD' in result: r = re.compile('

    Other Editions

    (.*?)
    ', re.DOTALL).findall(html) if r: result = r[0] result = find_re(result, "(.*?)' % id) result = find_re(result, "src=\"(.*?)\"") if result: data["posters"] = [result.replace("_w100", "")] else: data["posters"] = [] data['posters'] = [re.sub('(\?\d+)$', '', p) for p in data['posters']] data['posters'] = [p for p in data['posters'] if p] posters = find_re(html, '
    (.*?)
    ') for poster in re.compile('.*?src="(.*?)"', re.DOTALL).findall(html) #result = find_re(html, "