Skip to content

Commit

Permalink
Merge pull request jellyfin#5943 from Maxr1998/device-profile-defaults
Browse files Browse the repository at this point in the history
(cherry picked from commit 9d3f614)
Signed-off-by: Joshua M. Boniface <joshua@boniface.me>
  • Loading branch information
Bond-009 authored and joshuaboniface committed May 4, 2021
1 parent 9798bf2 commit 4c8df4c
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 124 deletions.
26 changes: 19 additions & 7 deletions Emby.Dlna/Didl/DidlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -974,15 +974,28 @@ private void AddCover(BaseItem item, StubType? stubType, XmlWriter writer)
return;
}

var albumartUrlInfo = GetImageUrl(imageInfo, _profile.MaxAlbumArtWidth, _profile.MaxAlbumArtHeight, "jpg");
// TODO: Remove these default values
var albumArtUrlInfo = GetImageUrl(
imageInfo,
_profile.MaxAlbumArtWidth ?? 10000,
_profile.MaxAlbumArtHeight ?? 10000,
"jpg");

writer.WriteStartElement("upnp", "albumArtURI", NsUpnp);
writer.WriteAttributeString("dlna", "profileID", NsDlna, _profile.AlbumArtPn);
writer.WriteString(albumartUrlInfo.url);
if (!string.IsNullOrEmpty(_profile.AlbumArtPn))
{
writer.WriteAttributeString("dlna", "profileID", NsDlna, _profile.AlbumArtPn);
}

writer.WriteString(albumArtUrlInfo.url);
writer.WriteFullEndElement();

// TOOD: Remove these default values
var iconUrlInfo = GetImageUrl(imageInfo, _profile.MaxIconWidth ?? 48, _profile.MaxIconHeight ?? 48, "jpg");
// TODO: Remove these default values
var iconUrlInfo = GetImageUrl(
imageInfo,
_profile.MaxIconWidth ?? 48,
_profile.MaxIconHeight ?? 48,
"jpg");
writer.WriteElementString("upnp", "icon", NsUpnp, iconUrlInfo.url);

if (!_profile.EnableAlbumArtInDidl)
Expand Down Expand Up @@ -1206,8 +1219,7 @@ public static string GetClientId(Guid idValue, StubType? stubType)

if (width.HasValue && height.HasValue)
{
var newSize = DrawingUtils.Resize(
new ImageDimensions(width.Value, height.Value), 0, 0, maxWidth, maxHeight);
var newSize = DrawingUtils.Resize(new ImageDimensions(width.Value, height.Value), 0, 0, maxWidth, maxHeight);

width = newSize.Width;
height = newSize.Height;
Expand Down
6 changes: 3 additions & 3 deletions Jellyfin.Api/Controllers/UniversalAudioController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,9 @@ private DeviceProfile GetDeviceProfile(
{
Type = DlnaProfileType.Audio,
Context = EncodingContext.Streaming,
Container = transcodingContainer,
AudioCodec = audioCodec,
Protocol = transcodingProtocol,
Container = transcodingContainer ?? "mp3",
AudioCodec = audioCodec ?? "mp3",
Protocol = transcodingProtocol ?? "http",
BreakOnNonKeyFrames = breakOnNonKeyFrames ?? false,
MaxAudioChannels = transcodingAudioChannels?.ToString(CultureInfo.InvariantCulture)
}
Expand Down
63 changes: 19 additions & 44 deletions MediaBrowser.Model/Dlna/ContainerProfile.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
#nullable disable
#pragma warning disable CS1591

using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Xml.Serialization;

namespace MediaBrowser.Model.Dlna
{
public class ContainerProfile
{
[Required]
[XmlAttribute("type")]
public DlnaProfileType Type { get; set; }

public ProfileCondition[] Conditions { get; set; }
public ProfileCondition[]? Conditions { get; set; } = Array.Empty<ProfileCondition>();

[Required]
[XmlAttribute("container")]
public string Container { get; set; }
public string Container { get; set; } = string.Empty;

public ContainerProfile()
{
Conditions = Array.Empty<ProfileCondition>();
}

public string[] GetContainers()
{
return SplitValue(Container);
}

public static string[] SplitValue(string value)
public static string[] SplitValue(string? value)
{
if (string.IsNullOrEmpty(value))
{
Expand All @@ -37,14 +29,14 @@ public static string[] SplitValue(string value)
return value.Split(',', StringSplitOptions.RemoveEmptyEntries);
}

public bool ContainsContainer(string container)
public bool ContainsContainer(string? container)
{
var containers = GetContainers();
var containers = SplitValue(Container);

return ContainsContainer(containers, container);
}

public static bool ContainsContainer(string profileContainers, string inputContainer)
public static bool ContainsContainer(string? profileContainers, string? inputContainer)
{
var isNegativeList = false;
if (profileContainers != null && profileContainers.StartsWith('-'))
Expand All @@ -56,46 +48,29 @@ public static bool ContainsContainer(string profileContainers, string inputConta
return ContainsContainer(SplitValue(profileContainers), isNegativeList, inputContainer);
}

public static bool ContainsContainer(string[] profileContainers, string inputContainer)
public static bool ContainsContainer(string[]? profileContainers, string? inputContainer)
{
return ContainsContainer(profileContainers, false, inputContainer);
}

public static bool ContainsContainer(string[] profileContainers, bool isNegativeList, string inputContainer)
public static bool ContainsContainer(string[]? profileContainers, bool isNegativeList, string? inputContainer)
{
if (profileContainers.Length == 0)
if (profileContainers == null || profileContainers.Length == 0)
{
return true;
return isNegativeList;
}

if (isNegativeList)
{
var allInputContainers = SplitValue(inputContainer);

foreach (var container in allInputContainers)
{
if (profileContainers.Contains(container, StringComparer.OrdinalIgnoreCase))
{
return false;
}
}
var allInputContainers = SplitValue(inputContainer);

return true;
}
else
foreach (var container in allInputContainers)
{
var allInputContainers = SplitValue(inputContainer);

foreach (var container in allInputContainers)
if (profileContainers.Contains(container, StringComparer.OrdinalIgnoreCase))
{
if (profileContainers.Contains(container, StringComparer.OrdinalIgnoreCase))
{
return true;
}
return !isNegativeList;
}

return false;
}

return isNegativeList;
}
}
}
Loading

0 comments on commit 4c8df4c

Please sign in to comment.