Merge pull request #9365 from Bond-009/friendlyname

pull/9370/head
Bond-009 2 years ago committed by GitHub
commit ccea623c0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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 = new string(characters);
var name = _profile.FriendlyName?.Replace("${HostName}", serverName, StringComparison.OrdinalIgnoreCase);
var serverName = string.Create(
characterList.Count,
characterList,
(dest, source) =>
{
for (int i = 0; i < dest.Length; i++)
{
dest[i] = source[i];
}
});
return name ?? string.Empty;
return _profile.FriendlyName.Replace("${HostName}", serverName, StringComparison.OrdinalIgnoreCase);
}
private void AppendIconList(StringBuilder builder)

@ -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());
}
}
Loading…
Cancel
Save