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

169 lines
5.8 KiB
JavaScript
Raw Normal View History

(function ($, document, window) {
2015-06-08 14:32:20 -07:00
function updateSeasonPatternHelp(page, value) {
2015-06-08 14:32:20 -07:00
var resultValue = value.replace('%s', '1').replace('%0s', '01').replace('%00s', '001');
var replacementHtmlResult = Globalize.translate('OrganizePatternResult').replace('{0}', resultValue);
$('.seasonFolderFieldDescription', page).html(replacementHtmlResult);
}
2015-06-08 14:32:20 -07:00
2014-01-21 09:24:12 -07:00
function getEpisodeFileName(value, enableMultiEpisode) {
2015-06-08 14:32:20 -07:00
var seriesName = "Series Name";
var episodeTitle = "Episode Four";
2014-01-21 09:24:12 -07:00
var result = value.replace('%sn', seriesName)
.replace('%s.n', seriesName.replace(' ', '.'))
.replace('%s_n', seriesName.replace(' ', '_'))
.replace('%s', '1')
.replace('%0s', '01')
.replace('%00s', '001')
.replace('%ext', 'mkv')
.replace('%en', episodeTitle)
.replace('%e.n', episodeTitle.replace(' ', '.'))
2014-01-21 09:24:12 -07:00
.replace('%e_n', episodeTitle.replace(' ', '_'));
2015-06-08 14:32:20 -07:00
2014-01-21 09:24:12 -07:00
if (enableMultiEpisode) {
result = result
.replace('%ed', '5')
.replace('%0ed', '05')
.replace('%00ed', '005');
}
return result
.replace('%e', '4')
.replace('%0e', '04')
.replace('%00e', '004');
2014-01-21 09:24:12 -07:00
}
function updateEpisodePatternHelp(page, value) {
value = getEpisodeFileName(value, false);
2015-06-08 14:32:20 -07:00
var replacementHtmlResult = Globalize.translate('OrganizePatternResult').replace('{0}', value);
$('.episodePatternDescription', page).html(replacementHtmlResult);
}
2014-01-21 09:24:12 -07:00
function updateMultiEpisodePatternHelp(page, value) {
value = getEpisodeFileName(value, true);
var replacementHtmlResult = Globalize.translate('OrganizePatternResult').replace('{0}', value);
2014-01-21 09:24:12 -07:00
$('.multiEpisodePatternDescription', page).html(replacementHtmlResult);
}
function loadPage(page, config) {
2014-07-30 19:09:23 -07:00
var tvOptions = config.TvOptions;
$('#chkEnableTvSorting', page).checked(tvOptions.IsEnabled).checkboxradio('refresh');
$('#chkOverwriteExistingEpisodes', page).checked(tvOptions.OverwriteExistingEpisodes).checkboxradio('refresh');
$('#chkDeleteEmptyFolders', page).checked(tvOptions.DeleteEmptyFolders).checkboxradio('refresh');
$('#txtMinFileSize', page).val(tvOptions.MinFileSizeMb);
$('#txtSeasonFolderPattern', page).val(tvOptions.SeasonFolderPattern).trigger('change');
$('#txtSeasonZeroName', page).val(tvOptions.SeasonZeroFolderName);
$('#txtWatchFolder', page).val(tvOptions.WatchLocations[0] || '');
$('#txtEpisodePattern', page).val(tvOptions.EpisodeNamePattern).trigger('change');
2014-01-21 09:24:12 -07:00
$('#txtMultiEpisodePattern', page).val(tvOptions.MultiEpisodeNamePattern).trigger('change');
2014-01-29 13:30:26 -07:00
$('#txtDeleteLeftOverFiles', page).val(tvOptions.LeftOverFileExtensionsToDelete.join(';'));
2015-09-03 10:01:51 -07:00
$('#copyOrMoveFile', page).val(tvOptions.CopyOriginalFile.toString());
2015-06-08 14:32:20 -07:00
}
function onSubmit() {
var form = this;
ApiClient.getNamedConfiguration('autoorganize').done(function (config) {
var tvOptions = config.TvOptions;
tvOptions.IsEnabled = $('#chkEnableTvSorting', form).checked();
tvOptions.OverwriteExistingEpisodes = $('#chkOverwriteExistingEpisodes', form).checked();
tvOptions.DeleteEmptyFolders = $('#chkDeleteEmptyFolders', form).checked();
tvOptions.MinFileSizeMb = $('#txtMinFileSize', form).val();
tvOptions.SeasonFolderPattern = $('#txtSeasonFolderPattern', form).val();
tvOptions.SeasonZeroFolderName = $('#txtSeasonZeroName', form).val();
tvOptions.EpisodeNamePattern = $('#txtEpisodePattern', form).val();
tvOptions.MultiEpisodeNamePattern = $('#txtMultiEpisodePattern', form).val();
tvOptions.LeftOverFileExtensionsToDelete = $('#txtDeleteLeftOverFiles', form).val().split(';');
var watchLocation = $('#txtWatchFolder', form).val();
tvOptions.WatchLocations = watchLocation ? [watchLocation] : [];
tvOptions.CopyOriginalFile = $('#copyOrMoveFile', form).val();
2015-06-08 14:32:20 -07:00
ApiClient.updateNamedConfiguration('autoorganize', config).done(Dashboard.processServerConfigurationUpdateResult);
});
return false;
}
2015-06-08 14:32:20 -07:00
2015-09-01 07:01:59 -07:00
$(document).on('pageinit', "#libraryFileOrganizerPage", function () {
var page = this;
2014-01-20 23:10:58 -07:00
$('#txtSeasonFolderPattern', page).on('change keyup', function () {
updateSeasonPatternHelp(page, this.value);
});
2014-01-20 23:10:58 -07:00
$('#txtEpisodePattern', page).on('change keyup', function () {
updateEpisodePatternHelp(page, this.value);
});
2014-01-21 09:24:12 -07:00
$('#txtMultiEpisodePattern', page).on('change keyup', function () {
updateMultiEpisodePatternHelp(page, this.value);
});
$('#btnSelectWatchFolder', 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) {
$('#txtWatchFolder', page).val(path);
}
picker.close();
},
2015-10-13 12:22:45 -07:00
header: Globalize.translate('HeaderSelectWatchFolder'),
instruction: Globalize.translate('HeaderSelectWatchFolderHelp')
});
});
});
2015-06-08 14:32:20 -07:00
$('.libraryFileOrganizerForm').off('submit', onSubmit).on('submit', onSubmit);
2015-09-24 10:08:10 -07:00
}).on('pageshow', "#libraryFileOrganizerPage", function () {
var page = this;
2014-07-30 19:09:23 -07:00
ApiClient.getNamedConfiguration('autoorganize').done(function (config) {
loadPage(page, config);
});
});
})(jQuery, document, window);