2009-07-13 08:09:58 +00:00
|
|
|
# -*- coding: UTF-8 -*-
|
|
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
|
|
|
import os
|
|
|
|
|
|
|
|
from django.conf import settings
|
|
|
|
from oxlib.cache import getUrlUnicode
|
|
|
|
from oxlib import findRe
|
|
|
|
import oxlib.net
|
|
|
|
import oxweb.criterion
|
|
|
|
|
2009-07-13 12:32:01 +00:00
|
|
|
from oxdata.lookup.models import MovieId, getMovieIdByImdbId
|
2009-07-13 08:09:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
def getPoster(id, url=None):
|
|
|
|
dirname = os.path.join(settings.DATA_ROOT, 'criterion.com', id)
|
|
|
|
filename = os.path.join(dirname, 'poster.jpg')
|
|
|
|
filename = os.path.normpath(filename)
|
|
|
|
if not os.path.exists(filename):
|
|
|
|
if not url:
|
|
|
|
data = oxweb.criterion.getData(id)
|
|
|
|
url = data['posterUrl']
|
2009-07-13 10:29:32 +00:00
|
|
|
oxlib.net.saveUrl(url, filename)
|
2009-07-13 08:09:58 +00:00
|
|
|
return filename
|
|
|
|
|
|
|
|
def archivePosters(init=False):
|
|
|
|
for criterionId in oxweb.criterion.getIds():
|
2009-07-13 08:29:42 +00:00
|
|
|
data = oxweb.criterion.getData(criterionId)
|
|
|
|
imdbId = data['imdbId']
|
2009-07-13 08:09:58 +00:00
|
|
|
try:
|
2009-07-13 12:32:01 +00:00
|
|
|
m = MovieId.objects.get(criterion_id=criterionId)
|
|
|
|
if imdbId and not m.imdb_id:
|
2009-07-13 08:29:42 +00:00
|
|
|
m.imdb_id = imdbId
|
|
|
|
m.save()
|
2009-07-13 12:32:01 +00:00
|
|
|
except MovieId.DoesNotExist:
|
2009-07-13 08:09:58 +00:00
|
|
|
if imdbId:
|
2009-07-13 12:32:01 +00:00
|
|
|
m = getMovieIdByImdbId(imdbId)
|
2009-07-13 08:09:58 +00:00
|
|
|
else:
|
2009-07-13 12:32:01 +00:00
|
|
|
m = MovieId()
|
2009-07-13 08:09:58 +00:00
|
|
|
m.criterion_id = criterionId
|
|
|
|
m.save()
|
|
|
|
url = data['posterUrl']
|
|
|
|
getPoster(criterionId, url)
|
|
|
|
|
|
|
|
def cron():
|
|
|
|
archivePosters()
|
|
|
|
|
|
|
|
def init():
|
|
|
|
archivePosters(True)
|
|
|
|
|