Skip to content

Commit

Permalink
More cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Bond-009 authored and crobibero committed Dec 27, 2021
1 parent 4441513 commit ea8f40e
Show file tree
Hide file tree
Showing 46 changed files with 135 additions and 203 deletions.
3 changes: 1 addition & 2 deletions Emby.Dlna/Didl/Filter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ public Filter()
public Filter(string filter)
{
_all = string.Equals(filter, "*", StringComparison.OrdinalIgnoreCase);

_fields = (filter ?? string.Empty).Split(',', StringSplitOptions.RemoveEmptyEntries);
_fields = filter.Split(',', StringSplitOptions.RemoveEmptyEntries);
}

public bool Contains(string field)
Expand Down
59 changes: 26 additions & 33 deletions Emby.Dlna/PlayTo/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1179,75 +1179,68 @@ public static async Task<Device> CreateuPnpDeviceAsync(Uri url, IHttpClientFacto
return new Device(deviceProperties, httpClientFactory, logger);
}

#nullable enable
private static DeviceIcon CreateIcon(XElement element)
{
if (element == null)
{
throw new ArgumentNullException(nameof(element));
}

var mimeType = element.GetDescendantValue(UPnpNamespaces.Ud.GetName("mimetype"));
var width = element.GetDescendantValue(UPnpNamespaces.Ud.GetName("width"));
var height = element.GetDescendantValue(UPnpNamespaces.Ud.GetName("height"));
var depth = element.GetDescendantValue(UPnpNamespaces.Ud.GetName("depth"));
var url = element.GetDescendantValue(UPnpNamespaces.Ud.GetName("url"));

var widthValue = int.Parse(width, NumberStyles.Integer, CultureInfo.InvariantCulture);
var heightValue = int.Parse(height, NumberStyles.Integer, CultureInfo.InvariantCulture);
_ = int.TryParse(width, NumberStyles.Integer, CultureInfo.InvariantCulture, out var widthValue);
_ = int.TryParse(height, NumberStyles.Integer, CultureInfo.InvariantCulture, out var heightValue);

return new DeviceIcon
{
Depth = depth,
Depth = element.GetDescendantValue(UPnpNamespaces.Ud.GetName("depth")) ?? string.Empty,
Height = heightValue,
MimeType = mimeType,
Url = url,
MimeType = element.GetDescendantValue(UPnpNamespaces.Ud.GetName("mimetype")) ?? string.Empty,
Url = element.GetDescendantValue(UPnpNamespaces.Ud.GetName("url")) ?? string.Empty,
Width = widthValue
};
}

private static DeviceService Create(XElement element)
{
var type = element.GetDescendantValue(UPnpNamespaces.Ud.GetName("serviceType"));
var id = element.GetDescendantValue(UPnpNamespaces.Ud.GetName("serviceId"));
var scpdUrl = element.GetDescendantValue(UPnpNamespaces.Ud.GetName("SCPDURL"));
var controlURL = element.GetDescendantValue(UPnpNamespaces.Ud.GetName("controlURL"));
var eventSubURL = element.GetDescendantValue(UPnpNamespaces.Ud.GetName("eventSubURL"));

return new DeviceService
{
ControlUrl = controlURL,
EventSubUrl = eventSubURL,
ScpdUrl = scpdUrl,
ServiceId = id,
ServiceType = type
=> new DeviceService()
{
ControlUrl = element.GetDescendantValue(UPnpNamespaces.Ud.GetName("controlURL")) ?? string.Empty,
EventSubUrl = element.GetDescendantValue(UPnpNamespaces.Ud.GetName("eventSubURL")) ?? string.Empty,
ScpdUrl = element.GetDescendantValue(UPnpNamespaces.Ud.GetName("SCPDURL")) ?? string.Empty,
ServiceId = element.GetDescendantValue(UPnpNamespaces.Ud.GetName("serviceId")) ?? string.Empty,
ServiceType = element.GetDescendantValue(UPnpNamespaces.Ud.GetName("serviceType")) ?? string.Empty
};
}

private void UpdateMediaInfo(UBaseObject mediaInfo, TransportState state)
private void UpdateMediaInfo(UBaseObject? mediaInfo, TransportState state)
{
TransportState = state;

var previousMediaInfo = CurrentMediaInfo;
CurrentMediaInfo = mediaInfo;

if (previousMediaInfo == null && mediaInfo != null)
if (mediaInfo == null)
{
if (state != TransportState.Stopped)
if (previousMediaInfo != null)
{
OnPlaybackStart(mediaInfo);
OnPlaybackStop(previousMediaInfo);
}
}
else if (mediaInfo != null && previousMediaInfo != null && !mediaInfo.Equals(previousMediaInfo))
else if (previousMediaInfo == null)
{
OnMediaChanged(previousMediaInfo, mediaInfo);
if (state != TransportState.Stopped)
{
OnPlaybackStart(mediaInfo);
}
}
else if (mediaInfo == null && previousMediaInfo != null)
else if (mediaInfo.Equals(previousMediaInfo))
{
OnPlaybackStop(previousMediaInfo);
OnPlaybackProgress(mediaInfo);
}
else if (mediaInfo != null && mediaInfo.Equals(previousMediaInfo))
else
{
OnPlaybackProgress(mediaInfo);
OnMediaChanged(previousMediaInfo, mediaInfo);
}
}

Expand Down
6 changes: 3 additions & 3 deletions Emby.Dlna/PlayTo/PlayToController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ private async void OnDevicePlaybackStopped(object sender, PlaybackStoppedEventAr

var mediaSource = await streamInfo.GetMediaSource(CancellationToken.None).ConfigureAwait(false);

var duration = mediaSource == null ?
(_device.Duration == null ? (long?)null : _device.Duration.Value.Ticks) :
mediaSource.RunTimeTicks;
var duration = mediaSource == null
? _device.Duration?.Ticks
: mediaSource.RunTimeTicks;

var playedToCompletion = positionTicks.HasValue && positionTicks.Value == 0;

Expand Down
2 changes: 1 addition & 1 deletion Emby.Dlna/PlayTo/TransportCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private string BuildArgumentXml(Argument argument, string? value, string command
var sendValue = state.AllowedValues.FirstOrDefault(a => string.Equals(a, commandParameter, StringComparison.OrdinalIgnoreCase)) ??
(state.AllowedValues.Count > 0 ? state.AllowedValues[0] : value);

return string.Format(CultureInfo.InvariantCulture, "<{0} xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"{1}\">{2}</{0}>", argument.Name, state.DataType ?? "string", sendValue);
return string.Format(CultureInfo.InvariantCulture, "<{0} xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"{1}\">{2}</{0}>", argument.Name, state.DataType, sendValue);
}

return string.Format(CultureInfo.InvariantCulture, "<{0}>{1}</{0}>", argument.Name, value);
Expand Down
3 changes: 1 addition & 2 deletions Emby.Dlna/Profiles/DefaultProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@ public DefaultProfile()

public void AddXmlRootAttribute(string name, string value)
{
var atts = XmlRootAttributes ?? System.Array.Empty<XmlAttribute>();
var list = atts.ToList();
var list = XmlRootAttributes.ToList();

list.Add(new XmlAttribute
{
Expand Down
8 changes: 4 additions & 4 deletions Emby.Dlna/Server/DescriptionXmlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private void AppendIconList(StringBuilder builder)
builder.Append("<icon>");

builder.Append("<mimetype>")
.Append(SecurityElement.Escape(icon.MimeType ?? string.Empty))
.Append(SecurityElement.Escape(icon.MimeType))
.Append("</mimetype>");
builder.Append("<width>")
.Append(SecurityElement.Escape(icon.Width.ToString(CultureInfo.InvariantCulture)))
Expand All @@ -198,7 +198,7 @@ private void AppendIconList(StringBuilder builder)
.Append(SecurityElement.Escape(icon.Height.ToString(CultureInfo.InvariantCulture)))
.Append("</height>");
builder.Append("<depth>")
.Append(SecurityElement.Escape(icon.Depth ?? string.Empty))
.Append(SecurityElement.Escape(icon.Depth))
.Append("</depth>");
builder.Append("<url>")
.Append(BuildUrl(icon.Url))
Expand All @@ -219,10 +219,10 @@ private void AppendServiceList(StringBuilder builder)
builder.Append("<service>");

builder.Append("<serviceType>")
.Append(SecurityElement.Escape(service.ServiceType ?? string.Empty))
.Append(SecurityElement.Escape(service.ServiceType))
.Append("</serviceType>");
builder.Append("<serviceId>")
.Append(SecurityElement.Escape(service.ServiceId ?? string.Empty))
.Append(SecurityElement.Escape(service.ServiceId))
.Append("</serviceId>");
builder.Append("<SCPDURL>")
.Append(BuildUrl(service.ScpdUrl))
Expand Down
12 changes: 6 additions & 6 deletions Emby.Dlna/Service/ServiceXmlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private static void AppendActionList(StringBuilder builder, IEnumerable<ServiceA
builder.Append("<action>");

builder.Append("<name>")
.Append(SecurityElement.Escape(item.Name ?? string.Empty))
.Append(SecurityElement.Escape(item.Name))
.Append("</name>");

builder.Append("<argumentList>");
Expand All @@ -48,13 +48,13 @@ private static void AppendActionList(StringBuilder builder, IEnumerable<ServiceA
builder.Append("<argument>");

builder.Append("<name>")
.Append(SecurityElement.Escape(argument.Name ?? string.Empty))
.Append(SecurityElement.Escape(argument.Name))
.Append("</name>");
builder.Append("<direction>")
.Append(SecurityElement.Escape(argument.Direction ?? string.Empty))
.Append(SecurityElement.Escape(argument.Direction))
.Append("</direction>");
builder.Append("<relatedStateVariable>")
.Append(SecurityElement.Escape(argument.RelatedStateVariable ?? string.Empty))
.Append(SecurityElement.Escape(argument.RelatedStateVariable))
.Append("</relatedStateVariable>");

builder.Append("</argument>");
Expand All @@ -81,10 +81,10 @@ private static void AppendServiceStateTable(StringBuilder builder, IEnumerable<S
.Append("\">");

builder.Append("<name>")
.Append(SecurityElement.Escape(item.Name ?? string.Empty))
.Append(SecurityElement.Escape(item.Name))
.Append("</name>");
builder.Append("<dataType>")
.Append(SecurityElement.Escape(item.DataType ?? string.Empty))
.Append(SecurityElement.Escape(item.DataType))
.Append("</dataType>");

if (item.AllowedValues.Count > 0)
Expand Down
2 changes: 1 addition & 1 deletion Emby.Drawing/ImageProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ private ImageFormat GetOutputFormat(IReadOnlyCollection<ImageFormat> clientSuppo
return ImageFormat.Jpg;
}

private string? GetMimeType(ImageFormat format, string path)
private string GetMimeType(ImageFormat format, string path)
=> format switch
{
ImageFormat.Bmp => MimeTypes.GetMimeType("i.bmp"),
Expand Down
2 changes: 1 addition & 1 deletion Emby.Naming/TV/SeriesPathParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private static SeriesPathParserResult Parse(string name, EpisodeExpression expre
if (expression.IsNamed)
{
result.SeriesName = match.Groups["seriesname"].Value;
result.Success = !string.IsNullOrEmpty(result.SeriesName) && !string.IsNullOrEmpty(match.Groups["seasonnumber"]?.Value);
result.Success = !string.IsNullOrEmpty(result.SeriesName) && !match.Groups["seasonnumber"].ValueSpan.IsEmpty;
}
}

Expand Down
32 changes: 16 additions & 16 deletions Emby.Notifications/CoreNotificationTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,63 +24,63 @@ public IEnumerable<NotificationTypeInfo> GetNotificationTypes()
{
new NotificationTypeInfo
{
Type = NotificationType.ApplicationUpdateInstalled.ToString()
Type = nameof(NotificationType.ApplicationUpdateInstalled)
},
new NotificationTypeInfo
{
Type = NotificationType.InstallationFailed.ToString()
Type = nameof(NotificationType.InstallationFailed)
},
new NotificationTypeInfo
{
Type = NotificationType.PluginInstalled.ToString()
Type = nameof(NotificationType.PluginInstalled)
},
new NotificationTypeInfo
{
Type = NotificationType.PluginError.ToString()
Type = nameof(NotificationType.PluginError)
},
new NotificationTypeInfo
{
Type = NotificationType.PluginUninstalled.ToString()
Type = nameof(NotificationType.PluginUninstalled)
},
new NotificationTypeInfo
{
Type = NotificationType.PluginUpdateInstalled.ToString()
Type = nameof(NotificationType.PluginUpdateInstalled)
},
new NotificationTypeInfo
{
Type = NotificationType.ServerRestartRequired.ToString()
Type = nameof(NotificationType.ServerRestartRequired)
},
new NotificationTypeInfo
{
Type = NotificationType.TaskFailed.ToString()
Type = nameof(NotificationType.TaskFailed)
},
new NotificationTypeInfo
{
Type = NotificationType.NewLibraryContent.ToString()
Type = nameof(NotificationType.NewLibraryContent)
},
new NotificationTypeInfo
{
Type = NotificationType.AudioPlayback.ToString()
Type = nameof(NotificationType.AudioPlayback)
},
new NotificationTypeInfo
{
Type = NotificationType.VideoPlayback.ToString()
Type = nameof(NotificationType.VideoPlayback)
},
new NotificationTypeInfo
{
Type = NotificationType.AudioPlaybackStopped.ToString()
Type = nameof(NotificationType.AudioPlaybackStopped)
},
new NotificationTypeInfo
{
Type = NotificationType.VideoPlaybackStopped.ToString()
Type = nameof(NotificationType.VideoPlaybackStopped)
},
new NotificationTypeInfo
{
Type = NotificationType.UserLockedOut.ToString()
Type = nameof(NotificationType.UserLockedOut)
},
new NotificationTypeInfo
{
Type = NotificationType.ApplicationUpdateAvailable.ToString()
Type = nameof(NotificationType.ApplicationUpdateAvailable)
}
};

Expand All @@ -98,7 +98,7 @@ public IEnumerable<NotificationTypeInfo> GetNotificationTypes()

private void Update(NotificationTypeInfo note)
{
note.Name = _localization.GetLocalizedString("NotificationOption" + note.Type) ?? note.Type;
note.Name = _localization.GetLocalizedString("NotificationOption" + note.Type);

note.IsBasedOnUserEvent = note.Type.IndexOf("Playback", StringComparison.OrdinalIgnoreCase) != -1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public void SaveConfiguration(string key, object configuration)
NewConfiguration = configuration
});

_configurations.AddOrUpdate(key, configuration, (k, v) => configuration);
_configurations.AddOrUpdate(key, configuration, (_, _) => configuration);

var path = GetConfigurationFile(key);
Directory.CreateDirectory(Path.GetDirectoryName(path));
Expand Down
24 changes: 1 addition & 23 deletions Emby.Server.Implementations/Data/SqliteItemRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,6 @@ public class SqliteItemRepository : BaseSqliteRepository, IItemRepository
typeof(AggregateFolder)
};

private readonly Dictionary<string, string> _types = GetTypeMapDictionary();

private static readonly Dictionary<BaseItemKind, string> _baseItemKindNames = new()
{
{ BaseItemKind.AggregateFolder, typeof(AggregateFolder).FullName },
Expand Down Expand Up @@ -3440,11 +3438,6 @@ private bool IsAlphaNumeric(string str)
return true;
}

private bool IsValidType(string value)
{
return IsAlphaNumeric(value);
}

private bool IsValidMediaType(string value)
{
return IsAlphaNumeric(value);
Expand Down Expand Up @@ -4711,7 +4704,7 @@ private List<string> GetWhereClauses(InternalItemsQuery query, IStatement statem
if (statement == null)
{
int index = 0;
string excludedTags = string.Join(',', query.ExcludeInheritedTags.Select(t => paramName + index++));
string excludedTags = string.Join(',', query.ExcludeInheritedTags.Select(_ => paramName + index++));
whereClauses.Add("((select CleanValue from itemvalues where ItemId=Guid and Type=6 and cleanvalue in (" + excludedTags + ")) is null)");
}
else
Expand Down Expand Up @@ -4968,21 +4961,6 @@ FROM AncestorIds
}
}

private static Dictionary<string, string> GetTypeMapDictionary()
{
var dict = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

foreach (var t in _knownTypes)
{
dict[t.Name] = t.FullName;
}

dict["Program"] = typeof(LiveTvProgram).FullName;
dict["TvChannel"] = typeof(LiveTvChannel).FullName;

return dict;
}

public void DeleteItem(Guid id)
{
if (id == Guid.Empty)
Expand Down
2 changes: 1 addition & 1 deletion Emby.Server.Implementations/Devices/DeviceId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private string GetCachedId()
{
var value = File.ReadAllText(CachePath, Encoding.UTF8);

if (Guid.TryParse(value, out var guid))
if (Guid.TryParse(value, out _))
{
return value;
}
Expand Down
Loading

0 comments on commit ea8f40e

Please sign in to comment.