File Display Name Script
This is a special system script intended for modifying the names of files as they appear within the system.
This feature is primarily designed to showcase different file names in the Web Console without making any changes to the actual files themselves.
To make use of this functionality, you'll need to create the appropriate System Script.
This script should expose the following function:
function getDisplayName(fullPath, relativePath, libraryName) {
return 'Updated: ' + relativePath;
}
Parameter | Description |
---|---|
fullPath | The full name/path of the file |
relativePath | The path relative to the library, this is the default value shown when not using this script |
libraryName | The name of the library this file is in. So you can adjust your logic per library |
The value returned by this function will be the name shown in the Web Console.
Complete Example
function getDisplayName(fullName, relativePath, libraryName)
{
if(/(movies|tv)/i.test(libraryName) === false)
return relativePath;
let extension = relativePath.substring(relativePath.lastIndexOf('.') + 1);
if(/([/])[\w\d]+\.[\w\d]{2,6}$/i.test(relativePath))
relativePath = relativePath.substring(0, relativePath.lastIndexOf('/'));
else if(/([\\])[\w\d]+\.[\w\d]{2,6}$/i.test(relativePath))
relativePath = relativePath.substring(0, relativePath.lastIndexOf('\\'));
let hdr = /[\.\s\-]hdr/i.test(relativePath) === true;
let tenbit = /[\.\s\-]10(\-)?bit/i.test(relativePath) === true;
let twelvebit = /[\.\s\-]12(\-)?bit/i.test(relativePath) === true;
let resolution = ((resolutionMatch = /[\.\s\-](1080p|1080i|720p|420p|4k)/i.exec(relativePath)) && resolutionMatch[1]) || '';
let year = ((yearMatch = /[\.\s\-]((19|20)[\d]{2})[\.\s\-]/.exec(relativePath)) && yearMatch[1]) || '';
let yearIndex = year ? relativePath.indexOf(year) : -1;
let resolutionIndex = resolution ? relativePath.indexOf(resolution) : -1;
if(yearIndex > 0 || resolutionIndex > 0)
{
let closest = Math.min(yearIndex === -1 ? 9999999 : yearIndex, resolutionIndex === -1 ? 9999999 : resolutionIndex);
relativePath = relativePath.substring(0, closest);
relativePath = relativePath.replace(/\./g, ' ').replace(/.*[\/\\]/, '').trim();
}
relativePath = relativePath.replace(/(S\d+E\d+)/, ' - $1 - ');
if(relativePath.indexOf(' - .') > 0){
relativePath = relativePath.substring(0, relativePath.indexOf(' - .'));
relativePath = relativePath.replace(/\./g, ' ').replace(/.*[\/\\]/, '').trim();
}
relativePath = relativePath.replace(/\s{2,}/g, ' ');
let additional = [];
if(year)
additional.push(year);
if(resolution)
additional.push(resolution);
if(tenbit)
additional.push('10-Bit');
else if(twelvebit)
additional.push('12-Bit');
if(hdr)
additional.push('HDR');
relativePath = relativePath.trim();
if(relativePath.trim().endsWith(' -'))
relativePath = relativePath.substring(0, relativePath.length - 2);
if(additional.length)
relativePath += ' - ' + additional.join(' / ');
return relativePath + '.' + extension;
}