add option to have direct download instead of torrent

This commit is contained in:
j 2013-09-14 14:09:37 +00:00
parent d8fff463de
commit f3c9d7b7af
9 changed files with 42 additions and 3 deletions

View File

@ -890,6 +890,7 @@
// fixme: this should include colors
"userLevels": ["guest", "member", "friend", "staff", "admin"],
"video": {
"torrent": true,
"formats": ["webm", "mp4"],
// fixme: this should be named "ratio" or "defaultRatio",
// as it also applies to clip lists (on load)

View File

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

View File

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

View File

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

View File

@ -19,6 +19,9 @@ urlpatterns = patterns("item.views",
(r'^(?P<id>[A-Z0-9].*)/torrent$', 'torrent'),
(r'^(?P<id>[A-Z0-9].*)/torrent/(?P<filename>.*?)$', 'torrent'),
#download
(r'^(?P<id>[A-Z0-9].*)/download/$', 'download'),
#export
(r'^(?P<id>[A-Z0-9].*)/json$', 'item_json'),
(r'^(?P<id>[A-Z0-9].*)/xml$', 'item_xml'),

View File

@ -831,6 +831,36 @@ def timeline(request, id, size, position=-1, format='jpg', mode=None):
path = timeline()
return HttpFileResponse(path, content_type='image/jpeg')
def download(request, id, index=1):
item = get_object_or_404(models.Item, itemId=id)
resolution = max(settings.CONFIG['video']['resolutions'])
format = 'webm'
if not item.access(request.user):
return HttpResponseForbidden()
if index:
index = int(index) - 1
else:
index = 0
streams = item.streams()
if index + 1 > streams.count():
raise Http404
stream = streams[index].get(resolution, format)
if not stream.available or not stream.media:
raise Http404
path = stream.media.path
content_type = mimetypes.guess_type(path)[0]
ext = os.path.splitext(path)[-1]
filename = "%s - %s %s%s" % (
item.get('title'),
settings.SITENAME,
item.itemId,
ext
)
response = HttpFileResponse(path, content_type=content_type)
response['Content-Disposition'] = "attachment; filename*=UTF-8''%s" % quote(filename.encode('utf-8'))
return response
def torrent(request, id, filename=None):
item = get_object_or_404(models.Item, itemId=id)
if not item.access(request.user):

View File

@ -127,7 +127,7 @@ pandora.ui.editor = function(data) {
pandora.$ui[dialog] = pandora.ui[dialog](data).open();
},
downloadvideo: function(data) {
document.location.href = '/' + ui.item + '/torrent/';
document.location.href = pandora.getDownloadLink(ui.item);
},
downloadselection: function(data) {
document.location.href = '/' + ui.item

View File

@ -84,7 +84,7 @@ pandora.ui.player = function(data) {
}), 'clip');
},
downloadvideo: function(data) {
document.location.href = '/' + ui.item + '/torrent/';
document.location.href = pandora.getDownloadLink(ui.item);
},
find: function(data) {
pandora.UI.set({itemFind: data.find});

View File

@ -928,6 +928,9 @@ pandora.getClipVideos = function(clip, resolution) {
};
}());
pandora.getDownloadLink = function(item) {
return '/' + item + (pandora.site.video.torrent ? '/torrent/' : '/download/');
}
pandora.getEditTooltip = function(title) {
return function(e) {