ongoing work
This commit is contained in:
parent
207e438e69
commit
822c139624
4 changed files with 68 additions and 4 deletions
|
@ -1,6 +1,16 @@
|
||||||
from carrot.connection import DjangoBrokerConnection
|
from carrot.connection import DjangoBrokerConnection
|
||||||
from carrot.messaging import Consumer
|
from carrot.messaging import Consumer, Publisher
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
import load
|
||||||
|
import models
|
||||||
|
|
||||||
|
def send_bg_message(msg):
|
||||||
|
conn = DjangoBrokerConnection()
|
||||||
|
publisher = Publisher(connection=conn, exchange="oxdb-bg",
|
||||||
|
routing_key="oxdb-bg")
|
||||||
|
publisher.send(msg)
|
||||||
|
publisher.close()
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
conn = DjangoBrokerConnection()
|
conn = DjangoBrokerConnection()
|
||||||
|
@ -8,12 +18,15 @@ def run():
|
||||||
consumer = Consumer(connection=conn, queue="oxdb-bg",
|
consumer = Consumer(connection=conn, queue="oxdb-bg",
|
||||||
exchange="oxdb-bg",
|
exchange="oxdb-bg",
|
||||||
routing_key="oxdb-bg")
|
routing_key="oxdb-bg")
|
||||||
def handle_background_tasks_callback(message_data, message):
|
def handle_background_tasks_callback(data, message):
|
||||||
print("Got feed import message")
|
print("Got feed import message")
|
||||||
print message_data
|
print data
|
||||||
if 'loadIMDb' in message_data:
|
if 'loadIMDb' in data:
|
||||||
imdbId = message_data['loadIMDb']
|
imdbId = message_data['loadIMDb']
|
||||||
load.loadIMDb(imdbId)
|
load.loadIMDb(imdbId)
|
||||||
|
elif 'findMovie' in data:
|
||||||
|
f = models.File.objects.get(pk=data['findMovie'])
|
||||||
|
f.findMovie()
|
||||||
message.ack()
|
message.ack()
|
||||||
consumer.register_callback(handle_background_tasks_callback)
|
consumer.register_callback(handle_background_tasks_callback)
|
||||||
consumer.wait() # Go into the consumer loop.
|
consumer.wait() # Go into the consumer loop.
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
import re
|
import re
|
||||||
import os.path
|
import os.path
|
||||||
import random
|
import random
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
@ -16,6 +17,7 @@ from django.utils import simplejson as json
|
||||||
import utils
|
import utils
|
||||||
import managers
|
import managers
|
||||||
import fields
|
import fields
|
||||||
|
import load
|
||||||
|
|
||||||
class MovieImdb(models.Model):
|
class MovieImdb(models.Model):
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
|
@ -74,6 +76,39 @@ class MovieOxdb(models.Model):
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return u"%s (%s)" % (self.title, self.year)
|
return u"%s (%s)" % (self.title, self.year)
|
||||||
|
|
||||||
|
class MovieExtra(models.Model):
|
||||||
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
|
modified = models.DateTimeField(auto_now=True)
|
||||||
|
|
||||||
|
title = models.CharField(max_length=1000)
|
||||||
|
description = models.TextField(blank=True)
|
||||||
|
contributor = models.CharField(max_length=1000)
|
||||||
|
|
||||||
|
def getMovie(info):
|
||||||
|
'''
|
||||||
|
info dict with:
|
||||||
|
imdbId, title, director, episode_title, season, series
|
||||||
|
'''
|
||||||
|
if 'imdbId' in info:
|
||||||
|
try:
|
||||||
|
movie = models.Movie.byImdbId(imdbId)
|
||||||
|
except models.Movie.DoesNotExist:
|
||||||
|
movie = load.loadIMDb(movieId==info['imdbId'])
|
||||||
|
else:
|
||||||
|
q = Movie.objects.filter(title=info['title'], year=info['director'])
|
||||||
|
if q.count() > 1:
|
||||||
|
movie = q[0]
|
||||||
|
else:
|
||||||
|
movie = newMovie(info['title'], info['director'], '')
|
||||||
|
updated = False
|
||||||
|
for key in ('episode_title', 'season', 'year'):
|
||||||
|
if key in info:
|
||||||
|
setattr(movie.oxdb, key, info[key])
|
||||||
|
updated = True
|
||||||
|
if updated:
|
||||||
|
movie.save()
|
||||||
|
return movie
|
||||||
|
|
||||||
def newMovie(title, director, year):
|
def newMovie(title, director, year):
|
||||||
movie = Movie()
|
movie = Movie()
|
||||||
oxdb = MovieOxdb()
|
oxdb = MovieOxdb()
|
||||||
|
@ -96,6 +131,7 @@ def movie_path(f, size):
|
||||||
class Movie(models.Model):
|
class Movie(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)
|
||||||
|
published = models.DateTimeField(default=datetime.now, editable=False)
|
||||||
|
|
||||||
#only movies that have metadata from files are available,
|
#only movies that have metadata from files are available,
|
||||||
#this is indicated by setting available to True
|
#this is indicated by setting available to True
|
||||||
|
@ -106,10 +142,13 @@ class Movie(models.Model):
|
||||||
|
|
||||||
imdb = models.OneToOneField('MovieImdb', null=True, related_name='movie')
|
imdb = models.OneToOneField('MovieImdb', null=True, related_name='movie')
|
||||||
oxdb = models.OneToOneField('MovieOxdb', null=True, related_name='movie')
|
oxdb = models.OneToOneField('MovieOxdb', null=True, related_name='movie')
|
||||||
|
extra = models.OneToOneField('MovieOxdb', null=True, related_name='movie')
|
||||||
|
|
||||||
objects = managers.MovieManager()
|
objects = managers.MovieManager()
|
||||||
|
|
||||||
def get(self, key, default=None):
|
def get(self, key, default=None):
|
||||||
|
if self.extra and getattr(self.extra, key):
|
||||||
|
return getattr(self.extra, key)
|
||||||
if self.oxdb and getattr(self.oxdb, key):
|
if self.oxdb and getattr(self.oxdb, key):
|
||||||
return getattr(self.oxdb, key)
|
return getattr(self.oxdb, key)
|
||||||
if self.imdb:
|
if self.imdb:
|
||||||
|
@ -949,6 +988,8 @@ FILE_TYPES = (
|
||||||
class File(models.Model):
|
class File(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)
|
||||||
|
published = models.DateTimeField(default=datetime.now, editable=False)
|
||||||
|
|
||||||
verified = models.BooleanField(default=False)
|
verified = models.BooleanField(default=False)
|
||||||
|
|
||||||
oshash = models.CharField(blank=True, unique=True, max_length=16)
|
oshash = models.CharField(blank=True, unique=True, max_length=16)
|
||||||
|
@ -1060,6 +1101,11 @@ class File(models.Model):
|
||||||
self.path = self.info['path']
|
self.path = self.info['path']
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
|
def findMovie(self):
|
||||||
|
info = utils.parsePath(self.path)
|
||||||
|
self.movie = getMovie(info)
|
||||||
|
self.save()
|
||||||
|
|
||||||
class Still(models.Model):
|
class Still(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)
|
||||||
|
|
|
@ -23,6 +23,7 @@ from oxdjango.decorators import login_required_json
|
||||||
|
|
||||||
import models
|
import models
|
||||||
import utils
|
import utils
|
||||||
|
from daemon import send_bg_message
|
||||||
|
|
||||||
'''
|
'''
|
||||||
field.length -> movie.sort.all()[0].field
|
field.length -> movie.sort.all()[0].field
|
||||||
|
@ -426,6 +427,8 @@ def update_archive(request, archive):
|
||||||
print "adding file", oshash, data['path']
|
print "adding file", oshash, data['path']
|
||||||
f = models.ArchiveFile.get_or_create(archive, oshash)
|
f = models.ArchiveFile.get_or_create(archive, oshash)
|
||||||
f.update(data)
|
f.update(data)
|
||||||
|
if not f.movie:
|
||||||
|
send_bg_message({'findMovie': f.id})
|
||||||
#FIXME: only add if it was not in File
|
#FIXME: only add if it was not in File
|
||||||
else:
|
else:
|
||||||
f = q[0]
|
f = q[0]
|
||||||
|
|
|
@ -68,6 +68,7 @@ def preferences(request):
|
||||||
key = request.GET.get('key', None)
|
key = request.GET.get('key', None)
|
||||||
value = request.GET.get('value', None)
|
value = request.GET.get('value', None)
|
||||||
user = request.user
|
user = request.user
|
||||||
|
response['preferences'] = {}
|
||||||
if not key: # return all preferences for current user
|
if not key: # return all preferences for current user
|
||||||
for p in models.Preference.objects.filter(user=user):
|
for p in models.Preference.objects.filter(user=user):
|
||||||
response['preferences'][p.key] = p.value
|
response['preferences'][p.key] = p.value
|
||||||
|
@ -76,6 +77,7 @@ def preferences(request):
|
||||||
p, created = models.Preference.objects.get_or_create(user=user, key=key)
|
p, created = models.Preference.objects.get_or_create(user=user, key=key)
|
||||||
response['preferences'][key] = p.value
|
response['preferences'][key] = p.value
|
||||||
else: # set preference
|
else: # set preference
|
||||||
|
del response['preferences']
|
||||||
response['message'] = '%s saved.' % key
|
response['message'] = '%s saved.' % key
|
||||||
if key == 'password':
|
if key == 'password':
|
||||||
user.set_password(value)
|
user.set_password(value)
|
||||||
|
|
Loading…
Reference in a new issue