Minor improvements

This commit is contained in:
Bond_009 2020-12-02 15:38:52 +01:00
parent 3b4f86579b
commit e4fd61411f
15 changed files with 48 additions and 75 deletions

View File

@ -1681,7 +1681,6 @@ namespace Emby.Dlna.ContentDirectory
private ServerItem GetItemFromObjectId(string id) private ServerItem GetItemFromObjectId(string id)
{ {
return DidlBuilder.IsIdRoot(id) return DidlBuilder.IsIdRoot(id)
? new ServerItem(_libraryManager.GetUserRootFolder()) ? new ServerItem(_libraryManager.GetUserRootFolder())
: ParseItemId(id); : ParseItemId(id);
} }

View File

@ -1,6 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using Emby.Dlna.Common; using Emby.Dlna.Common;
using MediaBrowser.Model.Dlna;
namespace Emby.Dlna.MediaReceiverRegistrar namespace Emby.Dlna.MediaReceiverRegistrar
{ {

View File

@ -12,8 +12,6 @@ using System.Xml;
using System.Xml.Linq; using System.Xml.Linq;
using Emby.Dlna.Common; using Emby.Dlna.Common;
using Emby.Dlna.Ssdp; using Emby.Dlna.Ssdp;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Emby.Dlna.PlayTo namespace Emby.Dlna.PlayTo
@ -345,7 +343,7 @@ namespace Emby.Dlna.PlayTo
RestartTimer(true); RestartTimer(true);
} }
private string CreateDidlMeta(string value) private static string CreateDidlMeta(string value)
{ {
if (string.IsNullOrEmpty(value)) if (string.IsNullOrEmpty(value))
{ {
@ -962,7 +960,7 @@ namespace Emby.Dlna.PlayTo
url = "/dmr/" + url; url = "/dmr/" + url;
} }
if (!url.StartsWith("/", StringComparison.Ordinal)) if (!url.StartsWith('/'))
{ {
url = "/" + url; url = "/" + url;
} }

View File

@ -9,7 +9,6 @@ using System.Threading.Tasks;
using Emby.Dlna.Didl; using Emby.Dlna.Didl;
using Jellyfin.Data.Entities; using Jellyfin.Data.Entities;
using Jellyfin.Data.Events; using Jellyfin.Data.Events;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Dlna; using MediaBrowser.Controller.Dlna;
using MediaBrowser.Controller.Drawing; using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
@ -41,7 +40,6 @@ namespace Emby.Dlna.PlayTo
private readonly IUserDataManager _userDataManager; private readonly IUserDataManager _userDataManager;
private readonly ILocalizationManager _localization; private readonly ILocalizationManager _localization;
private readonly IMediaSourceManager _mediaSourceManager; private readonly IMediaSourceManager _mediaSourceManager;
private readonly IConfigurationManager _config;
private readonly IMediaEncoder _mediaEncoder; private readonly IMediaEncoder _mediaEncoder;
private readonly IDeviceDiscovery _deviceDiscovery; private readonly IDeviceDiscovery _deviceDiscovery;
@ -68,7 +66,6 @@ namespace Emby.Dlna.PlayTo
IUserDataManager userDataManager, IUserDataManager userDataManager,
ILocalizationManager localization, ILocalizationManager localization,
IMediaSourceManager mediaSourceManager, IMediaSourceManager mediaSourceManager,
IConfigurationManager config,
IMediaEncoder mediaEncoder) IMediaEncoder mediaEncoder)
{ {
_session = session; _session = session;
@ -84,7 +81,6 @@ namespace Emby.Dlna.PlayTo
_userDataManager = userDataManager; _userDataManager = userDataManager;
_localization = localization; _localization = localization;
_mediaSourceManager = mediaSourceManager; _mediaSourceManager = mediaSourceManager;
_config = config;
_mediaEncoder = mediaEncoder; _mediaEncoder = mediaEncoder;
} }
@ -337,25 +333,17 @@ namespace Emby.Dlna.PlayTo
} }
var startIndex = command.StartIndex ?? 0; var startIndex = command.StartIndex ?? 0;
int len = items.Count - startIndex;
if (startIndex > 0) if (startIndex > 0)
{ {
items = items.GetRange(startIndex, items.Count - startIndex); items = items.GetRange(startIndex, len);
} }
var playlist = new List<PlaylistItem>(); var playlist = new PlaylistItem[len];
var isFirst = true; playlist[0] = CreatePlaylistItem(items[0], user, command.StartPositionTicks.Value, command.MediaSourceId, command.AudioStreamIndex, command.SubtitleStreamIndex);
for (int i = 1; i < len; i++)
foreach (var item in items)
{ {
if (isFirst && command.StartPositionTicks.HasValue) playlist[i] = CreatePlaylistItem(items[i], user, 0, null, null, null);
{
playlist.Add(CreatePlaylistItem(item, user, command.StartPositionTicks.Value, command.MediaSourceId, command.AudioStreamIndex, command.SubtitleStreamIndex));
isFirst = false;
}
else
{
playlist.Add(CreatePlaylistItem(item, user, 0, null, null, null));
}
} }
_logger.LogDebug("{0} - Playlist created", _session.DeviceName); _logger.LogDebug("{0} - Playlist created", _session.DeviceName);
@ -468,8 +456,8 @@ namespace Emby.Dlna.PlayTo
_dlnaManager.GetDefaultProfile(); _dlnaManager.GetDefaultProfile();
var mediaSources = item is IHasMediaSources var mediaSources = item is IHasMediaSources
? _mediaSourceManager.GetStaticMediaSources(item, true, user) ? _mediaSourceManager.GetStaticMediaSources(item, true, user).ToArray()
: new List<MediaSourceInfo>(); : Array.Empty<MediaSourceInfo>();
var playlistItem = GetPlaylistItem(item, mediaSources, profile, _session.DeviceId, mediaSourceId, audioStreamIndex, subtitleStreamIndex); var playlistItem = GetPlaylistItem(item, mediaSources, profile, _session.DeviceId, mediaSourceId, audioStreamIndex, subtitleStreamIndex);
playlistItem.StreamInfo.StartPositionTicks = startPostionTicks; playlistItem.StreamInfo.StartPositionTicks = startPostionTicks;
@ -548,7 +536,7 @@ namespace Emby.Dlna.PlayTo
return null; return null;
} }
private PlaylistItem GetPlaylistItem(BaseItem item, List<MediaSourceInfo> mediaSources, DeviceProfile profile, string deviceId, string mediaSourceId, int? audioStreamIndex, int? subtitleStreamIndex) private PlaylistItem GetPlaylistItem(BaseItem item, MediaSourceInfo[] mediaSources, DeviceProfile profile, string deviceId, string mediaSourceId, int? audioStreamIndex, int? subtitleStreamIndex)
{ {
if (string.Equals(item.MediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase)) if (string.Equals(item.MediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase))
{ {
@ -557,7 +545,7 @@ namespace Emby.Dlna.PlayTo
StreamInfo = new StreamBuilder(_mediaEncoder, _logger).BuildVideoItem(new VideoOptions StreamInfo = new StreamBuilder(_mediaEncoder, _logger).BuildVideoItem(new VideoOptions
{ {
ItemId = item.Id, ItemId = item.Id,
MediaSources = mediaSources.ToArray(), MediaSources = mediaSources,
Profile = profile, Profile = profile,
DeviceId = deviceId, DeviceId = deviceId,
MaxBitrate = profile.MaxStreamingBitrate, MaxBitrate = profile.MaxStreamingBitrate,
@ -577,7 +565,7 @@ namespace Emby.Dlna.PlayTo
StreamInfo = new StreamBuilder(_mediaEncoder, _logger).BuildAudioItem(new AudioOptions StreamInfo = new StreamBuilder(_mediaEncoder, _logger).BuildAudioItem(new AudioOptions
{ {
ItemId = item.Id, ItemId = item.Id,
MediaSources = mediaSources.ToArray(), MediaSources = mediaSources,
Profile = profile, Profile = profile,
DeviceId = deviceId, DeviceId = deviceId,
MaxBitrate = profile.MaxStreamingBitrate, MaxBitrate = profile.MaxStreamingBitrate,
@ -590,7 +578,7 @@ namespace Emby.Dlna.PlayTo
if (string.Equals(item.MediaType, MediaType.Photo, StringComparison.OrdinalIgnoreCase)) if (string.Equals(item.MediaType, MediaType.Photo, StringComparison.OrdinalIgnoreCase))
{ {
return new PlaylistItemFactory().Create((Photo)item, profile); return PlaylistItemFactory.Create((Photo)item, profile);
} }
throw new ArgumentException("Unrecognized item type."); throw new ArgumentException("Unrecognized item type.");
@ -774,13 +762,14 @@ namespace Emby.Dlna.PlayTo
private async Task SeekAfterTransportChange(long positionTicks, CancellationToken cancellationToken) private async Task SeekAfterTransportChange(long positionTicks, CancellationToken cancellationToken)
{ {
const int maxWait = 15000000; const int MaxWait = 15000000;
const int interval = 500; const int Interval = 500;
var currentWait = 0; var currentWait = 0;
while (_device.TransportState != TransportState.Playing && currentWait < maxWait) while (_device.TransportState != TransportState.Playing && currentWait < MaxWait)
{ {
await Task.Delay(interval).ConfigureAwait(false); await Task.Delay(Interval).ConfigureAwait(false);
currentWait += interval; currentWait += Interval;
} }
await _device.Seek(TimeSpan.FromTicks(positionTicks), cancellationToken).ConfigureAwait(false); await _device.Seek(TimeSpan.FromTicks(positionTicks), cancellationToken).ConfigureAwait(false);

View File

@ -90,10 +90,10 @@ namespace Emby.Dlna.PlayTo
string location = info.Location.ToString(); string location = info.Location.ToString();
// It has to report that it's a media renderer // It has to report that it's a media renderer
if (usn.IndexOf("MediaRenderer:", StringComparison.OrdinalIgnoreCase) == -1 && if (!usn.Contains("MediaRenderer:", StringComparison.OrdinalIgnoreCase)
nt.IndexOf("MediaRenderer:", StringComparison.OrdinalIgnoreCase) == -1) && !nt.Contains("MediaRenderer:", StringComparison.OrdinalIgnoreCase))
{ {
// _logger.LogDebug("Upnp device {0} does not contain a MediaRenderer device (0).", location); _logger.LogDebug("Upnp device {0} does not contain a MediaRenderer device (0).", location);
return; return;
} }
@ -203,7 +203,6 @@ namespace Emby.Dlna.PlayTo
_userDataManager, _userDataManager,
_localization, _localization,
_mediaSourceManager, _mediaSourceManager,
_config,
_mediaEncoder); _mediaEncoder);
sessionInfo.AddController(controller); sessionInfo.AddController(controller);

View File

@ -8,9 +8,9 @@ using MediaBrowser.Model.Session;
namespace Emby.Dlna.PlayTo namespace Emby.Dlna.PlayTo
{ {
public class PlaylistItemFactory public static class PlaylistItemFactory
{ {
public PlaylistItem Create(Photo item, DeviceProfile profile) public static PlaylistItem Create(Photo item, DeviceProfile profile)
{ {
var playlistItem = new PlaylistItem var playlistItem = new PlaylistItem
{ {

View File

@ -4,7 +4,6 @@ using System;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using System.Net.Http; using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.Mime; using System.Net.Mime;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
@ -60,7 +59,7 @@ namespace Emby.Dlna.PlayTo
return serviceUrl; return serviceUrl;
} }
if (!serviceUrl.StartsWith("/", StringComparison.Ordinal)) if (!serviceUrl.StartsWith('/'))
{ {
serviceUrl = "/" + serviceUrl; serviceUrl = "/" + serviceUrl;
} }

View File

@ -78,7 +78,7 @@ namespace Emby.Dlna.PlayTo
private static StateVariable FromXml(XElement container) private static StateVariable FromXml(XElement container)
{ {
var allowedValues = new List<string>(); var allowedValues = Array.Empty<string>();
var element = container.Descendants(UPnpNamespaces.Svc + "allowedValueList") var element = container.Descendants(UPnpNamespaces.Svc + "allowedValueList")
.FirstOrDefault(); .FirstOrDefault();
@ -86,14 +86,14 @@ namespace Emby.Dlna.PlayTo
{ {
var values = element.Descendants(UPnpNamespaces.Svc + "allowedValue"); var values = element.Descendants(UPnpNamespaces.Svc + "allowedValue");
allowedValues.AddRange(values.Select(child => child.Value)); allowedValues = values.Select(child => child.Value).ToArray();
} }
return new StateVariable return new StateVariable
{ {
Name = container.GetValue(UPnpNamespaces.Svc + "name"), Name = container.GetValue(UPnpNamespaces.Svc + "name"),
DataType = container.GetValue(UPnpNamespaces.Svc + "dataType"), DataType = container.GetValue(UPnpNamespaces.Svc + "dataType"),
AllowedValues = allowedValues.ToArray() AllowedValues = allowedValues
}; };
} }
@ -103,12 +103,12 @@ namespace Emby.Dlna.PlayTo
foreach (var arg in action.ArgumentList) foreach (var arg in action.ArgumentList)
{ {
if (arg.Direction == "out") if (string.Equals(arg.Direction, "out", StringComparison.Ordinal))
{ {
continue; continue;
} }
if (arg.Name == "InstanceID") if (string.Equals(arg.Name, "InstanceID", StringComparison.Ordinal))
{ {
stateString += BuildArgumentXml(arg, "0"); stateString += BuildArgumentXml(arg, "0");
} }
@ -127,12 +127,12 @@ namespace Emby.Dlna.PlayTo
foreach (var arg in action.ArgumentList) foreach (var arg in action.ArgumentList)
{ {
if (arg.Direction == "out") if (string.Equals(arg.Direction, "out", StringComparison.Ordinal))
{ {
continue; continue;
} }
if (arg.Name == "InstanceID") if (string.Equals(arg.Name, "InstanceID", StringComparison.Ordinal))
{ {
stateString += BuildArgumentXml(arg, "0"); stateString += BuildArgumentXml(arg, "0");
} }
@ -151,7 +151,7 @@ namespace Emby.Dlna.PlayTo
foreach (var arg in action.ArgumentList) foreach (var arg in action.ArgumentList)
{ {
if (arg.Name == "InstanceID") if (string.Equals(arg.Name, "InstanceID", StringComparison.Ordinal))
{ {
stateString += BuildArgumentXml(arg, "0"); stateString += BuildArgumentXml(arg, "0");
} }

View File

@ -1,21 +1,18 @@
#pragma warning disable CS1591 #pragma warning disable CS1591
using System; using System;
using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Net.Sockets;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Serialization;
using Emby.Dlna; using Emby.Dlna;
using Emby.Dlna.Main; using Emby.Dlna.Main;
using Emby.Dlna.Ssdp; using Emby.Dlna.Ssdp;
@ -52,7 +49,6 @@ using Jellyfin.Networking.Manager;
using MediaBrowser.Common; using MediaBrowser.Common;
using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Events; using MediaBrowser.Common.Events;
using MediaBrowser.Common.Json;
using MediaBrowser.Common.Net; using MediaBrowser.Common.Net;
using MediaBrowser.Common.Plugins; using MediaBrowser.Common.Plugins;
using MediaBrowser.Common.Updates; using MediaBrowser.Common.Updates;
@ -85,7 +81,6 @@ using MediaBrowser.Controller.SyncPlay;
using MediaBrowser.Controller.TV; using MediaBrowser.Controller.TV;
using MediaBrowser.LocalMetadata.Savers; using MediaBrowser.LocalMetadata.Savers;
using MediaBrowser.MediaEncoding.BdInfo; using MediaBrowser.MediaEncoding.BdInfo;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Cryptography; using MediaBrowser.Model.Cryptography;
using MediaBrowser.Model.Dlna; using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Globalization; using MediaBrowser.Model.Globalization;
@ -100,7 +95,6 @@ using MediaBrowser.Providers.Manager;
using MediaBrowser.Providers.Plugins.Tmdb; using MediaBrowser.Providers.Plugins.Tmdb;
using MediaBrowser.Providers.Subtitles; using MediaBrowser.Providers.Subtitles;
using MediaBrowser.XbmcMetadata.Providers; using MediaBrowser.XbmcMetadata.Providers;
using Microsoft.AspNetCore.DataProtection.Repositories;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
@ -128,7 +122,6 @@ namespace Emby.Server.Implementations
private IMediaEncoder _mediaEncoder; private IMediaEncoder _mediaEncoder;
private ISessionManager _sessionManager; private ISessionManager _sessionManager;
private IHttpClientFactory _httpClientFactory;
private string[] _urlPrefixes; private string[] _urlPrefixes;
/// <summary> /// <summary>
@ -661,7 +654,6 @@ namespace Emby.Server.Implementations
_mediaEncoder = Resolve<IMediaEncoder>(); _mediaEncoder = Resolve<IMediaEncoder>();
_sessionManager = Resolve<ISessionManager>(); _sessionManager = Resolve<ISessionManager>();
_httpClientFactory = Resolve<IHttpClientFactory>();
((AuthenticationRepository)Resolve<IAuthenticationRepository>()).Initialize(); ((AuthenticationRepository)Resolve<IAuthenticationRepository>()).Initialize();
@ -1049,7 +1041,7 @@ namespace Emby.Server.Implementations
metafile = dir.Split(Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries)[^1]; metafile = dir.Split(Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries)[^1];
int versionIndex = dir.LastIndexOf('_'); int versionIndex = dir.LastIndexOf('_');
if (versionIndex != -1 && Version.TryParse(dir.Substring(versionIndex + 1), out Version parsedVersion)) if (versionIndex != -1 && Version.TryParse(dir.AsSpan()[(versionIndex + 1)..], out Version parsedVersion))
{ {
// Versioned folder. // Versioned folder.
versions.Add(new LocalPlugin(Guid.Empty, metafile, parsedVersion, dir)); versions.Add(new LocalPlugin(Guid.Empty, metafile, parsedVersion, dir));

View File

@ -237,8 +237,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
if (!inside) if (!inside)
{ {
buffer[bufferIndex] = let; buffer[bufferIndex++] = let;
bufferIndex++;
} }
} }

View File

@ -95,7 +95,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
extInf = line.Substring(ExtInfPrefix.Length).Trim(); extInf = line.Substring(ExtInfPrefix.Length).Trim();
_logger.LogInformation("Found m3u channel: {0}", extInf); _logger.LogInformation("Found m3u channel: {0}", extInf);
} }
else if (!string.IsNullOrWhiteSpace(extInf) && !line.StartsWith("#", StringComparison.OrdinalIgnoreCase)) else if (!string.IsNullOrWhiteSpace(extInf) && !line.StartsWith('#'))
{ {
var channel = GetChannelnfo(extInf, tunerHostId, line); var channel = GetChannelnfo(extInf, tunerHostId, line);
if (string.IsNullOrWhiteSpace(channel.Id)) if (string.IsNullOrWhiteSpace(channel.Id))

View File

@ -256,7 +256,7 @@ namespace Jellyfin.Networking.Manager
} }
catch (ArgumentException e) catch (ArgumentException e)
{ {
_logger.LogWarning(e, "Ignoring LAN value {value}.", v); _logger.LogWarning(e, "Ignoring LAN value {Value}.", v);
} }
} }
@ -668,7 +668,6 @@ namespace Jellyfin.Networking.Manager
if (address.AddressFamily == AddressFamily.InterNetworkV6) if (address.AddressFamily == AddressFamily.InterNetworkV6)
{ {
int i = str.IndexOf("%", StringComparison.OrdinalIgnoreCase); int i = str.IndexOf("%", StringComparison.OrdinalIgnoreCase);
if (i != -1) if (i != -1)
{ {
str = str.Substring(0, i); str = str.Substring(0, i);

View File

@ -51,7 +51,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
{ {
eventsStarted = true; eventsStarted = true;
} }
else if (!string.IsNullOrEmpty(line) && line.Trim().StartsWith(";", StringComparison.Ordinal)) else if (!string.IsNullOrEmpty(line) && line.Trim().StartsWith(';'))
{ {
// skip comment lines // skip comment lines
} }
@ -151,13 +151,13 @@ namespace MediaBrowser.MediaEncoding.Subtitles
try try
{ {
var p = new SubtitleTrackEvent(); trackEvents.Add(
new SubtitleTrackEvent
p.StartPositionTicks = GetTimeCodeFromString(start); {
p.EndPositionTicks = GetTimeCodeFromString(end); StartPositionTicks = GetTimeCodeFromString(start),
p.Text = GetFormattedText(text); EndPositionTicks = GetTimeCodeFromString(end),
Text = GetFormattedText(text)
trackEvents.Add(p); });
} }
catch catch
{ {

View File

@ -47,7 +47,7 @@ namespace MediaBrowser.Model.Dlna
public static bool ContainsContainer(string profileContainers, string inputContainer) public static bool ContainsContainer(string profileContainers, string inputContainer)
{ {
var isNegativeList = false; var isNegativeList = false;
if (profileContainers != null && profileContainers.StartsWith("-", StringComparison.Ordinal)) if (profileContainers != null && profileContainers.StartsWith('-'))
{ {
isNegativeList = true; isNegativeList = true;
profileContainers = profileContainers.Substring(1); profileContainers = profileContainers.Substring(1);

View File

@ -203,7 +203,7 @@ namespace MediaBrowser.Providers.MediaInfo
{ {
item.ShortcutPath = File.ReadAllLines(item.Path) item.ShortcutPath = File.ReadAllLines(item.Path)
.Select(NormalizeStrmLine) .Select(NormalizeStrmLine)
.FirstOrDefault(i => !string.IsNullOrWhiteSpace(i) && !i.StartsWith("#", StringComparison.OrdinalIgnoreCase)); .FirstOrDefault(i => !string.IsNullOrWhiteSpace(i) && !i.StartsWith('#'));
} }
public Task<ItemUpdateType> FetchAudioInfo<T>(T item, MetadataRefreshOptions options, CancellationToken cancellationToken) public Task<ItemUpdateType> FetchAudioInfo<T>(T item, MetadataRefreshOptions options, CancellationToken cancellationToken)