remove config video.download; use canDownloadVideo capability instead.

This commit is contained in:
j 2013-07-06 11:15:10 +00:00
parent 662c7ec12a
commit ce03870fe6
6 changed files with 30 additions and 32 deletions

View file

@ -836,7 +836,6 @@
// fixme: this should include colors // fixme: this should include colors
"userLevels": ["guest", "member", "friend", "staff", "admin"], "userLevels": ["guest", "member", "friend", "staff", "admin"],
"video": { "video": {
"download": false,
"formats": ["webm", "mp4"], "formats": ["webm", "mp4"],
"previewRatio": 1.7777777778, "previewRatio": 1.7777777778,
"resolutions": [96] "resolutions": [96]

View file

@ -874,7 +874,6 @@
// fixme: this should include colors // fixme: this should include colors
"userLevels": ["guest", "member", "student", "staff", "admin"], "userLevels": ["guest", "member", "student", "staff", "admin"],
"video": { "video": {
"download": false,
"formats": ["webm", "mp4"], "formats": ["webm", "mp4"],
"previewRatio": 1.375, "previewRatio": 1.375,
"resolutions": [240, 480] "resolutions": [240, 480]

View file

@ -753,7 +753,6 @@
}, },
"userLevels": ["guest", "member", "staff", "admin"], "userLevels": ["guest", "member", "staff", "admin"],
"video": { "video": {
"download": true,
"formats": ["webm", "mp4"], "formats": ["webm", "mp4"],
"previewRatio": 1.3333333333, "previewRatio": 1.3333333333,
//supported resolutions are //supported resolutions are

View file

@ -1133,8 +1133,7 @@ class Item(models.Model):
self.select_frame() self.select_frame()
self.make_poster(True) self.make_poster(True)
self.make_icon() self.make_icon()
if settings.CONFIG['video']['download']: self.make_torrent()
self.make_torrent()
self.rendered = streams.count() > 0 self.rendered = streams.count() > 0
self.save() self.save()
if async: if async:

View file

@ -29,6 +29,7 @@ import tasks
from archive.models import File, Stream from archive.models import File, Stream
from archive import extract from archive import extract
from clip.models import Clip from clip.models import Clip
from user.models import has_capability
from ox.django.api import actions from ox.django.api import actions
@ -475,18 +476,9 @@ def get(request):
if not data['keys'] or 'groups' in data['keys'] \ if not data['keys'] or 'groups' in data['keys'] \
and request.user.get_profile().capability('canEditMetadata'): and request.user.get_profile().capability('canEditMetadata'):
info['groups'] = [g.name for g in item.groups.all()] info['groups'] = [g.name for g in item.groups.all()]
def check_capability(capability):
if request.user.is_anonymous():
level = 'guest'
else:
level = request.user.get_profile().get_level()
if request.user == item.user:
return True
return level in settings.CONFIG['capabilities'][capability] \
and settings.CONFIG['capabilities'][capability][level]
for k in settings.CONFIG['itemKeys']: for k in settings.CONFIG['itemKeys']:
if 'capability' in k \ if 'capability' in k \
and not check_capability(k['capability']) \ and not (request.user == item.user or can_capability(user, k['capability'])) \
and k['id'] in info \ and k['id'] in info \
and k['id'] not in ('parts', 'durations', 'duration'): and k['id'] not in ('parts', 'durations', 'duration'):
del info[k['id']] del info[k['id']]
@ -1018,26 +1010,28 @@ def atom_xml(request):
format = ET.SubElement(entry, "format") format = ET.SubElement(entry, "format")
format.attrib['xmlns'] = 'http://transmission.cc/FileFormat' format.attrib['xmlns'] = 'http://transmission.cc/FileFormat'
stream = item.streams().filter(source=None).order_by('-id')[0] streams = item.streams().filter(source=None).order_by('-id')
for key in ('size', 'duration', 'video_codec', if streams.exists():
'framerate', 'width', 'height', stream = streams[0]
'audio_codec', 'samplerate', 'channels'): for key in ('size', 'duration', 'video_codec',
value = stream.info.get(key) 'framerate', 'width', 'height',
if not value and stream.info.get('video'): 'audio_codec', 'samplerate', 'channels'):
value = stream.info['video'][0].get({ value = stream.info.get(key)
'video_codec': 'codec' if not value and stream.info.get('video'):
}.get(key, key)) value = stream.info['video'][0].get({
if not value and stream.info.get('audio'): 'video_codec': 'codec'
value = stream.info['audio'][0].get({ }.get(key, key))
'audio_codec': 'codec' if not value and stream.info.get('audio'):
}.get(key, key)) value = stream.info['audio'][0].get({
if value and value != -1: 'audio_codec': 'codec'
el = ET.SubElement(format, key) }.get(key, key))
el.text = unicode(value) if value and value != -1:
el = ET.SubElement(format, key)
el.text = unicode(value)
el = ET.SubElement(format, 'pixel_aspect_ratio') el = ET.SubElement(format, 'pixel_aspect_ratio')
el.text = u"1:1" el.text = u"1:1"
if settings.CONFIG['video'].get('download'): if has_capability(request.user, 'canDownloadVideo'):
if item.torrent: if item.torrent:
el = ET.SubElement(entry, "link") el = ET.SubElement(entry, "link")
el.attrib['rel'] = 'enclosure' el.attrib['rel'] = 'enclosure'

View file

@ -339,3 +339,11 @@ def user_json(user, keys=None):
if key not in keys: if key not in keys:
del j[key] del j[key]
return j return j
def has_capability(user, capability):
if user.is_anonymous():
level = 'guest'
else:
level = user.get_profile().get_level()
return level in settings.CONFIG['capabilities'][capability] \
and settings.CONFIG['capabilities'][capability][level]