Skip to content

Commit

Permalink
Add additional profile logging (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
disgustipated authored Nov 3, 2024
1 parent de7fc62 commit 298a221
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
22 changes: 13 additions & 9 deletions src/Jellyfin.Plugin.Dlna/DlnaManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public async Task InitProfilesAsync()
try
{
await ExtractSystemProfilesAsync().ConfigureAwait(false);
_logger.LogDebug("Creating user profiles directory {0} if it doesnt exist", UserProfilesPath);
Directory.CreateDirectory(UserProfilesPath);
LoadProfiles();
}
Expand All @@ -76,10 +77,12 @@ public async Task InitProfilesAsync()

private void LoadProfiles()
{
_logger.LogInformation("Using user profile directory {0}", UserProfilesPath);
var list = GetProfiles(UserProfilesPath, DeviceProfileType.User)
.OrderBy(i => i.Name)
.ToList();

_logger.LogInformation("Using system profile directory {0}", SystemProfilesPath);
list.AddRange(GetProfiles(SystemProfilesPath, DeviceProfileType.System)
.OrderBy(i => i.Name));
}
Expand Down Expand Up @@ -133,17 +136,17 @@ public DlnaDeviceProfile GetDefaultProfile()
/// <returns><b>True</b> if they match.</returns>
public bool IsMatch(DeviceIdentification deviceInfo, DeviceIdentification profileInfo)
{
return IsRegexOrSubstringMatch(deviceInfo.FriendlyName, profileInfo.FriendlyName)
&& IsRegexOrSubstringMatch(deviceInfo.Manufacturer, profileInfo.Manufacturer)
&& IsRegexOrSubstringMatch(deviceInfo.ManufacturerUrl, profileInfo.ManufacturerUrl)
&& IsRegexOrSubstringMatch(deviceInfo.ModelDescription, profileInfo.ModelDescription)
&& IsRegexOrSubstringMatch(deviceInfo.ModelName, profileInfo.ModelName)
&& IsRegexOrSubstringMatch(deviceInfo.ModelNumber, profileInfo.ModelNumber)
&& IsRegexOrSubstringMatch(deviceInfo.ModelUrl, profileInfo.ModelUrl)
&& IsRegexOrSubstringMatch(deviceInfo.SerialNumber, profileInfo.SerialNumber);
return IsRegexOrSubstringMatch(deviceInfo.FriendlyName, profileInfo.FriendlyName, "FriendlyName")
&& IsRegexOrSubstringMatch(deviceInfo.Manufacturer, profileInfo.Manufacturer, "Manufacturer")
&& IsRegexOrSubstringMatch(deviceInfo.ManufacturerUrl, profileInfo.ManufacturerUrl, "ManufacturerUrl")
&& IsRegexOrSubstringMatch(deviceInfo.ModelDescription, profileInfo.ModelDescription, "ModelDescription")
&& IsRegexOrSubstringMatch(deviceInfo.ModelName, profileInfo.ModelName, "ModelName")
&& IsRegexOrSubstringMatch(deviceInfo.ModelNumber, profileInfo.ModelNumber, "ModelNumber")
&& IsRegexOrSubstringMatch(deviceInfo.ModelUrl, profileInfo.ModelUrl, "ModelUrl")
&& IsRegexOrSubstringMatch(deviceInfo.SerialNumber, profileInfo.SerialNumber, "SerialNumber");
}

private bool IsRegexOrSubstringMatch(string input, string pattern)
private bool IsRegexOrSubstringMatch(string input, string pattern, string fieldname)
{
if (string.IsNullOrEmpty(pattern))
{
Expand All @@ -159,6 +162,7 @@ private bool IsRegexOrSubstringMatch(string input, string pattern)

try
{
_logger.LogDebug("Comparing profile field {0} - device input '{1}' and profile pattern '{2}' for profile match", fieldname, input, pattern);
return input.Equals(pattern, StringComparison.OrdinalIgnoreCase)
|| Regex.IsMatch(input, pattern, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Jellyfin.Plugin.Dlna/PlayTo/PlayToManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ private async Task AddDevice(UpnpDeviceInfo info, CancellationToken cancellation
SupportsMediaControl = true
});

_logger.LogInformation("DLNA Session created for {0} - {1}", device.Properties.Name, device.Properties.ModelName);
_logger.LogInformation("DLNA Session created for {0} - {1} using profile {2}", device.Properties.Name, device.Properties.ModelName, profile.Name);
}
}

Expand Down

0 comments on commit 298a221

Please sign in to comment.