diff options
| author | LogicalPhallacy <44458166+LogicalPhallacy@users.noreply.github.com> | 2019-01-23 00:31:35 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-01-23 00:31:35 -0800 |
| commit | 404bd04cbc17dc8c8bf4a5c9aa3ca9c5cd85aa68 (patch) | |
| tree | 3d267c6ceef9439a034c113095e10e4d619e7c70 /Emby.Server.Implementations/LiveTv/TunerHosts | |
| parent | 8ff89fdc0c30f595a171ffc550f907ef22b6212a (diff) | |
| parent | e05e002b8bb4d13eb2b80b56a0aad8903ddb701e (diff) | |
Merge pull request #8 from jellyfin/master
rebase to latest master
Diffstat (limited to 'Emby.Server.Implementations/LiveTv/TunerHosts')
8 files changed, 115 insertions, 213 deletions
diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/BaseTunerHost.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/BaseTunerHost.cs index ef2010ba6..ee86f66e6 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/BaseTunerHost.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/BaseTunerHost.cs @@ -1,8 +1,3 @@ -using MediaBrowser.Common.Configuration; -using MediaBrowser.Controller.LiveTv; -using MediaBrowser.Model.Dto; -using MediaBrowser.Model.LiveTv; -using Microsoft.Extensions.Logging; using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -10,13 +5,16 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; -using MediaBrowser.Common.Extensions; +using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.LiveTv; using MediaBrowser.Controller.MediaEncoding; -using MediaBrowser.Model.Dlna; +using MediaBrowser.Model.Dto; using MediaBrowser.Model.IO; +using MediaBrowser.Model.LiveTv; using MediaBrowser.Model.Serialization; -using MediaBrowser.Controller.Library; +using Microsoft.Extensions.Logging; namespace Emby.Server.Implementations.LiveTv.TunerHosts { @@ -40,13 +38,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts FileSystem = fileSystem; } - public virtual bool IsSupported - { - get - { - return true; - } - } + public virtual bool IsSupported => true; protected abstract Task<List<ChannelInfo>> GetChannelsInternal(TunerHostInfo tuner, CancellationToken cancellationToken); public abstract string Type { get; } @@ -140,7 +132,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts { if (string.IsNullOrEmpty(channelId)) { - throw new ArgumentNullException("channelId"); + throw new ArgumentNullException(nameof(channelId)); } if (IsValidChannelId(channelId)) @@ -175,7 +167,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts { if (string.IsNullOrEmpty(channelId)) { - throw new ArgumentNullException("channelId"); + throw new ArgumentNullException(nameof(channelId)); } if (!IsValidChannelId(channelId)) @@ -228,18 +220,13 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts throw new LiveTvConflictException(); } - protected virtual string ChannelIdPrefix - { - get - { - return Type + "_"; - } - } + protected virtual string ChannelIdPrefix => Type + "_"; + protected virtual bool IsValidChannelId(string channelId) { if (string.IsNullOrEmpty(channelId)) { - throw new ArgumentNullException("channelId"); + throw new ArgumentNullException(nameof(channelId)); } return channelId.StartsWith(ChannelIdPrefix, StringComparison.OrdinalIgnoreCase); diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs index be090df0c..e8e4bc723 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs @@ -1,27 +1,27 @@ -using MediaBrowser.Common.Configuration; -using MediaBrowser.Common.Net; -using MediaBrowser.Controller.LiveTv; -using MediaBrowser.Model.Dto; -using MediaBrowser.Model.Entities; -using MediaBrowser.Model.LiveTv; -using Microsoft.Extensions.Logging; -using MediaBrowser.Model.MediaInfo; -using MediaBrowser.Model.Serialization; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; -using MediaBrowser.Model.IO; +using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Extensions; +using MediaBrowser.Common.Net; using MediaBrowser.Controller; using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.LiveTv; using MediaBrowser.Controller.MediaEncoding; using MediaBrowser.Model.Configuration; +using MediaBrowser.Model.Dto; +using MediaBrowser.Model.Entities; +using MediaBrowser.Model.IO; +using MediaBrowser.Model.LiveTv; +using MediaBrowser.Model.MediaInfo; using MediaBrowser.Model.Net; +using MediaBrowser.Model.Serialization; using MediaBrowser.Model.System; -using MediaBrowser.Controller.Library; +using Microsoft.Extensions.Logging; namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun { @@ -42,28 +42,13 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun _environment = environment; } - public string Name - { - get { return "HD Homerun"; } - } + public string Name => "HD Homerun"; - public override string Type - { - get { return DeviceType; } - } + public override string Type => DeviceType; - public static string DeviceType - { - get { return "hdhomerun"; } - } + public static string DeviceType => "hdhomerun"; - protected override string ChannelIdPrefix - { - get - { - return "hdhr_"; - } - } + protected override string ChannelIdPrefix => "hdhr_"; private string GetChannelId(TunerHostInfo info, Channels i) { @@ -133,8 +118,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun { if (!string.IsNullOrEmpty(cacheKey)) { - DiscoverResponse response; - if (_modelCache.TryGetValue(cacheKey, out response)) + if (_modelCache.TryGetValue(cacheKey, out DiscoverResponse response)) { return response; } @@ -274,10 +258,10 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun for (int i = 0; i < model.TunerCount; ++i) { - var name = String.Format("Tuner {0}", i + 1); - var currentChannel = "none"; /// @todo Get current channel and map back to Station Id + var name = string.Format("Tuner {0}", i + 1); + var currentChannel = "none"; /// @todo Get current channel and map back to Station Id var isAvailable = await manager.CheckTunerAvailability(ipInfo, i, cancellationToken).ConfigureAwait(false); - LiveTvTunerStatus status = isAvailable ? LiveTvTunerStatus.Available : LiveTvTunerStatus.LiveTv; + var status = isAvailable ? LiveTvTunerStatus.Available : LiveTvTunerStatus.LiveTv; tuners.Add(new LiveTvTunerInfo { Name = name, @@ -325,7 +309,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun return await GetTunerInfosHttp(info, cancellationToken).ConfigureAwait(false); } - private string GetApiUrl(TunerHostInfo info) + private static string GetApiUrl(TunerHostInfo info) { var url = info.Url; @@ -359,7 +343,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun return Config.GetConfiguration<EncodingOptions>("encoding"); } - private string GetHdHrIdFromChannelId(string channelId) + private static string GetHdHrIdFromChannelId(string channelId) { return channelId.Split('_')[1]; } diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunManager.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunManager.cs index 0e84622bd..2205c0ecc 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunManager.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunManager.cs @@ -1,14 +1,13 @@ -using System; +using System; using System.Collections.Generic; -using System.Linq; +using System.Net; using System.Text; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Controller.LiveTv; using MediaBrowser.Model.Net; using Microsoft.Extensions.Logging; -using MediaBrowser.Controller.LiveTv; -using System.Net; namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun { @@ -37,10 +36,10 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun { var commands = new List<Tuple<string, string>>(); - if (!String.IsNullOrEmpty(_channel)) + if (!string.IsNullOrEmpty(_channel)) commands.Add(Tuple.Create("channel", _channel)); - if (!String.IsNullOrEmpty(_program)) + if (!string.IsNullOrEmpty(_program)) commands.Add(Tuple.Create("program", _program)); return commands; } @@ -61,11 +60,11 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun { var commands = new List<Tuple<string, string>>(); - if (!String.IsNullOrEmpty(_channel)) + if (!string.IsNullOrEmpty(_channel)) { if (!string.IsNullOrEmpty(_profile) && !string.Equals(_profile, "native", StringComparison.OrdinalIgnoreCase)) { - commands.Add(Tuple.Create("vchannel", String.Format("{0} transcode={1}", _channel, _profile))); + commands.Add(Tuple.Create("vchannel", string.Format("{0} transcode={1}", _channel, _profile))); } else { @@ -123,7 +122,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun } } - private async Task<bool> CheckTunerAvailability(ISocket socket, IpAddressInfo remoteIp, int tuner, CancellationToken cancellationToken) + private static async Task<bool> CheckTunerAvailability(ISocket socket, IpAddressInfo remoteIp, int tuner, CancellationToken cancellationToken) { var ipEndPoint = new IpEndPointInfo(remoteIp, HdHomeRunPort); @@ -133,8 +132,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun var receiveBuffer = new byte[8192]; var response = await socket.ReceiveAsync(receiveBuffer, 0, receiveBuffer.Length, cancellationToken).ConfigureAwait(false); - string returnVal; - ParseReturnMessage(response.Buffer, response.ReceivedBytes, out returnVal); + ParseReturnMessage(response.Buffer, response.ReceivedBytes, out string returnVal); return string.Equals(returnVal, "none", StringComparison.OrdinalIgnoreCase); } @@ -164,13 +162,12 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun continue; _activeTuner = i; - var lockKeyString = String.Format("{0:d}", lockKeyValue); + var lockKeyString = string.Format("{0:d}", lockKeyValue); var lockkeyMsg = CreateSetMessage(i, "lockkey", lockKeyString, null); await tcpClient.SendToAsync(lockkeyMsg, 0, lockkeyMsg.Length, ipEndPoint, cancellationToken).ConfigureAwait(false); var response = await tcpClient.ReceiveAsync(receiveBuffer, 0, receiveBuffer.Length, cancellationToken).ConfigureAwait(false); - string returnVal; // parse response to make sure it worked - if (!ParseReturnMessage(response.Buffer, response.ReceivedBytes, out returnVal)) + if (!ParseReturnMessage(response.Buffer, response.ReceivedBytes, out var returnVal)) continue; var commandList = commands.GetCommands(); @@ -188,7 +185,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun } - var targetValue = String.Format("rtp://{0}:{1}", localIp, localPort); + var targetValue = string.Format("rtp://{0}:{1}", localIp, localPort); var targetMsg = CreateSetMessage(i, "target", targetValue, lockKeyValue); await tcpClient.SendToAsync(targetMsg, 0, targetMsg.Length, ipEndPoint, cancellationToken).ConfigureAwait(false); @@ -223,8 +220,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun await tcpClient.SendToAsync(channelMsg, 0, channelMsg.Length, new IpEndPointInfo(_remoteIp, HdHomeRunPort), cancellationToken).ConfigureAwait(false); var response = await tcpClient.ReceiveAsync(receiveBuffer, 0, receiveBuffer.Length, cancellationToken).ConfigureAwait(false); // parse response to make sure it worked - string returnVal; - if (!ParseReturnMessage(response.Buffer, response.ReceivedBytes, out returnVal)) + if (!ParseReturnMessage(response.Buffer, response.ReceivedBytes, out string returnVal)) { return; } @@ -262,7 +258,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun private static byte[] CreateGetMessage(int tuner, string name) { - var byteName = Encoding.UTF8.GetBytes(String.Format("/tuner{0}/{1}\0", tuner, name)); + var byteName = Encoding.UTF8.GetBytes(string.Format("/tuner{0}/{1}\0", tuner, name)); int messageLength = byteName.Length + 10; // 4 bytes for header + 4 bytes for crc + 2 bytes for tag name and length var message = new byte[messageLength]; @@ -280,10 +276,10 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun return message; } - private static byte[] CreateSetMessage(int tuner, String name, String value, uint? lockkey) + private static byte[] CreateSetMessage(int tuner, string name, string value, uint? lockkey) { - var byteName = Encoding.UTF8.GetBytes(String.Format("/tuner{0}/{1}\0", tuner, name)); - var byteValue = Encoding.UTF8.GetBytes(String.Format("{0}\0", value)); + var byteName = Encoding.UTF8.GetBytes(string.Format("/tuner{0}/{1}\0", tuner, name)); + var byteValue = Encoding.UTF8.GetBytes(string.Format("{0}\0", value)); int messageLength = byteName.Length + byteValue.Length + 12; if (lockkey.HasValue) @@ -360,7 +356,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun private static bool ParseReturnMessage(byte[] buf, int numBytes, out string returnVal) { - returnVal = String.Empty; + returnVal = string.Empty; if (numBytes < 4) return false; @@ -411,7 +407,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun private class HdHomerunCrc { - private static UInt32[] crc_table = { + private static uint[] crc_table = { 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, @@ -477,7 +473,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d }; - public static UInt32 GetCrc32(byte[] bytes, int numBytes) + public static uint GetCrc32(byte[] bytes, int numBytes) { var hash = 0xffffffff; for (var i = 0; i < numBytes; i++) diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunUdpStream.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunUdpStream.cs index c781bccbb..2542ddd2a 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunUdpStream.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunUdpStream.cs @@ -1,5 +1,8 @@ -using System; +using System; +using System.Collections.Generic; using System.IO; +using System.Net; +using System.Net.Sockets; using System.Threading; using System.Threading.Tasks; using MediaBrowser.Common.Net; @@ -7,13 +10,9 @@ using MediaBrowser.Controller; using MediaBrowser.Controller.Library; using MediaBrowser.Model.Dto; using MediaBrowser.Model.IO; -using Microsoft.Extensions.Logging; -using MediaBrowser.Model.MediaInfo; -using MediaBrowser.Model.System; using MediaBrowser.Model.LiveTv; -using System.Collections.Generic; -using System.Net.Sockets; -using System.Net; +using MediaBrowser.Model.MediaInfo; +using Microsoft.Extensions.Logging; namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun { @@ -38,7 +37,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun EnableStreamSharing = true; } - private Socket CreateSocket(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType) + private static Socket CreateSocket(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType) { var socket = new Socket(addressFamily, SocketType.Stream, ProtocolType.Tcp); @@ -144,7 +143,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun }); } - private void Resolve(TaskCompletionSource<bool> openTaskCompletionSource) + private static void Resolve(TaskCompletionSource<bool> openTaskCompletionSource) { Task.Run(() => { @@ -204,16 +203,16 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun public override async Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { if (buffer == null) - throw new ArgumentNullException("buffer"); + throw new ArgumentNullException(nameof(buffer)); if (offset + count < 0) - throw new ArgumentOutOfRangeException("offset + count must not be negative", "offset+count"); + throw new ArgumentOutOfRangeException(nameof(offset), "offset + count must not be negative"); if (offset + count > buffer.Length) - throw new ArgumentException("offset + count must not be greater than the length of buffer", "offset+count"); + throw new ArgumentException("offset + count must not be greater than the length of buffer"); if (disposed) - throw new ObjectDisposedException(typeof(UdpClientStream).ToString()); + throw new ObjectDisposedException(nameof(UdpClientStream)); // This will always receive a 1328 packet size (PacketSize + RtpHeaderSize) // The RTP header will be stripped so see how many reads we need to make to fill the buffer. @@ -238,16 +237,16 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun public override int Read(byte[] buffer, int offset, int count) { if (buffer == null) - throw new ArgumentNullException("buffer"); + throw new ArgumentNullException(nameof(buffer)); if (offset + count < 0) throw new ArgumentOutOfRangeException("offset + count must not be negative", "offset+count"); if (offset + count > buffer.Length) - throw new ArgumentException("offset + count must not be greater than the length of buffer", "offset+count"); + throw new ArgumentException("offset + count must not be greater than the length of buffer"); if (disposed) - throw new ObjectDisposedException(typeof(UdpClientStream).ToString()); + throw new ObjectDisposedException(nameof(UdpClientStream)); // This will always receive a 1328 packet size (PacketSize + RtpHeaderSize) // The RTP header will be stripped so see how many reads we need to make to fill the buffer. @@ -274,49 +273,19 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun disposed = true; } - public override bool CanRead - { - get - { - throw new NotImplementedException(); - } - } + public override bool CanRead => throw new NotImplementedException(); - public override bool CanSeek - { - get - { - throw new NotImplementedException(); - } - } + public override bool CanSeek => throw new NotImplementedException(); - public override bool CanWrite - { - get - { - throw new NotImplementedException(); - } - } + public override bool CanWrite => throw new NotImplementedException(); - public override long Length - { - get - { - throw new NotImplementedException(); - } - } + public override long Length => throw new NotImplementedException(); public override long Position { - get - { - throw new NotImplementedException(); - } + get => throw new NotImplementedException(); - set - { - throw new NotImplementedException(); - } + set => throw new NotImplementedException(); } public override void Flush() diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/LiveStream.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/LiveStream.cs index 4a2b4ebb2..1f8ca276e 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/LiveStream.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/LiveStream.cs @@ -1,18 +1,15 @@ -using System; +using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Threading; using System.Threading.Tasks; using MediaBrowser.Controller; -using MediaBrowser.Controller.IO; -using MediaBrowser.Controller.LiveTv; +using MediaBrowser.Controller.Library; using MediaBrowser.Model.Dto; using MediaBrowser.Model.IO; -using Microsoft.Extensions.Logging; -using MediaBrowser.Model.System; using MediaBrowser.Model.LiveTv; -using System.Linq; -using MediaBrowser.Controller.Library; +using Microsoft.Extensions.Logging; namespace Emby.Server.Implementations.LiveTv.TunerHosts { @@ -217,13 +214,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts } } - protected virtual int EmptyReadLimit - { - get - { - return 1000; - } - } + protected virtual int EmptyReadLimit => 1000; private void TrySeek(FileStream stream, long offset) { diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs index a54bd1613..638796e2e 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs @@ -1,24 +1,24 @@ -using MediaBrowser.Common.Extensions; -using MediaBrowser.Controller.LiveTv; -using MediaBrowser.Model.Dto; -using MediaBrowser.Model.Entities; -using MediaBrowser.Model.LiveTv; -using Microsoft.Extensions.Logging; -using MediaBrowser.Model.MediaInfo; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; -using MediaBrowser.Model.IO; +using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Net; using MediaBrowser.Controller; using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.LiveTv; using MediaBrowser.Controller.MediaEncoding; +using MediaBrowser.Model.Dto; +using MediaBrowser.Model.Entities; +using MediaBrowser.Model.IO; +using MediaBrowser.Model.LiveTv; +using MediaBrowser.Model.MediaInfo; using MediaBrowser.Model.Serialization; using MediaBrowser.Model.System; -using System.IO; -using MediaBrowser.Controller.Library; +using Microsoft.Extensions.Logging; namespace Emby.Server.Implementations.LiveTv.TunerHosts { @@ -39,15 +39,9 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts _mediaSourceManager = mediaSourceManager; } - public override string Type - { - get { return "m3u"; } - } + public override string Type => "m3u"; - public virtual string Name - { - get { return "M3U Tuner"; } - } + public virtual string Name => "M3U Tuner"; private string GetFullChannelIdPrefix(TunerHostInfo info) { @@ -141,9 +135,8 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts var protocol = _mediaSourceManager.GetPathProtocol(path); - Uri uri; var isRemote = true; - if (Uri.TryCreate(path, UriKind.Absolute, out uri)) + if (Uri.TryCreate(path, UriKind.Absolute, out var uri)) { isRemote = !_networkManager.IsInLocalNetwork(uri.Host); } diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs index 208225c1e..a54a53b25 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Globalization; using System.IO; @@ -6,14 +6,13 @@ using System.Linq; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; -using MediaBrowser.Model.IO; using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Net; using MediaBrowser.Controller; -using MediaBrowser.Controller.IO; using MediaBrowser.Controller.LiveTv; -using Microsoft.Extensions.Logging; using MediaBrowser.Model.Extensions; +using MediaBrowser.Model.IO; +using Microsoft.Extensions.Logging; namespace Emby.Server.Implementations.LiveTv.TunerHosts { @@ -59,7 +58,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts Url = url, CancellationToken = cancellationToken, // Some data providers will require a user agent - UserAgent = _appHost.FriendlyName + "/" + _appHost.ApplicationVersion + UserAgent = _appHost.ApplicationUserAgent }); } return Task.FromResult(_fileSystem.OpenRead(url)); @@ -118,12 +117,10 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts extInf = extInf.Trim(); - string remaining; - var attributes = ParseExtInf(extInf, out remaining); + var attributes = ParseExtInf(extInf, out string remaining); extInf = remaining; - string value; - if (attributes.TryGetValue("tvg-logo", out value)) + if (attributes.TryGetValue("tvg-logo", out string value)) { channel.ImageUrl = value; } @@ -131,11 +128,9 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts channel.Name = GetChannelName(extInf, attributes); channel.Number = GetChannelNumber(extInf, attributes, mediaUrl); - string tvgId; - attributes.TryGetValue("tvg-id", out tvgId); + attributes.TryGetValue("tvg-id", out string tvgId); - string channelId; - attributes.TryGetValue("channel-id", out channelId); + attributes.TryGetValue("channel-id", out string channelId); channel.TunerChannelId = string.IsNullOrWhiteSpace(tvgId) ? channelId : tvgId; @@ -173,8 +168,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts { var numberPart = nameInExtInf.Substring(0, numberIndex).Trim(new[] { ' ', '.' }); - double number; - if (double.TryParse(numberPart, NumberStyles.Any, CultureInfo.InvariantCulture, out number)) + if (double.TryParse(numberPart, NumberStyles.Any, CultureInfo.InvariantCulture, out var number)) { numberString = numberPart; } @@ -188,11 +182,9 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts if (!IsValidChannelNumber(numberString)) { - string value; - if (attributes.TryGetValue("tvg-id", out value)) + if (attributes.TryGetValue("tvg-id", out string value)) { - double doubleValue; - if (double.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out doubleValue)) + if (double.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var doubleValue)) { numberString = value; } @@ -206,8 +198,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts if (!IsValidChannelNumber(numberString)) { - string value; - if (attributes.TryGetValue("channel-id", out value)) + if (attributes.TryGetValue("channel-id", out string value)) { numberString = value; } @@ -251,7 +242,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts return numberString; } - private bool IsValidChannelNumber(string numberString) + private static bool IsValidChannelNumber(string numberString) { if (string.IsNullOrWhiteSpace(numberString) || string.Equals(numberString, "-1", StringComparison.OrdinalIgnoreCase) || @@ -260,8 +251,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts return false; } - double value; - if (!double.TryParse(numberString, NumberStyles.Any, CultureInfo.InvariantCulture, out value)) + if (!double.TryParse(numberString, NumberStyles.Any, CultureInfo.InvariantCulture, out var value)) { return false; } @@ -269,7 +259,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts return true; } - private string GetChannelName(string extInf, Dictionary<string, string> attributes) + private static string GetChannelName(string extInf, Dictionary<string, string> attributes) { var nameParts = extInf.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); var nameInExtInf = nameParts.Length > 1 ? nameParts.Last().Trim() : null; @@ -284,8 +274,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts { var numberPart = nameInExtInf.Substring(0, numberIndex).Trim(new[] { ' ', '.' }); - double number; - if (double.TryParse(numberPart, NumberStyles.Any, CultureInfo.InvariantCulture, out number)) + if (double.TryParse(numberPart, NumberStyles.Any, CultureInfo.InvariantCulture, out var number)) { //channel.Number = number.ToString(); nameInExtInf = nameInExtInf.Substring(numberIndex + 1).Trim(new[] { ' ', '-' }); @@ -293,8 +282,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts } } - string name; - attributes.TryGetValue("tvg-name", out name); + attributes.TryGetValue("tvg-name", out string name); if (string.IsNullOrWhiteSpace(name)) { @@ -314,7 +302,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts return name; } - private Dictionary<string, string> ParseExtInf(string line, out string remaining) + private static Dictionary<string, string> ParseExtInf(string line, out string remaining) { var dict = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/SharedHttpStream.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/SharedHttpStream.cs index 9b10daba0..b39a9f679 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/SharedHttpStream.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/SharedHttpStream.cs @@ -1,21 +1,15 @@ -using System; -using System.IO; +using System; +using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using Emby.Server.Implementations.IO; -using MediaBrowser.Model.IO; using MediaBrowser.Common.Net; using MediaBrowser.Controller; -using MediaBrowser.Controller.LiveTv; using MediaBrowser.Controller.Library; using MediaBrowser.Model.Dto; -using Microsoft.Extensions.Logging; -using MediaBrowser.Model.MediaInfo; -using MediaBrowser.Model.System; -using System.Globalization; -using MediaBrowser.Controller.IO; +using MediaBrowser.Model.IO; using MediaBrowser.Model.LiveTv; -using System.Collections.Generic; +using MediaBrowser.Model.MediaInfo; +using Microsoft.Extensions.Logging; namespace Emby.Server.Implementations.LiveTv.TunerHosts { |
