Allow multiple library folders
Build Plugin / build (push) Successful in 2m21s

This commit is contained in:
2025-12-19 23:29:25 +01:00
parent c02469c6d0
commit d3fbaef417
4 changed files with 340 additions and 36 deletions
@@ -1,7 +1,24 @@
using System.Collections.Generic;
using MediaBrowser.Model.Plugins;
namespace Jellyfin.Plugin.JellyLMS.Configuration;
/// <summary>
/// Represents a path mapping between Jellyfin and LMS file paths.
/// </summary>
public class PathMapping
{
/// <summary>
/// Gets or sets the path prefix as seen by Jellyfin.
/// </summary>
public string JellyfinPath { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the same path prefix as seen by LMS.
/// </summary>
public string LmsPath { get; set; } = string.Empty;
}
/// <summary>
/// Plugin configuration for JellyLMS.
/// </summary>
@@ -72,14 +89,46 @@ public class PluginConfiguration : BasePluginConfiguration
/// <summary>
/// Gets or sets the media path prefix as seen by Jellyfin.
/// Used for path mapping when UseDirectFilePath is enabled.
/// Example: /media/music or C:\Music.
/// Deprecated: Use PathMappings instead. Kept for backwards compatibility.
/// </summary>
public string JellyfinMediaPath { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the media path prefix as seen by LMS.
/// Used for path mapping when UseDirectFilePath is enabled.
/// Example: /mnt/music or //nas/music.
/// Deprecated: Use PathMappings instead. Kept for backwards compatibility.
/// </summary>
public string LmsMediaPath { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the list of path mappings between Jellyfin and LMS.
/// Each mapping allows files from different locations to be played via direct file access.
/// </summary>
public List<PathMapping> PathMappings { get; set; } = new();
/// <summary>
/// Gets all effective path mappings, including legacy single mapping if configured.
/// </summary>
/// <returns>Enumerable of all configured path mappings.</returns>
public IEnumerable<PathMapping> GetAllPathMappings()
{
// Return configured list mappings first
foreach (var mapping in PathMappings)
{
if (!string.IsNullOrEmpty(mapping.JellyfinPath) && !string.IsNullOrEmpty(mapping.LmsPath))
{
yield return mapping;
}
}
// Fall back to legacy single mapping for backwards compatibility
if (!string.IsNullOrEmpty(JellyfinMediaPath) && !string.IsNullOrEmpty(LmsMediaPath))
{
yield return new PathMapping
{
JellyfinPath = JellyfinMediaPath,
LmsPath = LmsMediaPath
};
}
}
}
@@ -154,16 +154,30 @@
</div>
<div id="directPathSettings" style="margin-top: 15px;">
<div class="inputContainer">
<label class="inputLabel inputLabelUnfocused" for="JellyfinMediaPath">Jellyfin Media Path</label>
<input id="JellyfinMediaPath" name="JellyfinMediaPath" type="text" is="emby-input" placeholder="/media/music" />
<div class="fieldDescription">The path prefix as Jellyfin sees your media library (e.g., /media/music)</div>
<h4 style="margin-bottom: 10px;">Path Mappings</h4>
<p class="fieldDescription">Map Jellyfin paths to LMS paths. Add multiple mappings if your music and podcasts are in different locations.</p>
<div style="margin-bottom: 15px;">
<button is="emby-button" type="button" id="btnDiscoverPaths" class="raised button-alt emby-button">
<span>Discover Jellyfin Paths</span>
</button>
<span id="discoverStatus" style="margin-left: 10px;"></span>
</div>
<div class="inputContainer">
<label class="inputLabel inputLabelUnfocused" for="LmsMediaPath">LMS Media Path</label>
<input id="LmsMediaPath" name="LmsMediaPath" type="text" is="emby-input" placeholder="/mnt/music" />
<div class="fieldDescription">The same location as LMS sees it (e.g., /mnt/music or //nas/music)</div>
<div id="discoveredPaths" style="display: none; margin-bottom: 15px; padding: 10px; background: rgba(0,0,0,0.2); border-radius: 4px;">
<strong>Detected Jellyfin paths:</strong>
<ul id="detectedPrefixList" style="margin: 5px 0; padding-left: 20px;"></ul>
<div class="fieldDescription">Click a path to use it as the Jellyfin path in a new mapping</div>
</div>
<div id="pathMappingsList">
<!-- Dynamic path mappings will be added here -->
</div>
<div style="margin-top: 10px;">
<button is="emby-button" type="button" id="btnAddMapping" class="raised button-alt emby-button">
<span>+ Add Mapping</span>
</button>
</div>
</div>
</div>
@@ -433,6 +447,113 @@
});
}
// Path Mapping Functions
function renderPathMappings(mappings) {
var container = document.querySelector('#pathMappingsList');
if (!mappings || mappings.length === 0) {
container.innerHTML = '<p class="fieldDescription">No path mappings configured. Click "Discover Jellyfin Paths" to get started.</p>';
return;
}
var html = '';
mappings.forEach(function(mapping, index) {
html += '<div class="path-mapping-row" style="display: flex; gap: 10px; align-items: flex-end; margin-bottom: 10px; padding: 10px; background: rgba(0,0,0,0.1); border-radius: 4px;">';
html += '<div style="flex: 1;">';
html += '<label class="inputLabel inputLabelUnfocused">Jellyfin Path</label>';
html += '<input type="text" is="emby-input" class="mapping-jellyfin-path" data-index="' + index + '" value="' + (mapping.JellyfinPath || '') + '" placeholder="/media/music" />';
html += '</div>';
html += '<div style="flex: 1;">';
html += '<label class="inputLabel inputLabelUnfocused">LMS Path</label>';
html += '<input type="text" is="emby-input" class="mapping-lms-path" data-index="' + index + '" value="' + (mapping.LmsPath || '') + '" placeholder="/mnt/music" />';
html += '</div>';
html += '<button is="emby-button" type="button" class="raised button-alt emby-button btnRemoveMapping" data-index="' + index + '" style="margin-bottom: 0;">';
html += '<span>Remove</span>';
html += '</button>';
html += '</div>';
});
container.innerHTML = html;
// Add remove handlers
container.querySelectorAll('.btnRemoveMapping').forEach(function(btn) {
btn.addEventListener('click', function() {
var idx = parseInt(this.getAttribute('data-index'));
JellyLmsConfig.pathMappings.splice(idx, 1);
renderPathMappings(JellyLmsConfig.pathMappings);
});
});
// Update stored mappings when inputs change
container.querySelectorAll('.mapping-jellyfin-path, .mapping-lms-path').forEach(function(input) {
input.addEventListener('change', function() {
var idx = parseInt(this.getAttribute('data-index'));
if (this.classList.contains('mapping-jellyfin-path')) {
JellyLmsConfig.pathMappings[idx].JellyfinPath = this.value;
} else {
JellyLmsConfig.pathMappings[idx].LmsPath = this.value;
}
});
});
}
function addPathMapping(jellyfinPath, lmsPath) {
JellyLmsConfig.pathMappings = JellyLmsConfig.pathMappings || [];
JellyLmsConfig.pathMappings.push({
JellyfinPath: jellyfinPath || '',
LmsPath: lmsPath || ''
});
renderPathMappings(JellyLmsConfig.pathMappings);
}
function discoverPaths() {
var statusDiv = document.querySelector('#discoverStatus');
statusDiv.innerHTML = '<span style="color: orange;">Discovering...</span>';
ApiClient.ajax({
url: ApiClient.getUrl('JellyLms/DiscoverPaths'),
type: 'GET',
dataType: 'json'
}).then(function(result) {
statusDiv.innerHTML = '';
var discoveredDiv = document.querySelector('#discoveredPaths');
var prefixList = document.querySelector('#detectedPrefixList');
if (result.DetectedPrefixes && result.DetectedPrefixes.length > 0) {
discoveredDiv.style.display = 'block';
var html = '';
result.DetectedPrefixes.forEach(function(prefix) {
html += '<li><a href="#" class="detected-prefix-link" data-path="' + prefix + '" style="color: #00a4dc;">' + prefix + '</a></li>';
});
prefixList.innerHTML = html;
// Add click handlers to use detected paths
prefixList.querySelectorAll('.detected-prefix-link').forEach(function(link) {
link.addEventListener('click', function(e) {
e.preventDefault();
addPathMapping(this.getAttribute('data-path'), '');
});
});
} else {
discoveredDiv.style.display = 'block';
prefixList.innerHTML = '<li>No audio files found in library</li>';
}
}).catch(function(err) {
statusDiv.innerHTML = '<span style="color: red;">Discovery failed</span>';
console.error('Path discovery failed:', err);
});
}
function getPathMappingsFromUI() {
var mappings = [];
document.querySelectorAll('.path-mapping-row').forEach(function(row) {
var jellyfinPath = row.querySelector('.mapping-jellyfin-path').value;
var lmsPath = row.querySelector('.mapping-lms-path').value;
if (jellyfinPath || lmsPath) {
mappings.push({ JellyfinPath: jellyfinPath, LmsPath: lmsPath });
}
});
return mappings;
}
document.querySelector('#JellyLmsConfigPage')
.addEventListener('pageshow', function() {
Dashboard.showLoadingMsg();
@@ -446,8 +567,18 @@
document.querySelector('#EnableAutoSync').checked = config.EnableAutoSync !== false;
document.querySelector('#DefaultPlayerMac').value = config.DefaultPlayerMac || '';
document.querySelector('#UseDirectFilePath').checked = config.UseDirectFilePath || false;
document.querySelector('#JellyfinMediaPath').value = config.JellyfinMediaPath || '';
document.querySelector('#LmsMediaPath').value = config.LmsMediaPath || '';
// Load path mappings (new list format, with fallback to legacy single mapping)
JellyLmsConfig.pathMappings = config.PathMappings || [];
// If no list mappings but legacy single mapping exists, show it
if (JellyLmsConfig.pathMappings.length === 0 && config.JellyfinMediaPath && config.LmsMediaPath) {
JellyLmsConfig.pathMappings = [{
JellyfinPath: config.JellyfinMediaPath,
LmsPath: config.LmsMediaPath
}];
}
renderPathMappings(JellyLmsConfig.pathMappings);
Dashboard.hideLoadingMsg();
loadPlayers();
@@ -491,8 +622,10 @@
config.EnableAutoSync = document.querySelector('#EnableAutoSync').checked;
config.DefaultPlayerMac = document.querySelector('#DefaultPlayerMac').value;
config.UseDirectFilePath = document.querySelector('#UseDirectFilePath').checked;
config.JellyfinMediaPath = document.querySelector('#JellyfinMediaPath').value;
config.LmsMediaPath = document.querySelector('#LmsMediaPath').value;
// Save path mappings (clear legacy single mapping when using list)
config.PathMappings = getPathMappingsFromUI();
config.JellyfinMediaPath = '';
config.LmsMediaPath = '';
ApiClient.updatePluginConfiguration(JellyLmsConfig.pluginUniqueId, config).then(function (result) {
Dashboard.processPluginConfigurationUpdateResult(result);
});
@@ -501,6 +634,16 @@
e.preventDefault();
return false;
});
document.querySelector('#btnDiscoverPaths')
.addEventListener('click', function() {
discoverPaths();
});
document.querySelector('#btnAddMapping')
.addEventListener('click', function() {
addPathMapping('', '');
});
</script>
</div>
</body>