1 line
12 KiB
JavaScript
1 line
12 KiB
JavaScript
define(["exports","./../modules/tabbedview/basetab.js","./../modules/loading/loading.js","./../modules/common/globalize.js","./../modules/formhelper.js","./../modules/emby-apiclient/connectionmanager.js","./codeceditor.js","./../modules/emby-elements/emby-input/emby-input.js","./../modules/emby-elements/emby-button/emby-button.js","./../modules/emby-elements/emby-checkbox/emby-checkbox.js","./../modules/emby-elements/emby-select/emby-select.js"],function(_exports,_basetab,_loading,_globalize,_formhelper,_connectionmanager,_codeceditor,_embyInput,_embyButton,_embyCheckbox,_embySelect){function loadPage(instance,config,codecs,defaultCodecConfigurations){var view=instance.view,selectHwa=view.querySelector(".selectHwa"),codecConfigs=(selectHwa.value=config.HardwareAccelerationMode||0,1===config.HardwareAccelerationMode?defaultCodecConfigurations:config.CodecConfigurations||[]);!function(context,codecs,codecConfigs){if(null==codecs||0===codecs.length)return;!function(codecs,codecConfigs){for(var i=0,length=codecs.length;i<length;i++){var codec=codecs[i],config=getConfigurationByCodecId(codecConfigs,codec.Id);config&&config.Priority?codec.Priority=config.Priority:codec.Priority=0}}(codecs,codecConfigs);var decoderHtml=renderCodecsGrouped(0,0,codecs.filter(function(codec){return"Decoder"===codec.Direction&&codec.IsHardwareCodec})),encoderHtml=renderCodecsGrouped(0,0,codecs.filter(function(codec){return"Encoder"===codec.Direction&&codec.IsHardwareCodec})),codecConfigs=renderCodecsGrouped(0,0,codecs.filter(function(codec){return"Encoder"===codec.Direction&&!codec.IsHardwareCodec&&codec.SupportsParameters}));context.querySelector(".hardwareDecoders").innerHTML=decoderHtml,context.querySelector(".hardwareEncoders").innerHTML=encoderHtml,context.querySelector(".softwareEncoders").innerHTML=codecConfigs}(view,instance.codecList=codecs,codecConfigs),Array.prototype.forEach.call(view.querySelectorAll(".chkEnableCodec"),function(c){var codecId=c.getAttribute("data-codec"),codecId=getConfigurationByCodecId(codecConfigs,codecId);c.checked=codecId&&codecId.IsEnabled}),view.querySelector(".chkEnableThrottle").checked=config.EnableThrottling,view.querySelector(".txtDownMixAudioBoost").value=config.DownMixAudioBoost,view.querySelector(".txtTranscodingTempPath").value=config.TranscodingTempPath||"",view.querySelector(".chkEnableSubtitleExtraction").checked=config.EnableSubtitleExtraction||!1,onHwaModeChange.call(instance,{target:selectHwa,currentTarget:selectHwa}),_loading.default.hide()}function renderCodecsGrouped(context,codecConfigs,codecs){return codecs.map(function(item){return item.MediaTypeName}).filter(distinct).map(function(group){var groupCodecs=codecs.filter(function(codec){return codec.MediaTypeName===group});return function(group,codecs){codecs.sort(function(c1,c2){return c2.Priority-c1.Priority});var html="";html+="<div>",codecs.length&&!codecs[0].IsHardwareCodec||(html+='<h3 class="checkboxListLabel">'+group+"</h3>");return html=(html+='<div class="checkboxList codecList">')+codecs.map(renderSingleCodec).join("")+"</div></div>"}(group,groupCodecs)}).join("")}function renderSingleCodec(codec,index,codecs){var checkBoxHtml='<label class="listItemCheckboxContainer">',name=codec.Name,name=(codec.IsHardwareCodec?checkBoxHtml+='<input type="checkbox" is="emby-checkbox" class="chkEnableCodec" data-codec="'+codec.Id+'" />':name=codec.MediaTypeName,checkBoxHtml+="<span>"+name+"</span></label>",""),upDownHtml=(ApiClient.isMinServerVersion("4.8.0.30")&&(codec.SupportsParameters&&(name+='<button type="button" title="'+_globalize.default.translate("HeaderCodecSettings")+'" is="paper-icon-button-light" class="listItemButton btnCodecParams" data-itemid="'+codec.Id+'"><i class="md-icon">settings</i></button>'),codec.Id)&&codec.IsHardwareCodec&&(name+='<button type="button" title="'+_globalize.default.translate("Info")+'" is="paper-icon-button-light" class="listItemButton btnCodecInfo" data-itemid="'+codec.Id+'"><i class="md-icon"></i></button>'),""),index=(0<index?upDownHtml+='<button type="button" is="paper-icon-button-light" title="'+_globalize.default.translate("HeaderMoveUpInOrder")+'" aria-label="'+_globalize.default.translate("HeaderMoveUpInOrder")+'" class="listItemButton btnSortableMoveUp btnSortable" data-pluginindex="'+codec.Id+'"><i class="md-icon">keyboard_arrow_up</i></button>':1<codecs.length&&(upDownHtml+='<button type="button" is="paper-icon-button-light" title="'+_globalize.default.translate("HeaderDownUpInOrder")+'" aria-label="'+_globalize.default.translate("HeaderDownUpInOrder")+'" class="listItemButton btnSortableMoveDown btnSortable" data-pluginindex="'+codec.Id+'"><i class="md-icon">keyboard_arrow_down</i></button>'),'<div class="listItem listItem-border sortableOption">');return(index+=checkBoxHtml)+'<div class="listItemBody two-line listItemBodyText"></div>'+name+upDownHtml+"</div>"}function onSubmit(e){var form=this,apiClient=(_loading.default.show(),ApiClient);return apiClient.getNamedConfiguration("encoding").then(function(config){config.DownMixAudioBoost=form.querySelector(".txtDownMixAudioBoost").value,config.TranscodingTempPath=form.querySelector(".txtTranscodingTempPath").value,config.EnableSubtitleExtraction=form.querySelector(".chkEnableSubtitleExtraction").checked,config.EnableThrottling=form.querySelector(".chkEnableThrottle").checked;var selectHwa=form.querySelector(".selectHwa"),codecConfigs=(config.HardwareAccelerationMode=parseInt(selectHwa.value),[]);2===config.HardwareAccelerationMode&&Array.prototype.forEach.call(form.querySelectorAll(".chkEnableCodec"),function(c){var priority=c.checked?100-function(checkBox){var li=checkBox.closest(".sortableOption"),index=0;for(;li=li.previousElementSibling;)index++;return index}(c):0,priority={CodecId:c.getAttribute("data-codec"),Priority:priority,IsEnabled:c.checked};codecConfigs.push(priority)}),config.HardwareAccelerationType=null,config.CodecConfigurations=codecConfigs,apiClient.updateNamedConfiguration("encoding",config).then(function(response){_loading.default.hide(),_formhelper.default.handleConfigurationSavedResponse(response)})}),e.preventDefault(),e.stopPropagation(),!1}function getConfigurationByCodecId(codecConfigs,codecId){if(codecId&&null!=codecConfigs&&0!==codecConfigs.length)for(var i=0;i<codecConfigs.length;i++)if(codecConfigs[i]&&codecConfigs[i].CodecId&&codecConfigs[i].CodecId===codecId)return codecConfigs[i];return null}function showCodecEditor(codec,editParams){_codeceditor.default.show(codec,editParams).then(function(){},function(){})}function distinct(value,index,self){return self.indexOf(value)===index}function bindEvents(instance){var boundOnCodecClick=function(e){var list,btnCodecInfo=e.target.closest(".btnCodecInfo");btnCodecInfo?(btnCodecInfo=findCodecById(this,btnCodecInfo.getAttribute("data-itemid")))&&showCodecEditor(btnCodecInfo,!1):(btnCodecInfo=e.target.closest(".btnCodecParams"))?(btnCodecInfo=findCodecById(this,btnCodecInfo.getAttribute("data-itemid")))&&showCodecEditor(btnCodecInfo,!0):(btnCodecInfo=e.target.closest(".btnSortable"))&&(e=btnCodecInfo.closest(".sortableOption"),list=e.closest(".codecList"),btnCodecInfo.classList.contains("btnSortableMoveDown")?(btnCodecInfo=e.nextElementSibling)&&(e.parentNode.removeChild(e),btnCodecInfo.parentNode.insertBefore(e,btnCodecInfo.nextElementSibling)):(btnCodecInfo=e.previousElementSibling)&&(e.parentNode.removeChild(e),btnCodecInfo.parentNode.insertBefore(e,btnCodecInfo)),Array.prototype.forEach.call(list.querySelectorAll(".sortableOption"),adjustSortableListElement))}.bind(instance),instance=instance.view;instance.querySelector(".hardwareDecoders").addEventListener("click",boundOnCodecClick),instance.querySelector(".hardwareEncoders").addEventListener("click",boundOnCodecClick),instance.querySelector(".softwareEncoders").addEventListener("click",boundOnCodecClick)}function findCodecById(instance,id){instance=instance.codecList;if(instance&&0<instance.length){instance=instance.filter(function(codec){return codec.Id===id});if(instance&&0<instance.length)return instance[0]}return null}function adjustSortableListElement(elem){var btnSortable=elem.querySelector(".btnSortable");elem.previousElementSibling?(btnSortable.classList.add("btnSortableMoveUp"),btnSortable.classList.remove("btnSortableMoveDown"),btnSortable.querySelector("i").innerHTML="keyboard_arrow_up"):(btnSortable.classList.remove("btnSortableMoveUp"),btnSortable.classList.add("btnSortableMoveDown"),btnSortable.querySelector("i").innerHTML="keyboard_arrow_down"),elem.nextElementSibling?elem.classList.add("listItem-border"):elem.classList.remove("listItem-border")}function onHwaModeChange(e){for(var e=e.currentTarget,advancedSections=this.view.querySelectorAll(".hwaAdvanced"),mode=e.value,i=0,length=advancedSections.length;i<length;i++)"2"===mode?advancedSections[i].classList.remove("hide"):advancedSections[i].classList.add("hide")}function checkMediaEncodingInitialization(instance,apiClient){_loading.default.show(),apiClient.getToneMapOptions().then(function(toneMapOptions){var view=instance.view;view.querySelector(".encodingSettingsForm").classList.remove("hide"),view.querySelector(".encodingNotInitializedMessage").classList.add("hide"),function(instance,apiClient){_loading.default.show();var configPromise=apiClient.getNamedConfiguration("encoding"),codecInfoPromise=apiClient.getVideoCodecInformation().catch(function(){return[]}),apiClient=apiClient.getJSON(apiClient.getUrl("Encoding/CodecConfiguration/Defaults")).catch(function(){return[]});Promise.all([configPromise,codecInfoPromise,apiClient]).then(function(responses){loadPage(instance,responses[0],responses[1],responses[2])})}(instance,apiClient)},function(errorResponse){var view=instance.view;view.querySelector(".encodingSettingsForm").classList.add("hide"),view.querySelector(".encodingNotInitializedMessage").classList.remove("hide"),503===errorResponse.status?function(instance,apiClient){setTimeout(function(){checkMediaEncodingInitialization(instance,apiClient)},1e3)}(instance,apiClient):_loading.default.hide()})}function TranscodingTab(view,params){_basetab.default.apply(this,arguments)}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,Object.assign(TranscodingTab.prototype,_basetab.default.prototype),TranscodingTab.prototype.loadTemplate=function(){return require(["text!transcoding/transcodingtab.html"])},TranscodingTab.prototype.onTemplateLoaded=function(){_basetab.default.prototype.onTemplateLoaded.apply(this,arguments);var apiClient=_connectionmanager.default.currentApiClient(),view=this.view;bindEvents(this),view.querySelector(".selectHwa").addEventListener("change",onHwaModeChange.bind(this)),view.querySelector(".hwaGuideLink").innerHTML=_globalize.default.translate("SeeOurHwaGuide",'<a is="emby-linkbutton" href="https://support.emby.media/support/solutions/articles/44001160148-hardware-acceleration-overview" class="button-link" target="_blank">',"</a>"),view.querySelector(".btnSelectTranscodingTempPath").addEventListener("click",function(){require(["directorybrowser"],function(directoryBrowser){var picker=new directoryBrowser;picker.show({callback:function(path){path&&(view.querySelector(".txtTranscodingTempPath").value=path),picker.close()},validateWriteable:!0,header:_globalize.default.translate("HeaderSelectTranscodingPath"),instruction:_globalize.default.translate("HeaderSelectTranscodingPathHelp")})})}),view.querySelector(".encodingSettingsForm").addEventListener("submit",onSubmit),apiClient.getSystemInfo().then(function(systemInfo){for(var hwaPremiereInfo=view.querySelectorAll(".hwaPremiereInfo"),i=0,length=hwaPremiereInfo.length;i<length;i++)systemInfo.HardwareAccelerationRequiresPremiere?hwaPremiereInfo[i].classList.remove("hide"):hwaPremiereInfo[i].classList.add("hide"),hwaPremiereInfo[i].innerHTML=_globalize.default.translate("FeatureRequiresEmbyPremiere",'<a href="https://emby.media/premiere" data-preset="premiereinfo" is="emby-linkbutton" type="button" class="button-link btnHwaPremiere">',"</a>")})},TranscodingTab.prototype.onResume=function(options){_basetab.default.prototype.onResume.apply(this,arguments),checkMediaEncodingInitialization(this,ApiClient)},TranscodingTab.prototype.destroy=function(){_basetab.default.prototype.destroy.apply(this,arguments),this.codecList=null},_exports.default=TranscodingTab}); |