pandora_prelinger
This commit is contained in:
commit
70c74225d4
8 changed files with 1974 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
*.pyc
|
0
__init__.py
Normal file
0
__init__.py
Normal file
1003
config.jsonc
Normal file
1003
config.jsonc
Normal file
File diff suppressed because it is too large
Load diff
141
data.py
Normal file
141
data.py
Normal file
|
@ -0,0 +1,141 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
import json
|
||||
import os
|
||||
from os.path import join, normpath, dirname
|
||||
|
||||
import ox
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
import item.models
|
||||
import archive.models
|
||||
|
||||
base = normpath(dirname(__file__))
|
||||
|
||||
with open(join(base, 'prelinger.json')) as f:
|
||||
data = json.load(f)
|
||||
|
||||
|
||||
def get_item(archive):
|
||||
qs = item.models.Item.objects.filter(data__contains='"archive": "%s"'%archive)
|
||||
if qs.count():
|
||||
return qs[0], False
|
||||
return item.models.Item(), True
|
||||
|
||||
def update_item(d, add_only=False):
|
||||
info = {{
|
||||
'description': 'summary',
|
||||
'id': 'archive',
|
||||
'mp4': 'stream',
|
||||
}.get(k,k):d[k] for k in d}
|
||||
for k in ('type', 'flv', 'video'):
|
||||
if k in info:
|
||||
del info[k]
|
||||
if 'year' in info:
|
||||
if isinstance(info['year'], list):
|
||||
info['year'] = info['year'][0]
|
||||
if isinstance(info['year'], basestring):
|
||||
info['year'] = info['year'][:4]
|
||||
extra = []
|
||||
for key in ('director', 'publisher', 'creator', 'sponsor'):
|
||||
if key in info:
|
||||
if len(info[key]) > 200:
|
||||
extra.append(info[key])
|
||||
info[key] = [info[key].split('.')[0][:200]]
|
||||
else:
|
||||
info[key] = [info[key]]
|
||||
if extra:
|
||||
info['summary'] = info.get('summary', '') + '\n\n' + '\n\n'.join(extra)
|
||||
if 'summary' in info:
|
||||
info['summary'] = ox.sanitize_html(info['summary'].replace('\n', '<br>\n'))
|
||||
if 'title' in info:
|
||||
info['title'] = info['title'].replace('(%s)' % info.get('year', ''), '').strip()
|
||||
info['title'] = ox.normalize_title(info['title'])
|
||||
if info.get('sound') in ('b&w', 'b/w'):
|
||||
info['sound'], info['color'] = info['color'], info['sound']
|
||||
if 'sound' in info:
|
||||
info['sound'] = [{
|
||||
'sound': 'Sound',
|
||||
'sd': 'Sound',
|
||||
'yes': 'Sound',
|
||||
'no': 'Silent',
|
||||
'si': 'Silent',
|
||||
'silen': 'Silent',
|
||||
'silent': 'Silent',
|
||||
}.get(c.lower(), c) for c in info['sound'].split('/')]
|
||||
if 'color' in info:
|
||||
info['color'] = [{
|
||||
'color': 'Color',
|
||||
'c': 'Color',
|
||||
'sepia': 'Sepia',
|
||||
'tinted': 'Tinted',
|
||||
'black and white': 'B&W',
|
||||
'bw': 'B&W',
|
||||
'b&w': 'B&W',
|
||||
}.get(c.lower(), c) for c in info['color'].replace('b/w', 'b&w').split('/')]
|
||||
|
||||
i, created = get_item(info['archive'])
|
||||
if add_only and not created:
|
||||
return
|
||||
print info['archive'], info.get('title', 'Untitled')
|
||||
for k in info:
|
||||
i.data[k] = info[k]
|
||||
i.level = 0
|
||||
i.save()
|
||||
if created:
|
||||
i.save()
|
||||
i.make_poster(True)
|
||||
|
||||
def update_items(add_only=False):
|
||||
for d in data:
|
||||
update_item(d, add_only)
|
||||
|
||||
def update_item_stream(i):
|
||||
if update_stream(i):
|
||||
for s in i.streams():
|
||||
s.make_timeline()
|
||||
i.level = 0
|
||||
i.save()
|
||||
i.update_timeline()
|
||||
i.make_poster(True)
|
||||
return True
|
||||
return False
|
||||
|
||||
def update_stream(i):
|
||||
stream_url = i.data.get('stream')
|
||||
if not stream_url:
|
||||
return False
|
||||
for s in i.streams():
|
||||
if s.info['url'] != stream_url:
|
||||
s.delete()
|
||||
else:
|
||||
return False
|
||||
oshash = ox.net.oshash(stream_url)
|
||||
if oshash == 'IOError':
|
||||
print 'invalid url', stream_url
|
||||
return False
|
||||
f, created = archive.models.File.objects.get_or_create(oshash=oshash)
|
||||
f.item = i
|
||||
f.selected = True
|
||||
f.available = True
|
||||
f.info['extension'] = 'mp4'
|
||||
f.path = stream_url
|
||||
f.save()
|
||||
s, created = archive.models.Stream.objects.get_or_create(source=None, file=f)
|
||||
if created:
|
||||
s.info['url'] = stream_url
|
||||
s.available = True
|
||||
s.resolution = 480
|
||||
s.format = 'mp4'
|
||||
s.save()
|
||||
return True
|
||||
return False
|
||||
|
||||
def update_streams():
|
||||
import itemlist.models
|
||||
l = itemlist.models.List.get('j:with Video')
|
||||
for i in item.models.Item.objects.all():
|
||||
print i
|
||||
if update_item_stream(i):
|
||||
l.add(i)
|
42
get_data.py
Normal file
42
get_data.py
Normal file
|
@ -0,0 +1,42 @@
|
|||
#pip install internetarchive
|
||||
import json
|
||||
import internetarchive
|
||||
|
||||
|
||||
data = {}
|
||||
for e in internetarchive.search.Search('collection:prelinger'):
|
||||
item = internetarchive.get_item(e['identifier'])
|
||||
for key in ('h.264', 'MPEG4', '512Kb MPEG4', 'HiRes MPEG4'):
|
||||
files = [f for f in item.files if f['format'] == key]
|
||||
if files:
|
||||
break
|
||||
if files:
|
||||
print item.metadata['title']
|
||||
print 'https://archive.org/details/%s' % item.identifier
|
||||
url = 'https://archive.org/download/%s/%s' % (item.identifier, files[0]['name'])
|
||||
print url
|
||||
data[item.identifier] = {
|
||||
'id': item.identifier,
|
||||
'mp4': url,
|
||||
'mp4_size': files[0]['size'],
|
||||
}
|
||||
for key in (
|
||||
'title', 'description', 'year',
|
||||
'publisher', 'addeddate', 'sound',
|
||||
'creator', 'color', 'credits', 'publisher',
|
||||
'sponsor', 'uploader', 'licenseurl',
|
||||
#needed?
|
||||
'date',
|
||||
):
|
||||
if key in item.metadata and item.metadata[key]:
|
||||
data[item.identifier][key] = item.metadata[key]
|
||||
if data[item.identifier][key][0] == '[' and data[item.identifier][key][-1] == ']':
|
||||
data[item.identifier][key] = data[item.identifier][key][1:-1]
|
||||
else:
|
||||
formats = sorted({f['format']:1 for f in item.files}.keys())
|
||||
if formats:
|
||||
print item.identifier, item.files
|
||||
print formats
|
||||
|
||||
with open('prelinger.json', 'w') as f:
|
||||
json.dump(data.values(), f, indent=2)
|
85
install.py
Executable file
85
install.py
Executable file
|
@ -0,0 +1,85 @@
|
|||
#!/usr/bin/python2
|
||||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
|
||||
import os
|
||||
from os.path import join, abspath, basename, dirname
|
||||
import re
|
||||
|
||||
name = 'prelinger'
|
||||
base = abspath(dirname(__file__))
|
||||
os.chdir(base)
|
||||
|
||||
for root, folders, files in os.walk(join(base, 'static')):
|
||||
for f in files:
|
||||
src = join(root, f)
|
||||
target = src.replace(base, '/srv/pandora')
|
||||
rel_src = os.path.relpath(src, dirname(target))
|
||||
if os.path.exists(target):
|
||||
os.unlink(target)
|
||||
os.symlink(rel_src, target)
|
||||
if f in ('logo.%s.png'%name, 'icon.%s.png'%name):
|
||||
t = target.replace('%s.'%name, '')
|
||||
if os.path.exists(t):
|
||||
os.unlink(t)
|
||||
os.symlink(f, os.path.join(dirname(target), t))
|
||||
|
||||
'''
|
||||
overwrite = (
|
||||
('home', 'indiancinema'),
|
||||
)
|
||||
|
||||
os.chdir('/srv/pandora/static/js')
|
||||
for filename, sitename in overwrite:
|
||||
src = '%s.%s.js' % (filename, sitename)
|
||||
target = '%s.%s.js' % (filename, name)
|
||||
if os.path.exists(target):
|
||||
os.unlink(target)
|
||||
os.symlink(src, target)
|
||||
'''
|
||||
|
||||
os.chdir(base)
|
||||
src = join(base, 'config.jsonc')
|
||||
target = '/srv/pandora/pandora/config.%s.jsonc' % name
|
||||
rel_src = os.path.relpath(src, dirname(target))
|
||||
if os.path.exists(target):
|
||||
os.unlink(target)
|
||||
os.symlink(rel_src, target)
|
||||
t = '/srv/pandora/pandora/config.jsonc'
|
||||
if os.path.exists(t):
|
||||
os.unlink(t)
|
||||
os.symlink(basename(target), t)
|
||||
|
||||
for root, folders, files in os.walk(join(base, 'scripts')):
|
||||
for f in files:
|
||||
if f.endswith('.pyc'):
|
||||
continue
|
||||
src = join(root, f)
|
||||
target = src.replace(base, '/srv/pandora')
|
||||
rel_src = os.path.relpath(src, dirname(target))
|
||||
if os.path.exists(target):
|
||||
os.unlink(target)
|
||||
os.symlink(rel_src, target)
|
||||
if f == 'poster.%s.py' % name:
|
||||
t = os.path.join(dirname(target), 'poster.py')
|
||||
if os.path.exists(t):
|
||||
os.unlink(t)
|
||||
os.symlink(f, os.path.join(dirname(target), t))
|
||||
|
||||
local_settings_py = '/srv/pandora/pandora/local_settings.py'
|
||||
with open(local_settings_py) as fd:
|
||||
local_settings_changed = False
|
||||
local_settings = fd.read()
|
||||
if not 'LOCAL_APPS' in local_settings:
|
||||
local_settings += '\nLOCAL_APPS = ["%s"]\n' % name
|
||||
local_settings_changed = True
|
||||
else:
|
||||
apps = re.compile('(LOCAL_APPS.*?)\]', re.DOTALL).findall(local_settings)[0]
|
||||
if not name in apps:
|
||||
new_apps = apps.strip() + ',\n"%s"\n' % name
|
||||
local_settings = local_settings.replace(apps, new_apps)
|
||||
local_settings_changed = True
|
||||
if local_settings_changed:
|
||||
with open(local_settings_py, 'w') as fd:
|
||||
fd.write(local_settings)
|
||||
|
44
notes.py
Normal file
44
notes.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
from __future__ import division
|
||||
import re
|
||||
import ox
|
||||
import item.models
|
||||
import annotation.models
|
||||
import user.models
|
||||
|
||||
def parse_notes(i, fps=29.97):
|
||||
u = user.models.User.objects.all()[0]
|
||||
text = i.data.get('summary', '')
|
||||
parts = text.split('<br>\n<br>\n')
|
||||
annotations = []
|
||||
offset = None
|
||||
for part in parts:
|
||||
m = re.compile('^((\d{2}):(\d{2}):(\d{2}):(\d{2})) +(.*)').findall(part)
|
||||
if m:
|
||||
tc, h, m, s, f, txt = m[0]
|
||||
seconds = int(h) * 60 * 60 + int(m) * 60 + int(s) + int(f)/fps
|
||||
if offset == None:
|
||||
offset = seconds - 60
|
||||
timecode = ox.format_timecode(seconds - offset)
|
||||
text = text.replace(tc, '<a href="/%s/%s">%s</a>' %(i.public_id, timecode, tc))
|
||||
if annotations:
|
||||
annotations[-1]['out'] = seconds - offset - 1/fps
|
||||
annotations.append({
|
||||
'in': seconds - offset,
|
||||
'out': -1,
|
||||
'value': txt
|
||||
})
|
||||
if annotations:
|
||||
annotations[-1]['out'] = i.sort.duration
|
||||
if text != i.data.get('summary', ''):
|
||||
i.data['summary'] = text
|
||||
i.save()
|
||||
for d in annotations:
|
||||
a = annotation.models.Annotation()
|
||||
a.item = i
|
||||
a.layer = 'publicnotes'
|
||||
a.start = d['in']
|
||||
a.end = d['out']
|
||||
a.value = d['value']
|
||||
a.user = u
|
||||
a.save()
|
||||
return text, annotations
|
658
static/js/infoView.prelinger.js
Normal file
658
static/js/infoView.prelinger.js
Normal file
|
@ -0,0 +1,658 @@
|
|||
'use strict';
|
||||
|
||||
pandora.ui.infoView = function(data) {
|
||||
|
||||
var ui = pandora.user.ui,
|
||||
descriptions = [],
|
||||
canEdit = pandora.site.capabilities.canEditMetadata[pandora.user.level] || data.editable,
|
||||
canRemove = pandora.site.capabilities.canRemoveItems[pandora.user.level],
|
||||
css = {
|
||||
marginTop: '4px',
|
||||
textAlign: 'justify'
|
||||
},
|
||||
html,
|
||||
iconRatio = ui.icons == 'posters' ? data.posterRatio : 1,
|
||||
iconSize = ui.infoIconSize,
|
||||
iconWidth = iconRatio > 1 ? iconSize : Math.round(iconSize * iconRatio),
|
||||
iconHeight = iconRatio < 1 ? iconSize : Math.round(iconSize / iconRatio),
|
||||
iconLeft = iconSize == 256 ? Math.floor((iconSize - iconWidth) / 2) : 0,
|
||||
borderRadius = ui.icons == 'posters' ? 0 : iconSize / 8,
|
||||
margin = 16,
|
||||
nameKeys = ['director'],
|
||||
listKeys = nameKeys.concat(['country', 'groups']),
|
||||
statisticsWidth = 128,
|
||||
|
||||
$bar = Ox.Bar({size: 16})
|
||||
.bindEvent({
|
||||
doubleclick: function(e) {
|
||||
if ($(e.target).is('.OxBar')) {
|
||||
$info.animate({scrollTop: 0}, 250);
|
||||
}
|
||||
}
|
||||
}),
|
||||
|
||||
$options = Ox.MenuButton({
|
||||
items: [
|
||||
{
|
||||
id: 'delete',
|
||||
title: Ox._('Delete {0}...', [pandora.site.itemName.singular]),
|
||||
disabled: !canRemove
|
||||
}
|
||||
],
|
||||
style: 'square',
|
||||
title: 'set',
|
||||
tooltip: Ox._('Options'),
|
||||
type: 'image',
|
||||
})
|
||||
.css({
|
||||
float: 'left',
|
||||
borderColor: 'rgba(0, 0, 0, 0)',
|
||||
background: 'rgba(0, 0, 0, 0)'
|
||||
})
|
||||
.bindEvent({
|
||||
click: function(data_) {
|
||||
if (data_.id == 'delete') {
|
||||
pandora.$ui.deleteItemDialog = pandora.ui.deleteItemDialog(data).open();
|
||||
}
|
||||
}
|
||||
})
|
||||
.appendTo($bar),
|
||||
|
||||
$edit = Ox.MenuButton({
|
||||
items: [
|
||||
{
|
||||
id: 'insert',
|
||||
title: Ox._('Insert HTML...'),
|
||||
disabled: true
|
||||
}
|
||||
],
|
||||
style: 'square',
|
||||
title: 'edit',
|
||||
tooltip: Ox._('Edit'),
|
||||
type: 'image',
|
||||
})
|
||||
.css({
|
||||
float: 'right',
|
||||
borderColor: 'rgba(0, 0, 0, 0)',
|
||||
background: 'rgba(0, 0, 0, 0)'
|
||||
})
|
||||
.bindEvent({
|
||||
click: function(data) {
|
||||
// ...
|
||||
}
|
||||
})
|
||||
.appendTo($bar),
|
||||
|
||||
$info = Ox.Element().css({overflowY: 'auto'}),
|
||||
|
||||
that = Ox.SplitPanel({
|
||||
elements: [
|
||||
{element: $bar, size: 16},
|
||||
{element: $info}
|
||||
],
|
||||
orientation: 'vertical'
|
||||
}),
|
||||
|
||||
$icon = Ox.Element({
|
||||
element: '<img>',
|
||||
})
|
||||
.attr({
|
||||
src: '/' + data.id + '/' + (
|
||||
ui.icons == 'posters' ? 'poster' : 'icon'
|
||||
) + '512.jpg?' + data.modified
|
||||
})
|
||||
.css({
|
||||
position: 'absolute',
|
||||
left: margin + iconLeft + 'px',
|
||||
top: margin + 'px',
|
||||
width: iconWidth + 'px',
|
||||
height: iconHeight + 'px',
|
||||
borderRadius: borderRadius + 'px',
|
||||
cursor: 'pointer'
|
||||
})
|
||||
.bindEvent({
|
||||
singleclick: toggleIconSize
|
||||
})
|
||||
.appendTo($info),
|
||||
|
||||
$reflection = $('<div>')
|
||||
.addClass('OxReflection')
|
||||
.css({
|
||||
position: 'absolute',
|
||||
left: margin + 'px',
|
||||
top: margin + iconHeight + 'px',
|
||||
width: iconSize + 'px',
|
||||
height: iconSize / 2 + 'px',
|
||||
overflow: 'hidden'
|
||||
})
|
||||
.appendTo($info),
|
||||
|
||||
$reflectionIcon = $('<img>')
|
||||
.attr({
|
||||
src: '/' + data.id + '/' + (
|
||||
ui.icons == 'posters' ? 'poster' : 'icon'
|
||||
) + '512.jpg?' + data.modified
|
||||
})
|
||||
.css({
|
||||
position: 'absolute',
|
||||
left: iconLeft + 'px',
|
||||
width: iconWidth + 'px',
|
||||
height: iconHeight + 'px',
|
||||
borderRadius: borderRadius + 'px'
|
||||
})
|
||||
.appendTo($reflection),
|
||||
|
||||
$reflectionGradient = $('<div>')
|
||||
.css({
|
||||
position: 'absolute',
|
||||
width: iconSize + 'px',
|
||||
height: iconSize / 2 + 'px'
|
||||
})
|
||||
.appendTo($reflection),
|
||||
|
||||
$text = Ox.Element()
|
||||
.addClass('OxTextPage')
|
||||
.css({
|
||||
position: 'absolute',
|
||||
left: margin + (iconSize == 256 ? 256 : iconWidth) + margin + 'px',
|
||||
top: margin + 'px',
|
||||
right: margin + statisticsWidth + margin + 'px',
|
||||
})
|
||||
.appendTo($info),
|
||||
|
||||
$statistics = $('<div>')
|
||||
.css({
|
||||
position: 'absolute',
|
||||
width: statisticsWidth + 'px',
|
||||
top: margin + 'px',
|
||||
right: margin + 'px'
|
||||
})
|
||||
.appendTo($info),
|
||||
|
||||
$capabilities;
|
||||
|
||||
[$options, $edit].forEach(function($element) {
|
||||
$element.find('input').css({
|
||||
borderWidth: 0,
|
||||
borderRadius: 0,
|
||||
padding: '3px'
|
||||
});
|
||||
});
|
||||
|
||||
if (!canEdit) {
|
||||
pandora.createLinks($info);
|
||||
}
|
||||
|
||||
// Title -------------------------------------------------------------------
|
||||
|
||||
$('<div>')
|
||||
.css({
|
||||
marginTop: '-2px',
|
||||
})
|
||||
.append(
|
||||
Ox.EditableContent({
|
||||
editable: canEdit,
|
||||
tooltip: canEdit ? pandora.getEditTooltip() : '',
|
||||
value: data.title || ''
|
||||
})
|
||||
.css({
|
||||
marginBottom: '-3px',
|
||||
fontWeight: 'bold',
|
||||
fontSize: '13px'
|
||||
})
|
||||
.bindEvent({
|
||||
submit: function(event) {
|
||||
editMetadata('title', event.value);
|
||||
}
|
||||
})
|
||||
)
|
||||
.appendTo($text);
|
||||
|
||||
// Director, Year and Country ----------------------------------------------
|
||||
|
||||
renderGroup(['director', 'year', 'country']);
|
||||
renderGroup(['creator', 'sponsor', 'publisher']);
|
||||
|
||||
renderGroup(['color', 'sound']);
|
||||
|
||||
renderGroup(['archive', 'licenseurl']);
|
||||
|
||||
// Summary -----------------------------------------------------------------
|
||||
|
||||
if (canEdit || data.summary) {
|
||||
$('<div>')
|
||||
.append(
|
||||
Ox.EditableContent({
|
||||
clickLink: pandora.clickLink,
|
||||
editable: canEdit,
|
||||
format: function(value) {
|
||||
return value.replace(
|
||||
/<img src=/g,
|
||||
'<img style="float: left; max-width: 256px; max-height: 256px; margin: 0 16px 16px 0" src='
|
||||
);
|
||||
},
|
||||
maxHeight: Infinity,
|
||||
placeholder: formatLight(Ox._('No Summary')),
|
||||
tooltip: canEdit ? pandora.getEditTooltip() : '',
|
||||
type: 'textarea',
|
||||
value: data.summary || ''
|
||||
})
|
||||
.css(css)
|
||||
.css({
|
||||
marginTop: '12px',
|
||||
overflow: 'hidden'
|
||||
})
|
||||
.bindEvent({
|
||||
submit: function(event) {
|
||||
editMetadata('summary', event.value);
|
||||
}
|
||||
})
|
||||
)
|
||||
.appendTo($text);
|
||||
}
|
||||
|
||||
// Duration, Aspect Ratio --------------------------------------------------
|
||||
|
||||
['duration', 'aspectratio'].forEach(function(key) {
|
||||
var itemKey = Ox.getObjectById(pandora.site.itemKeys, key),
|
||||
value = data[key] || 0;
|
||||
$('<div>')
|
||||
.css({marginBottom: '4px'})
|
||||
.append(formatKey(itemKey.title, 'statistics'))
|
||||
.append(
|
||||
Ox.Theme.formatColor(null, 'gradient')
|
||||
.css({textAlign: 'right'})
|
||||
.html(
|
||||
Ox['format' + Ox.toTitleCase(itemKey.format.type)]
|
||||
.apply(null, [value].concat(itemKey.format.args))
|
||||
)
|
||||
)
|
||||
.appendTo($statistics);
|
||||
});
|
||||
|
||||
// Hue, Saturation, Lightness, Volume --------------------------------------
|
||||
|
||||
['hue', 'saturation', 'lightness', 'volume'].forEach(function(key) {
|
||||
$('<div>')
|
||||
.css({marginBottom: '4px'})
|
||||
.append(formatKey(key, 'statistics'))
|
||||
.append(
|
||||
Ox.Theme.formatColor(
|
||||
data[key] || 0, key == 'volume' ? 'lightness' : key
|
||||
).css({textAlign: 'right'})
|
||||
)
|
||||
.appendTo($statistics);
|
||||
});
|
||||
|
||||
// Cuts per Minute ---------------------------------------------------------
|
||||
|
||||
$('<div>')
|
||||
.css({marginBottom: '4px'})
|
||||
.append(formatKey('cuts per minute', 'statistics'))
|
||||
.append(
|
||||
Ox.Theme.formatColor(null, 'gradient')
|
||||
.css({textAlign: 'right'})
|
||||
.html(Ox.formatNumber(data['cutsperminute'] || 0, 3))
|
||||
)
|
||||
.appendTo($statistics);
|
||||
|
||||
// Rights Level ------------------------------------------------------------
|
||||
|
||||
var $rightsLevel = $('<div>');
|
||||
$('<div>')
|
||||
.css({marginBottom: '4px'})
|
||||
.append(formatKey('Rights Level', 'statistics'))
|
||||
.append($rightsLevel)
|
||||
.appendTo($statistics);
|
||||
renderRightsLevel();
|
||||
|
||||
// Notes --------------------------------------------------------------------
|
||||
|
||||
if (canEdit) {
|
||||
$('<div>')
|
||||
.css({marginBottom: '4px'})
|
||||
.append(
|
||||
formatKey('Notes', 'statistics').options({
|
||||
tooltip: Ox._('Only {0} can see and edit these comments', [
|
||||
Object.keys(pandora.site.capabilities.canEditMetadata).map(function(level, i) {
|
||||
return (
|
||||
i == 0 ? ''
|
||||
: i < Ox.len(pandora.site.capabilities.canEditMetadata) - 1 ? ', '
|
||||
: ' ' + Ox._('and') + ' '
|
||||
) + Ox.toTitleCase(level)
|
||||
}).join('')])
|
||||
})
|
||||
)
|
||||
.append(
|
||||
Ox.EditableContent({
|
||||
height: 128,
|
||||
placeholder: formatLight(Ox._('No notes')),
|
||||
tooltip: pandora.getEditTooltip(),
|
||||
type: 'textarea',
|
||||
value: data.notes || '',
|
||||
width: 128
|
||||
})
|
||||
.bindEvent({
|
||||
submit: function(event) {
|
||||
editMetadata('notes', event.value);
|
||||
}
|
||||
})
|
||||
)
|
||||
.appendTo($statistics);
|
||||
}
|
||||
|
||||
$('<div>').css({height: '16px'}).appendTo($statistics);
|
||||
|
||||
function editMetadata(key, value) {
|
||||
if (value != data[key]) {
|
||||
var edit = {id: data.id};
|
||||
if (key == 'title') {
|
||||
edit[key] = value;
|
||||
} else if (listKeys.indexOf(key) >= 0) {
|
||||
edit[key] = value ? value.split(', ') : [];
|
||||
} else {
|
||||
edit[key] = value ? value : null;
|
||||
}
|
||||
pandora.api.edit(edit, function(result) {
|
||||
var src;
|
||||
data[key] = result.data[key];
|
||||
descriptions[key] && descriptions[key].options({
|
||||
value: result.data[key + 'description']
|
||||
});
|
||||
Ox.Request.clearCache(); // fixme: too much? can change filter/list etc
|
||||
if (result.data.id != data.id) {
|
||||
pandora.UI.set({item: result.data.id});
|
||||
pandora.$ui.browser.value(data.id, 'id', result.data.id);
|
||||
}
|
||||
pandora.updateItemContext();
|
||||
pandora.$ui.browser.value(result.data.id, key, result.data[key]);
|
||||
pandora.$ui.itemTitle
|
||||
.options({
|
||||
title: '<b>' + result.data.title
|
||||
+ (Ox.len(result.data.director)
|
||||
? ' (' + result.data.director.join(', ') + ')'
|
||||
: '')
|
||||
+ (result.data.year ? ' ' + result.data.year : '') + '</b>'
|
||||
});
|
||||
if (
|
||||
Ox.contains(['title', 'director', 'year'], key)
|
||||
&& ui.icons == 'posters'
|
||||
) {
|
||||
src = '/' + data.id + '/poster512.jpg?' + Ox.uid()
|
||||
$icon.attr({src: src});
|
||||
$reflectionIcon.attr({src: src});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function formatKey(key, mode) {
|
||||
var item = Ox.getObjectById(pandora.site.itemKeys, key);
|
||||
key = Ox._(item ? item.title : key);
|
||||
mode = mode || 'text';
|
||||
return mode == 'text'
|
||||
? '<span style="font-weight: bold">' + Ox.toTitleCase(key) + ':</span> '
|
||||
: mode == 'description'
|
||||
? Ox.toTitleCase(key)
|
||||
: Ox.Element()
|
||||
.css({marginBottom: '4px', fontWeight: 'bold'})
|
||||
.html(Ox.toTitleCase(key)
|
||||
.replace(' Per ', ' per '));
|
||||
}
|
||||
|
||||
function formatLight(str) {
|
||||
return '<span class="OxLight">' + str + '</span>';
|
||||
}
|
||||
|
||||
function formatLink(value, key) {
|
||||
return (Ox.isArray(value) ? value : [value]).map(function(value) {
|
||||
return key
|
||||
? '<a href="/' + key + '=' + value + '">' + value + '</a>'
|
||||
: value;
|
||||
}).join(', ');
|
||||
}
|
||||
|
||||
function formatValue(key, value) {
|
||||
var ret;
|
||||
if (key == 'year') {
|
||||
ret = formatLink(value, 'year');
|
||||
} else if (nameKeys.indexOf(key) > -1) {
|
||||
ret = formatLink(value.split(', '), 'name');
|
||||
} else if (listKeys.indexOf(key) > -1) {
|
||||
ret = formatLink(value.split(', '), key);
|
||||
} else if (key == 'archive') {
|
||||
ret = '<a href="https://archive.org/details/' + value + '">' + value + '</a>';
|
||||
} else if (key == 'licenseurl') {
|
||||
ret = '<a href="' + value + '">' + value + '</a>';
|
||||
} else {
|
||||
ret = value;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
function getRightsLevelElement(rightsLevel) {
|
||||
return Ox.Theme.formatColorLevel(
|
||||
rightsLevel,
|
||||
pandora.site.rightsLevels.map(function(rightsLevel) {
|
||||
return rightsLevel.name;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
function getValue(key, value) {
|
||||
return !value ? ''
|
||||
: Ox.contains(listKeys, key) ? value.join(', ')
|
||||
: value;
|
||||
}
|
||||
|
||||
function renderCapabilities(rightsLevel) {
|
||||
var capabilities = [].concat(
|
||||
canEdit ? [{name: 'canSeeItem', symbol: 'Find'}] : [],
|
||||
[
|
||||
{name: 'canPlayClips', symbol: 'PlayInToOut'},
|
||||
{name: 'canPlayVideo', symbol: 'Play'},
|
||||
{name: 'canDownloadVideo', symbol: 'Download'}
|
||||
]
|
||||
),
|
||||
userLevels = canEdit ? pandora.site.userLevels : [pandora.user.level];
|
||||
$capabilities.empty();
|
||||
userLevels.forEach(function(userLevel, i) {
|
||||
var $element,
|
||||
$line = $('<div>')
|
||||
.css({
|
||||
height: '16px',
|
||||
marginBottom: '4px'
|
||||
})
|
||||
.appendTo($capabilities);
|
||||
if (canEdit) {
|
||||
$element = Ox.Theme.formatColorLevel(i, userLevels.map(function(userLevel) {
|
||||
return Ox.toTitleCase(userLevel);
|
||||
}), [0, 240]);
|
||||
Ox.Label({
|
||||
textAlign: 'center',
|
||||
title: Ox.toTitleCase(userLevel),
|
||||
width: 60
|
||||
})
|
||||
.addClass('OxColor OxColorGradient')
|
||||
.css({
|
||||
float: 'left',
|
||||
height: '12px',
|
||||
paddingTop: '2px',
|
||||
background: $element.css('background'),
|
||||
fontSize: '8px',
|
||||
color: $element.css('color')
|
||||
})
|
||||
.data({OxColor: $element.data('OxColor')})
|
||||
.appendTo($line);
|
||||
}
|
||||
capabilities.forEach(function(capability) {
|
||||
var hasCapability = pandora.site.capabilities[capability.name][userLevel] >= rightsLevel,
|
||||
$element = Ox.Theme.formatColorLevel(hasCapability, ['', '']);
|
||||
Ox.Button({
|
||||
tooltip: (canEdit ? Ox.toTitleCase(userLevel) : 'You') + ' '
|
||||
+ (hasCapability ? 'can' : 'can\'t') + ' '
|
||||
+ Ox.toSlashes(capability.name)
|
||||
.split('/').slice(1).join(' ')
|
||||
.toLowerCase(),
|
||||
title: capability.symbol,
|
||||
type: 'image'
|
||||
})
|
||||
.addClass('OxColor OxColorGradient')
|
||||
.css({background: $element.css('background')})
|
||||
.css('margin' + (canEdit ? 'Left' : 'Right'), '4px')
|
||||
.data({OxColor: $element.data('OxColor')})
|
||||
.appendTo($line);
|
||||
});
|
||||
if (!canEdit) {
|
||||
Ox.Button({
|
||||
title: Ox._('Help'),
|
||||
tooltip: Ox._('About Rights'),
|
||||
type: 'image'
|
||||
})
|
||||
.css({marginLeft: '52px'})
|
||||
.bindEvent({
|
||||
click: function() {
|
||||
pandora.UI.set({page: 'rights'});
|
||||
}
|
||||
})
|
||||
.appendTo($line);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function renderGroup(keys) {
|
||||
var $element;
|
||||
if (canEdit || keys.filter(function(key) {
|
||||
return data[key];
|
||||
}).length) {
|
||||
$element = $('<div>').addClass('OxSelectable').css(css);
|
||||
keys.forEach(function(key, i) {
|
||||
if (canEdit || data[key]) {
|
||||
if ($element.children().length) {
|
||||
$('<span>').html('; ').appendTo($element);
|
||||
}
|
||||
$('<span>').html(formatKey(key)).appendTo($element);
|
||||
Ox.EditableContent({
|
||||
clickLink: pandora.clickLink,
|
||||
format: function(value) {
|
||||
return formatValue(key, value);
|
||||
},
|
||||
placeholder: formatLight(Ox._('unknown')),
|
||||
tooltip: canEdit ? pandora.getEditTooltip() : '',
|
||||
value: getValue(key, data[key])
|
||||
})
|
||||
.bindEvent({
|
||||
submit: function(data) {
|
||||
editMetadata(key, data.value);
|
||||
}
|
||||
})
|
||||
.appendTo($element);
|
||||
}
|
||||
});
|
||||
$element.appendTo($text);
|
||||
}
|
||||
}
|
||||
|
||||
function renderRightsLevel() {
|
||||
var $rightsLevelElement = getRightsLevelElement(data.rightslevel),
|
||||
$rightsLevelSelect;
|
||||
$rightsLevel.empty();
|
||||
if (canEdit) {
|
||||
$rightsLevelSelect = Ox.Select({
|
||||
items: pandora.site.rightsLevels.map(function(rightsLevel, i) {
|
||||
return {id: i, title: rightsLevel.name};
|
||||
}),
|
||||
width: 128,
|
||||
value: data.rightslevel
|
||||
})
|
||||
.addClass('OxColor OxColorGradient')
|
||||
.css({
|
||||
marginBottom: '4px',
|
||||
background: $rightsLevelElement.css('background')
|
||||
})
|
||||
.data({OxColor: $rightsLevelElement.data('OxColor')})
|
||||
.bindEvent({
|
||||
change: function(event) {
|
||||
var rightsLevel = event.value;
|
||||
$rightsLevelElement = getRightsLevelElement(rightsLevel);
|
||||
$rightsLevelSelect
|
||||
.css({background: $rightsLevelElement.css('background')})
|
||||
.data({OxColor: $rightsLevelElement.data('OxColor')})
|
||||
renderCapabilities(rightsLevel);
|
||||
pandora.api.edit({id: data.id, rightslevel: rightsLevel}, function(result) {
|
||||
// ...
|
||||
});
|
||||
}
|
||||
})
|
||||
.appendTo($rightsLevel);
|
||||
} else {
|
||||
$rightsLevelElement
|
||||
.css({
|
||||
marginBottom: '4px'
|
||||
})
|
||||
.appendTo($rightsLevel);
|
||||
}
|
||||
$capabilities = $('<div>').appendTo($rightsLevel);
|
||||
renderCapabilities(data.rightslevel);
|
||||
}
|
||||
|
||||
function toggleIconSize() {
|
||||
iconSize = iconSize == 256 ? 512 : 256;
|
||||
iconWidth = iconRatio > 1 ? iconSize : Math.round(iconSize * iconRatio);
|
||||
iconHeight = iconRatio < 1 ? iconSize : Math.round(iconSize / iconRatio);
|
||||
iconLeft = iconSize == 256 ? Math.floor((iconSize - iconWidth) / 2) : 0,
|
||||
borderRadius = ui.icons == 'posters' ? 0 : iconSize / 8;
|
||||
$icon.animate({
|
||||
left: margin + iconLeft + 'px',
|
||||
width: iconWidth + 'px',
|
||||
height: iconHeight + 'px',
|
||||
borderRadius: borderRadius + 'px'
|
||||
}, 250);
|
||||
$reflection.animate({
|
||||
top: margin + iconHeight + 'px',
|
||||
width: iconSize + 'px',
|
||||
height: iconSize / 2 + 'px'
|
||||
}, 250);
|
||||
$reflectionIcon.animate({
|
||||
left: iconLeft + 'px',
|
||||
width: iconWidth + 'px',
|
||||
height: iconHeight + 'px',
|
||||
borderRadius: borderRadius + 'px'
|
||||
}, 250);
|
||||
$reflectionGradient.animate({
|
||||
width: iconSize + 'px',
|
||||
height: iconSize / 2 + 'px'
|
||||
}, 250);
|
||||
$text.animate({
|
||||
left: margin + (iconSize == 256 ? 256 : iconWidth) + margin + 'px',
|
||||
}, 250);
|
||||
pandora.UI.set({infoIconSize: iconSize});
|
||||
}
|
||||
|
||||
that.reload = function() {
|
||||
var src = src = '/' + data.id + '/' + (
|
||||
ui.icons == 'posters' ? 'poster' : 'icon'
|
||||
) + '512.jpg?' + Ox.uid();
|
||||
$icon.attr({src: src});
|
||||
$reflectionIcon.attr({src: src});
|
||||
iconSize = iconSize == 256 ? 512 : 256;
|
||||
iconRatio = ui.icons == 'posters'
|
||||
? (ui.showSitePosters ? pandora.site.posters.ratio : data.posterRatio) : 1;
|
||||
toggleIconSize();
|
||||
};
|
||||
|
||||
that.bindEvent({
|
||||
mousedown: function() {
|
||||
setTimeout(function() {
|
||||
!Ox.Focus.focusedElementIsInput() && that.gainFocus();
|
||||
});
|
||||
},
|
||||
pandora_icons: that.reload,
|
||||
pandora_showsiteposters: function() {
|
||||
ui.icons == 'posters' && that.reload();
|
||||
}
|
||||
});
|
||||
|
||||
return that;
|
||||
|
||||
};
|
Loading…
Reference in a new issue