make systems without imdb work

This commit is contained in:
j 2011-01-28 14:18:38 +05:30
parent 1014bc8a89
commit ec28dc05e1
10 changed files with 76 additions and 36 deletions

View file

@ -4,6 +4,8 @@ from __future__ import division, with_statement
from django.db import models from django.db import models
from django.contrib.auth.models import User from django.contrib.auth.models import User
import ox
import utils import utils

View file

@ -30,7 +30,4 @@ def site_config():
site_config['keys'] = {} site_config['keys'] = {}
for key in site_config['itemKeys']: for key in site_config['itemKeys']:
site_config['keys'][key['id']] = key site_config['keys'][key['id']] = key
site_config['_findKeys'] = {}
for key in site_config['findKeys']:
site_config['_findKeys'][key['id']] = key
return site_config return site_config

View file

@ -52,7 +52,10 @@ def getPage(request):
name = data name = data
else: else:
name = data['name'] name = data['name']
page = get_object_or_404_json(models.Page, name=name) page, created = models.Page.objects.get_or_create(name=name)
if created:
page.body = 'Insert text here'
page.save()
response = json_response({'name': page.name, 'body': page.body}) response = json_response({'name': page.name, 'body': page.body})
return render_to_json_response(response) return render_to_json_response(response)
actions.register(getPage) actions.register(getPage)

View file

@ -77,7 +77,8 @@ class File(models.Model):
for key in ('duration', 'size'): for key in ('duration', 'size'):
setattr(self, key, self.info.get(key, 0)) setattr(self, key, self.info.get(key, 0))
if 'video' in self.info and self.info['video']: if 'video' in self.info and self.info['video'] and \
'width' in self.info['video'][0]:
video = self.info['video'][0] video = self.info['video'][0]
self.video_codec = video['codec'] self.video_codec = video['codec']
self.width = video['width'] self.width = video['width']

View file

@ -6,6 +6,7 @@ from celery.decorators import task
from item.utils import parse_path from item.utils import parse_path
from item.models import get_item from item.models import get_item
from django.conf import settings
import models import models
@ -55,7 +56,10 @@ def update_files(user, volume, files):
#new oshash, add to database #new oshash, add to database
else: else:
if not i: if not i:
item_info = parse_path(folder) if settings.USE_IMDB:
item_info = parse_path(folder)
else:
item_info = parse_path(path)
i = get_item(item_info) i = get_item(item_info)
file_object = models.File() file_object = models.File()
file_object.oshash = oshash file_object.oshash = oshash

View file

@ -6,6 +6,8 @@ from datetime import datetime
import os.path import os.path
import subprocess import subprocess
from glob import glob from glob import glob
import uuid
import unicodedata
from django.db import models from django.db import models
from django.db.models import Sum from django.db.models import Sum
@ -76,12 +78,15 @@ def get_item(info):
except Item.DoesNotExist: except Item.DoesNotExist:
item.save() item.save()
else: else:
try: qs = Item.objects.filter(find__key='title', find__value=info['title'])
item = Item.objects.get(itemId=info['itemId']) if qs.count() == 1:
except Item.DoesNotExist: item = qs[0]
item = Item(itemId=info['itemId']) else:
item = Item()
item.data = {
'title': info['title']
}
item.save() item.save()
return item return item
@ -195,13 +200,20 @@ class Item(models.Model):
def __unicode__(self): def __unicode__(self):
year = self.get('year') year = self.get('year')
if year: if year:
return u'%s (%s)' % (self.get('title'), self.get('year')) return u'%s (%s)' % (self.get('title', 'Untitled'), self.get('year'))
return self.get('title') return self.get('title', u'Untitled')
def get_absolute_url(self): def get_absolute_url(self):
return '/%s' % self.itemId return '/%s' % self.itemId
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
if not self.id:
if not self.itemId:
self.itemId = str(uuid.uuid1())
super(Item, self).save(*args, **kwargs)
if not settings.USE_IMDB:
self.itemId = ox.to32(self.id)
self.oxdbId = self.oxdb_id() self.oxdbId = self.oxdb_id()
if self.poster: if self.poster:
@ -367,6 +379,8 @@ class Item(models.Model):
def oxdb_id(self): def oxdb_id(self):
if not settings.USE_IMDB:
return self.itemId
return utils.oxdb_id(self.get('title', ''), self.get('director', []), str(self.get('year', '')), return utils.oxdb_id(self.get('title', ''), self.get('director', []), str(self.get('year', '')),
self.get('season', ''), self.get('episode', ''), self.get('season', ''), self.get('episode', ''),
self.get('episode_title', ''), self.get('episode_director', []), self.get('episode_year', '')) self.get('episode_title', ''), self.get('episode_director', []), self.get('episode_year', ''))
@ -388,7 +402,8 @@ class Item(models.Model):
f.delete() f.delete()
#FIXME: use site_config #FIXME: use site_config
save('title', '\n'.join([self.get('title'), self.get('original_title', '')])) save('title', u'\n'.join([self.get('title', 'Untitled'),
self.get('original_title', '')]))
for key in self.facet_keys: for key in self.facet_keys:
if key == 'character': if key == 'character':
@ -466,7 +481,7 @@ class Item(models.Model):
if name not in base_keys: if name not in base_keys:
if sort_type == 'title': if sort_type == 'title':
value = utils.sort_title(canonicalTitle(self.get(source))) value = utils.sort_title(canonicalTitle(self.get(source, u'Untitled')))
value = utils.sort_string(value) value = utils.sort_string(value)
set_value(s, name, value) set_value(s, name, value)
elif sort_type == 'person': elif sort_type == 'person':
@ -577,7 +592,11 @@ class Item(models.Model):
''' '''
def frame(self, position, width=128): def frame(self, position, width=128):
stream = self.streams.filter(profile=settings.VIDEO_PROFILE+'.webm')[0] stream = self.streams.filter(profile=settings.VIDEO_PROFILE+'.webm')
if stream.count()>0:
stream = stream[0]
else:
return None
path = os.path.join(settings.MEDIA_ROOT, self.path(), path = os.path.join(settings.MEDIA_ROOT, self.path(),
'frames', "%d"%width, "%s.jpg"%position) 'frames', "%d"%width, "%s.jpg"%position)
if not os.path.exists(path): if not os.path.exists(path):
@ -739,9 +758,12 @@ class Item(models.Model):
'-l', timeline, '-l', timeline,
'-p', poster '-p', poster
] ]
if settings.USE_IMDB and len(self.itemId) == 7: if settings.USE_IMDB:
if len(self.itemId) == 7:
cmd += ['-i', self.itemId]
cmd += ['-o', self.oxdbId]
else:
cmd += ['-i', self.itemId] cmd += ['-i', self.itemId]
cmd += ['-o', self.oxdbId]
p = subprocess.Popen(cmd) p = subprocess.Popen(cmd)
p.wait() p.wait()
return posters.keys() return posters.keys()

View file

@ -8,6 +8,7 @@ import re
import hashlib import hashlib
import unicodedata import unicodedata
from django.conf import settings
import ox import ox
import ox.iso import ox.iso
from ox.normalize import normalizeName, normalizeTitle from ox.normalize import normalizeName, normalizeTitle
@ -166,11 +167,13 @@ def parse_path(path):
M/McCarthy, Thomas/The Visitor (2007) M/McCarthy, Thomas/The Visitor (2007)
G/Godard, Jean-Luc/Histoire(s) du cinema_ Toutes les histoires (1988) G/Godard, Jean-Luc/Histoire(s) du cinema_ Toutes les histoires (1988)
''' '''
import ox.web.imdb
search_title = oxdb_title(path, True)
r = {} r = {}
r['title'] = oxdb_title(path) r['title'] = oxdb_title(path)
r['director'] = oxdb_directors(path) if not settings.USE_IMDB:
return r
import ox.web.imdb
search_title = oxdb_title(path, True)
r['directors'] = oxdb_directors(path)
year = ox.findRe(path, '\((\d{4})\)') year = ox.findRe(path, '\((\d{4})\)')
if year: if year:
r['year'] = year r['year'] = year

View file

@ -51,7 +51,7 @@ def render_poster(id, title, frame, timeline, poster):
else: else:
pixel = list(poster_image.getpixel((x, y))) pixel = list(poster_image.getpixel((x, y)))
for c in range(3): for c in range(3):
pixel[c] = (pixel[c] + poster_color[c]) / 4 pixel[c] = int((pixel[c] + poster_color[c]) / 4)
poster_image.putpixel((x, y), tuple(pixel)) poster_image.putpixel((x, y), tuple(pixel))
drawText(poster_image, ((poster_width - text_size[0]) / 2, text_top + (text_height - text_size[1]) / 2), text, font_file, font_size, poster_color) drawText(poster_image, ((poster_width - text_size[0]) / 2, text_top + (text_height - text_size[1]) / 2), text, font_file, font_size, poster_color)
poster_image.save(poster) poster_image.save(poster)
@ -60,6 +60,8 @@ def main():
parser = OptionParser() parser = OptionParser()
parser.add_option('-i', '--id', dest='id', help='Pad.ma Id') parser.add_option('-i', '--id', dest='id', help='Pad.ma Id')
parser.add_option('-t', '--title', dest='title', help='Title', default='') parser.add_option('-t', '--title', dest='title', help='Title', default='')
parser.add_option('-d', '--director', dest='director', help='Director', default='')
parser.add_option('-y', '--year', dest='year', help='Year', default='')
parser.add_option('-f', '--frame', dest='frame', help='Poster frame (image file to be read)') parser.add_option('-f', '--frame', dest='frame', help='Poster frame (image file to be read)')
parser.add_option('-l', '--timeline', dest='timeline', help='Timeline (image file to be read)') parser.add_option('-l', '--timeline', dest='timeline', help='Timeline (image file to be read)')
parser.add_option('-p', '--poster', dest='poster', help='Poster (image file to be written)') parser.add_option('-p', '--poster', dest='poster', help='Poster (image file to be written)')

View file

@ -132,6 +132,7 @@ INSTALLED_APPS = (
'timeline', 'timeline',
'user', 'user',
'api', 'api',
'urlalias',
) )
AUTH_PROFILE_MODULE = 'user.UserProfile' AUTH_PROFILE_MODULE = 'user.UserProfile'

View file

@ -527,7 +527,7 @@ var pandora = new Ox.App({
}, },
backButton: function() { backButton: function() {
var that = Ox.Button({ var that = Ox.Button({
title: 'Back to Movies', title: 'Back to ' + app.config.itemName.plural,
width: 96 width: 96
}).css({ }).css({
float: 'left', float: 'left',
@ -725,7 +725,7 @@ var pandora = new Ox.App({
elements: $.merge(app.user.ui.list ? [ elements: $.merge(app.user.ui.list ? [
app.$ui.findListSelect = new Ox.Select({ app.$ui.findListSelect = new Ox.Select({
items: [ items: [
{id: 'all', title: 'Find: All Movies'}, {id: 'all', title: 'Find: All ' + app.config.itemName.plural},
{id: 'list', title: 'Find: This List'} {id: 'list', title: 'Find: This List'}
], ],
overlap: 'right', overlap: 'right',
@ -1725,7 +1725,7 @@ var pandora = new Ox.App({
} else if (app.user.ui.itemView == 'player') { } else if (app.user.ui.itemView == 'player') {
var video = result.data.item.stream, var video = result.data.item.stream,
subtitles = result.data.item.layers.subtitles; subtitles = result.data.item.layers.subtitles;
video.height = 96; video.height = video.profiles[0]
video.width = parseInt(video.height * video.aspectRatio / 2) * 2; video.width = parseInt(video.height * video.aspectRatio / 2) * 2;
video.url = video.baseUrl + '/' + video.height + 'p.' + ($.support.video.webm ? 'webm' : 'mp4'); video.url = video.baseUrl + '/' + video.height + 'p.' + ($.support.video.webm ? 'webm' : 'mp4');
app.$ui.contentPanel.replace(1, app.$ui.player = new Ox.VideoPanelPlayer({ app.$ui.contentPanel.replace(1, app.$ui.player = new Ox.VideoPanelPlayer({
@ -1766,7 +1766,7 @@ var pandora = new Ox.App({
'out': 10, 'out': 10,
'text': 'This subtitle is just a test...' 'text': 'This subtitle is just a test...'
}]; }];
video.height = 96; video.height = video.profiles[0]
video.width = parseInt(video.height * video.aspectRatio / 2) * 2; video.width = parseInt(video.height * video.aspectRatio / 2) * 2;
video.url = video.baseUrl + '/' + video.height + 'p.' + ($.support.video.webm ? 'webm' : 'mp4'); video.url = video.baseUrl + '/' + video.height + 'p.' + ($.support.video.webm ? 'webm' : 'mp4');
that.replace(0, app.$ui.editor = new Ox.VideoEditor({ that.replace(0, app.$ui.editor = new Ox.VideoEditor({
@ -2260,7 +2260,7 @@ var pandora = new Ox.App({
if (data.ids.length == 1) { if (data.ids.length == 1) {
$still = $('<img>') $still = $('<img>')
.attr({ .attr({
src: 'http://0xdb.org/' + data.ids[0] + '/still.jpg' src: '/' + data.ids[0] + '/icon.jpg'
}) })
.one('load', function() { .one('load', function() {
if (data.ids[0] != app.ui.selectedMovies[0]) { if (data.ids[0] != app.ui.selectedMovies[0]) {
@ -2397,7 +2397,7 @@ var pandora = new Ox.App({
] }, ] },
{ id: 'listMenu', title: 'List', items: [ { id: 'listMenu', title: 'List', items: [
{ id: 'history', title: 'History', items: [ { id: 'history', title: 'History', items: [
{ id: 'allmovies', title: 'All Movies' } { id: 'allmovies', title: 'All ' + app.config.itemName.plural }
] }, ] },
{ id: 'lists', title: 'View List', items: [ { id: 'lists', title: 'View List', items: [
{ id: 'favorites', title: 'Favorites' } { id: 'favorites', title: 'Favorites' }
@ -2412,7 +2412,7 @@ var pandora = new Ox.App({
{ id: 'newsmartlist', title: 'New Smart List...', keyboard: 'alt control n' }, { id: 'newsmartlist', title: 'New Smart List...', keyboard: 'alt control n' },
{ id: 'newsmartlistfromresults', title: 'New Smart List from Results...', keyboard: 'shift alt control n' }, { id: 'newsmartlistfromresults', title: 'New Smart List from Results...', keyboard: 'shift alt control n' },
{}, {},
{ id: 'addmovietolist', title: ['Add Selected Movie to List...', 'Add Selected Movies to List...'], disabled: true }, { id: 'addmovietolist', title: ['Add Selected ' + app.config.itemName.singular + ' to List...', 'Add Selected ' + app.config.itemName.plural + ' to List...'], disabled: true },
{}, {},
{ id: 'setposterframe', title: 'Set Poster Frame', disabled: true } { id: 'setposterframe', title: 'Set Poster Frame', disabled: true }
]}, ]},
@ -2430,7 +2430,7 @@ var pandora = new Ox.App({
{ id: 'invertselection', title: 'Invert Selection', disabled: true, keyboard: 'alt control a' } { id: 'invertselection', title: 'Invert Selection', disabled: true, keyboard: 'alt control a' }
] }, ] },
{ id: 'viewMenu', title: 'View', items: [ { id: 'viewMenu', title: 'View', items: [
{ id: 'movies', title: 'View Movies', items: [ { id: 'movies', title: 'View ' + app.config.itemName.plural, items: [
{ group: 'viewmovies', min: 0, max: 1, items: $.map(app.config.listViews, function(view, i) { { group: 'viewmovies', min: 0, max: 1, items: $.map(app.config.listViews, function(view, i) {
return $.extend({ return $.extend({
checked: app.user.ui.lists[app.user.ui.list].listView == view.id, checked: app.user.ui.lists[app.user.ui.list].listView == view.id,
@ -2447,7 +2447,7 @@ var pandora = new Ox.App({
{ id: 'video', title: 'Video' } { id: 'video', title: 'Video' }
] }, ] },
{}, {},
{ id: 'openmovie', title: ['Open Movie', 'Open Movies'], disabled: true, items: [ { id: 'openmovie', title: ['Open ' + app.config.itemName.singular, 'Open ' + app.config.itemName.plural], disabled: true, items: [
{ group: 'movieview', min: 0, max: 1, items: $.map(app.config.itemViews, function(view, i) { { group: 'movieview', min: 0, max: 1, items: $.map(app.config.itemViews, function(view, i) {
return $.extend({ return $.extend({
checked: app.user.ui.itemView == view.id, checked: app.user.ui.itemView == view.id,
@ -2458,17 +2458,17 @@ var pandora = new Ox.App({
{ id: 'lists', title: 'Hide Lists', keyboard: 'shift l' }, { id: 'lists', title: 'Hide Lists', keyboard: 'shift l' },
{ id: 'info', title: 'Hide Info', keyboard: 'shift i' }, { id: 'info', title: 'Hide Info', keyboard: 'shift i' },
{ id: 'groups', title: 'Hide Groups', keyboard: 'shift g' }, { id: 'groups', title: 'Hide Groups', keyboard: 'shift g' },
{ id: 'movies', title: 'Hide Movies', disabled: true, keyboard: 'shift m' } { id: 'movies', title: 'Hide ' + app.config.itemName.plural, disabled: true, keyboard: 'shift m' }
]}, ]},
{ id: 'sortMenu', title: 'Sort', items: [ { id: 'sortMenu', title: 'Sort', items: [
{ id: 'sortmovies', title: 'Sort Movies by', items: [ { id: 'sortmovies', title: 'Sort ' + app.config.itemName.plural + ' by', items: [
{ group: 'sortmovies', min: 1, max: 1, items: $.map(app.ui.sortKeys, function(key, i) { { group: 'sortmovies', min: 1, max: 1, items: $.map(app.ui.sortKeys, function(key, i) {
return $.extend({ return $.extend({
checked: app.user.ui.lists[app.user.ui.list].sort[0].key == key.id, checked: app.user.ui.lists[app.user.ui.list].sort[0].key == key.id,
}, key); }, key);
}) } }) }
] }, ] },
{ id: 'ordermovies', title: 'Order Movies', items: [ { id: 'ordermovies', title: 'Order ' + app.config.itemName.plural, items: [
{ group: 'ordermovies', min: 1, max: 1, items: [ { group: 'ordermovies', min: 1, max: 1, items: [
{ id: 'ascending', title: 'Ascending', checked: app.user.ui.lists[app.user.ui.list].sort[0].operator === '' }, { id: 'ascending', title: 'Ascending', checked: app.user.ui.lists[app.user.ui.list].sort[0].operator === '' },
{ id: 'descending', title: 'Descending', checked: app.user.ui.lists[app.user.ui.list].sort[0].operator == '-' } { id: 'descending', title: 'Descending', checked: app.user.ui.lists[app.user.ui.list].sort[0].operator == '-' }
@ -2945,6 +2945,9 @@ var pandora = new Ox.App({
} }
}); });
pandora.api.getPage(app.user.ui.sitePage, function(result) {
that.html(result.data.body).css({'overflow-y':'auto'});
});
} else if (app.user.ui.section == 'items') { } else if (app.user.ui.section == 'items') {
that = new Ox.SplitPanel({ that = new Ox.SplitPanel({
elements: [ elements: [
@ -3692,7 +3695,7 @@ var pandora = new Ox.App({
item: '' item: ''
}); });
}, },
'^(|about|archives|faq|help|home|news|preferences|software|terms|tour)$': function(url) { '^(|about|archives|faq|help|license|home|news|preferences|software|terms|tour)$': function(url) {
UI.set({ UI.set({
section: 'site', section: 'site',
sitePage: url || 'home' sitePage: url || 'home'
@ -3775,6 +3778,8 @@ var pandora = new Ox.App({
URL.parse(); URL.parse();
if (app.user.ui.section != old.user.ui.section) { if (app.user.ui.section != old.user.ui.section) {
app.$ui.appPanel.replace(1, app.$ui.mainPanel = ui.mainPanel()); app.$ui.appPanel.replace(1, app.$ui.mainPanel = ui.mainPanel());
} else if (app.user.ui.sitePage != old.user.ui.sitePage) {
app.$ui.mainPanel.replace(1, app.$ui.rightPanel = ui.rightPanel());
} else if (!app.user.ui.item || !old.user.ui.item) { } else if (!app.user.ui.item || !old.user.ui.item) {
app.$ui.mainPanel.replace(1, app.$ui.rightPanel = ui.rightPanel()); app.$ui.mainPanel.replace(1, app.$ui.rightPanel = ui.rightPanel());
} else { } else {
@ -3838,4 +3843,4 @@ var pandora = new Ox.App({
load(); load();
}); });