This commit is contained in:
Bond_009 2023-02-20 20:32:49 +01:00
parent 720852f708
commit cf29e9a9c5
2 changed files with 65 additions and 8 deletions

View File

@ -147,11 +147,16 @@ namespace Emby.Dlna.Server
}
}
private string GetFriendlyName()
internal string GetFriendlyName()
{
if (string.IsNullOrEmpty(_profile.FriendlyName))
{
return "Jellyfin - " + _serverName;
return _serverName;
}
if (!_profile.FriendlyName.Contains("${HostName}", StringComparison.OrdinalIgnoreCase))
{
return _profile.FriendlyName;
}
var characterList = new List<char>();
@ -164,13 +169,18 @@ namespace Emby.Dlna.Server
}
}
var characters = characterList.ToArray();
var serverName = string.Create(
characterList.Count,
characterList,
(dest, source) =>
{
for (int i = 0; i < dest.Length; i++)
{
dest[i] = source[i];
}
});
var serverName = new string(characters);
var name = _profile.FriendlyName?.Replace("${HostName}", serverName, StringComparison.OrdinalIgnoreCase);
return name ?? string.Empty;
return _profile.FriendlyName.Replace("${HostName}", serverName, StringComparison.OrdinalIgnoreCase);
}
private void AppendIconList(StringBuilder builder)

View File

@ -0,0 +1,47 @@
using Emby.Dlna.Server;
using MediaBrowser.Model.Dlna;
using Xunit;
namespace Jellyfin.Dlna.Server.Tests;
public class DescriptionXmlBuilderTests
{
[Fact]
public void GetFriendlyName_EmptyProfile_ReturnsServerName()
{
const string ServerName = "Test Server Name";
var builder = new DescriptionXmlBuilder(new DeviceProfile(), "serverUdn", "localhost", ServerName, string.Empty);
Assert.Equal(ServerName, builder.GetFriendlyName());
}
[Fact]
public void GetFriendlyName_FriendlyName_ReturnsFriendlyName()
{
const string FriendlyName = "Friendly Neighborhood Test Server";
var builder = new DescriptionXmlBuilder(
new DeviceProfile()
{
FriendlyName = FriendlyName
},
"serverUdn",
"localhost",
"Test Server Name",
string.Empty);
Assert.Equal(FriendlyName, builder.GetFriendlyName());
}
[Fact]
public void GetFriendlyName_FriendlyNameInterpolation_ReturnsFriendlyName()
{
var builder = new DescriptionXmlBuilder(
new DeviceProfile()
{
FriendlyName = "Friendly Neighborhood ${HostName}"
},
"serverUdn",
"localhost",
"Test Server Name",
string.Empty);
Assert.Equal("Friendly Neighborhood TestServerName", builder.GetFriendlyName());
}
}