jellyfin-web/dashboard-ui/scripts/encodingsettings.js

202 lines
6.3 KiB
JavaScript
Raw Normal View History

define(['jQuery'], function ($) {
2016-06-28 22:49:31 -07:00
function loadPage(page, config, systemInfo) {
2016-02-08 19:15:26 -07:00
page.querySelector('#chkEnableThrottle').checked = config.EnableThrottling;
2015-11-26 21:33:20 -07:00
$('#selectVideoDecoder', page).val(config.HardwareAccelerationType);
2015-09-03 10:01:51 -07:00
$('#selectThreadCount', page).val(config.EncodingThreadCount);
2014-04-18 10:16:25 -07:00
$('#txtDownMixAudioBoost', page).val(config.DownMixAudioBoost);
2016-06-23 10:21:37 -07:00
page.querySelector('.txtEncoderPath').value = config.EncoderAppPath || '';
$('#txtTranscodingTempPath', page).val(config.TranscodingTempPath || '');
2014-04-18 10:16:25 -07:00
2016-06-28 22:49:31 -07:00
var selectEncoderPath = page.querySelector('#selectEncoderPath');
selectEncoderPath.value = systemInfo.EncoderLocationType;
onSelectEncoderPathChange.call(selectEncoderPath);
Dashboard.hideLoadingMsg();
}
2016-06-23 10:04:18 -07:00
function onSaveEncodingPathFailure(response) {
Dashboard.hideLoadingMsg();
var msg = '';
// This is a fallback that handles both 404 and 400 (no path entered)
msg = Globalize.translate('FFmpegSavePathNotFound');
require(['alert'], function (alert) {
alert(msg);
});
}
2016-06-28 22:49:31 -07:00
function updateEncoder(form) {
2016-07-30 10:43:55 -07:00
return ApiClient.getSystemInfo().then(function (systemInfo) {
2016-06-28 22:49:31 -07:00
if (systemInfo.EncoderLocationType == "External") {
return;
}
return ApiClient.ajax({
url: ApiClient.getUrl('System/MediaEncoder/Path'),
type: 'POST',
data: {
Path: form.querySelector('.txtEncoderPath').value,
PathType: form.querySelector('#selectEncoderPath').value
}
}).then(Dashboard.processServerConfigurationUpdateResult, onSaveEncodingPathFailure);
});
}
2015-06-07 18:23:56 -07:00
function onSubmit() {
var form = this;
2016-06-19 23:19:28 -07:00
var onDecoderConfirmed = function () {
2016-02-04 21:56:07 -07:00
Dashboard.showLoadingMsg();
2015-06-07 18:23:56 -07:00
2016-02-04 21:56:07 -07:00
ApiClient.getNamedConfiguration("encoding").then(function (config) {
config.DownMixAudioBoost = $('#txtDownMixAudioBoost', form).val();
config.TranscodingTempPath = $('#txtTranscodingTempPath', form).val();
config.EncodingThreadCount = $('#selectThreadCount', form).val();
config.HardwareAccelerationType = $('#selectVideoDecoder', form).val();
2016-02-08 19:15:26 -07:00
config.EnableThrottling = form.querySelector('#chkEnableThrottle').checked;
2016-06-23 10:04:18 -07:00
ApiClient.updateNamedConfiguration("encoding", config).then(function () {
2016-06-28 22:49:31 -07:00
updateEncoder(form);
2016-06-23 10:04:18 -07:00
});
2016-02-04 21:56:07 -07:00
});
};
if ($('#selectVideoDecoder', form).val()) {
2016-02-26 13:29:27 -07:00
require(['alert'], function (alert) {
alert({
title: Globalize.translate('TitleHardwareAcceleration'),
text: Globalize.translate('HardwareAccelerationWarning')
}).then(onDecoderConfirmed);
2016-02-04 21:56:07 -07:00
});
} else {
onDecoderConfirmed();
}
2015-06-07 18:23:56 -07:00
// Disable default form submission
return false;
}
2016-04-12 22:28:45 -07:00
function getTabs() {
return [
{
href: 'cinemamodeconfiguration.html',
name: Globalize.translate('TabCinemaMode')
},
{
href: 'playbackconfiguration.html',
name: Globalize.translate('TabResumeSettings')
},
{
href: 'streamingsettings.html',
name: Globalize.translate('TabStreaming')
},
{
href: 'encodingsettings.html',
name: Globalize.translate('TabTranscoding')
}];
}
2016-06-28 22:49:31 -07:00
function onSelectEncoderPathChange(e) {
var page = $(this).parents('.page')[0];
if (this.value == 'Custom') {
page.querySelector('.fldEncoderPath').classList.remove('hide');
2016-07-30 10:43:55 -07:00
page.querySelector('.txtEncoderPath').setAttribute('required', 'required');
2016-06-28 22:49:31 -07:00
} else {
page.querySelector('.fldEncoderPath').classList.add('hide');
2016-07-30 10:43:55 -07:00
page.querySelector('.txtEncoderPath').removeAttribute('required');
2016-06-28 22:49:31 -07:00
}
}
2015-09-01 07:01:59 -07:00
$(document).on('pageinit', "#encodingSettingsPage", function () {
var page = this;
2016-06-19 23:19:28 -07:00
$('#btnSelectEncoderPath', page).on("click.selectDirectory", function () {
require(['directorybrowser'], function (directoryBrowser) {
2016-06-23 10:04:18 -07:00
var picker = new directoryBrowser();
2016-06-19 23:19:28 -07:00
picker.show({
2016-06-23 10:04:18 -07:00
includeFiles: true,
2016-06-19 23:19:28 -07:00
callback: function (path) {
if (path) {
$('.txtEncoderPath', page).val(path);
}
picker.close();
}
});
});
});
$('#btnSelectTranscodingTempPath', page).on("click.selectDirectory", function () {
2015-10-13 12:22:45 -07:00
require(['directorybrowser'], function (directoryBrowser) {
2015-10-13 12:22:45 -07:00
var picker = new directoryBrowser();
2015-10-13 12:22:45 -07:00
picker.show({
2015-10-13 12:22:45 -07:00
callback: function (path) {
2015-10-13 12:22:45 -07:00
if (path) {
$('#txtTranscodingTempPath', page).val(path);
}
picker.close();
},
2015-10-13 12:22:45 -07:00
header: Globalize.translate('HeaderSelectTranscodingPath'),
instruction: Globalize.translate('HeaderSelectTranscodingPathHelp')
});
});
});
2015-06-07 18:23:56 -07:00
$('.encodingSettingsForm').off('submit', onSubmit).on('submit', onSubmit);
2016-06-28 22:49:31 -07:00
page.querySelector('#selectEncoderPath').addEventListener('change', onSelectEncoderPathChange);
2015-06-07 18:23:56 -07:00
2015-09-24 10:08:10 -07:00
}).on('pageshow', "#encodingSettingsPage", function () {
Dashboard.showLoadingMsg();
2016-06-19 23:19:28 -07:00
LibraryMenu.setTabs('playback', 3, getTabs);
var page = this;
2015-12-14 08:43:03 -07:00
ApiClient.getNamedConfiguration("encoding").then(function (config) {
2016-06-28 22:49:31 -07:00
ApiClient.getSystemInfo().then(function (systemInfo) {
2016-06-28 22:49:31 -07:00
if (systemInfo.EncoderLocationType == "External") {
page.querySelector('.fldSelectEncoderPathType').classList.add('hide');
} else {
page.querySelector('.fldSelectEncoderPathType').classList.remove('hide');
}
loadPage(page, config, systemInfo);
});
});
2016-06-28 22:49:31 -07:00
});
});