pandora/static/js/downloadVideoDialog.js

186 lines
7 KiB
JavaScript
Raw Permalink Normal View History

2018-03-06 06:48:04 +00:00
'use strict';
pandora.ui.downloadVideoDialog = function(options) {
var ui = pandora.user.ui,
formats = {
'webm': 'WebM',
'mp4': 'MP4',
},
2020-02-02 14:42:14 +00:00
parts = options.out ? null : Ox.max(options.video.map(function(video) {
2019-10-31 10:16:16 +00:00
return video.index
})),
2018-03-06 06:48:04 +00:00
$content = Ox.Element()
.css({margin: '16px'}),
$text = $('<div>')
.html((
options.out
? Ox._(
'Download Selection ({0} - {1})<br>of {2}', [
Ox.formatDuration(options['in']),
Ox.formatDuration(options.out),
options.title
]
)
: Ox._('Download {0}', [options.title])
))
.css({marginBottom: '16px'})
.appendTo($content),
2019-10-31 10:16:16 +00:00
$format,
$resolution,
2018-03-06 06:48:04 +00:00
$form = window.$form = Ox.Form({
items: [
Ox.Select({
id: 'format',
items: pandora.site.video.formats.map(function(format) {
return {
id: format,
title: formats[format]
};
2019-10-31 10:16:16 +00:00
}).concat(!options.out && options.source ? [{
id: 'source',
title: Ox._('Source')
}] : []),
2018-03-06 06:48:04 +00:00
label: Ox._('Format'),
labelWidth: 120,
value: pandora.site.video.downloadFormat,
width: 240
})
.bindEvent({
change: function(data) {
2019-10-31 10:16:16 +00:00
if (data.value == 'source') {
$resolution.hide()
} else {
$resolution.show()
}
2018-03-06 06:48:04 +00:00
}
}),
2019-10-31 10:16:16 +00:00
$resolution = Ox.Select({
2018-03-06 06:48:04 +00:00
id: 'resolution',
items: pandora.site.video.resolutions.map(function(resolution) {
return {
id: resolution,
title: resolution + 'p'
};
}),
label: Ox._('Resolution'),
labelWidth: 120,
value: ui.videoResolution,
width: 240
})
.bindEvent({
change: function(data) {
}
})
2019-10-31 10:16:16 +00:00
].concat(parts ? [
Ox.Select({
id: 'part',
items: Ox.range(parts + 1).map(function(resolution, idx) {
return {
id: idx + 1,
title: 'Part ' + (idx+1)
};
}),
label: Ox._('Part'),
labelWidth: 120,
value: 1,
width: 240
})
.bindEvent({
change: function(data) {
}
})
] : [])
2018-03-06 06:48:04 +00:00
}).appendTo($content),
2019-08-21 14:23:34 +00:00
failed = false,
2018-03-06 06:48:04 +00:00
that = Ox.Dialog({
buttons: [
Ox.Button({
id: 'download',
title: Ox._('Download')
}).bindEvent({
click: function() {
2019-08-21 14:23:34 +00:00
if (failed) {
that.close();
return
}
2018-03-06 06:48:04 +00:00
var values = $form.values(),
url
if (options.out) {
2019-08-21 14:23:34 +00:00
var $screen = Ox.LoadingScreen({
size: 16
})
that.options({content: $screen.start()});
pandora.api.extractClip({
item: options.item,
resolution: values.resolution,
format: values.format,
'in': options['in'],
out: options.out
}, function(result) {
if (result.data.taskId) {
pandora.wait(result.data.taskId, function(result) {
console.log('wait -> ', result)
if (result.data.result) {
url = '/' + options.item
+ '/' + values.resolution
+ 'p.' + values.format
+ '?t=' + options['in'] + ',' + options.out;
that.close();
document.location.href = url
} else {
}
}, 1000)
} else {
that.options({content: 'Failed to extract clip.'});
that.options('buttons')[0].options({
title: Ox._('Close')
});
failed = true;
}
})
2018-03-06 06:48:04 +00:00
} else {
2019-10-31 10:16:16 +00:00
if (values.format == 'source') {
url = '/' + options.item
+ '/download/source/'
+ (values.part ? values.part : '')
} else {
url = '/' + options.item
+ '/download/' + values.resolution
+ 'p'
+ (values.part ? values.part : '')
+ '.' + values.format
}
2018-03-06 06:48:04 +00:00
}
2019-08-21 14:23:34 +00:00
if (url) {
that.close();
document.location.href = url
}
2018-03-06 06:48:04 +00:00
}
})
],
closeButton: true,
content: $content,
removeOnClose: true,
keys: {enter: 'download', escape: 'close'},
title: (
options.out
? Ox._('Download Video Selection')
: Ox._('Download Video')
),
width: 432
});
return that;
};