include data to generate oxdb id

This commit is contained in:
j 2009-07-13 14:53:58 +02:00
parent dd5ebf0ed5
commit 27a5f0ab76

View file

@ -1,6 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4 # vi:si:et:sw=4:sts=4:ts=4
import os.path import os
import hashlib
from django.db import models from django.db import models
from django.db.models import Q from django.db.models import Q
from django.contrib.auth.models import User from django.contrib.auth.models import User
@ -22,6 +24,14 @@ class MovieId(models.Model):
created = models.DateTimeField(auto_now_add=True) created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True) modified = models.DateTimeField(auto_now=True)
title = models.CharField(max_length=1000, blank=True, default='')
year = models.CharField(max_length=4, blank=True, default='')
director = models.CharField(max_length=1000, blank=True, default='')
series_title = models.TextField(blank=True, default='')
episode_title = models.TextField(blank=True, default='')
season = models.IntegerField(default=-1)
episode = models.IntegerField(default=-1)
oxdb_id = models.CharField(max_length=42, unique=True, blank=True, null=True, default=None) oxdb_id = models.CharField(max_length=42, unique=True, blank=True, null=True, default=None)
imdb_id = models.CharField(max_length=7, unique=True, blank=True, null=True, default=None) imdb_id = models.CharField(max_length=7, unique=True, blank=True, null=True, default=None)
@ -52,6 +62,17 @@ class MovieId(models.Model):
setattr(self, _key.get(key, key), data[key]) setattr(self, _key.get(key, key), data[key])
self.save() self.save()
def gen_oxdb_id(self):
oxid_value = u"\n".join([self.title, self.director, self.year])
oxid = hashlib.sha1(oxid_value.encode('utf-8')).hexdigest()
if self.episode > -1:
oxid_value = u"\n".join([self.title, "%02d" % self.season])
oxid = hashlib.sha1(oxid_value.encode('utf-8')).hexdigest()[:20]
oxid_value = u"\n".join(["%02d" % self.episode, self.episode_title, self.director, self.year])
oxid += hashlib.sha1(oxid_value.encode('utf-8')).hexdigest()[:20]
self.oxdb_id = u"0x" + oxid
self.save()
def json(self): def json(self):
json = {} json = {}
for key in ('imdb_id', for key in ('imdb_id',