Simplify/remove/clean code

* Remove useless runtime check (we only support one)
* Remove unused args
* Remove a global constant

And ofc fix some warnings ;)
This commit is contained in:
Bond-009
2019-03-25 22:25:32 +01:00
parent 5024c52c60
commit b44a70ff36
14 changed files with 50 additions and 73 deletions

View File

@@ -261,7 +261,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
public string HomePageUrl => "https://github.com/jellyfin/jellyfin";
public async Task RefreshSeriesTimers(CancellationToken cancellationToken, IProgress<double> progress)
public async Task RefreshSeriesTimers(CancellationToken cancellationToken)
{
var seriesTimers = await GetSeriesTimersAsync(cancellationToken).ConfigureAwait(false);
@@ -271,7 +271,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
}
}
public async Task RefreshTimers(CancellationToken cancellationToken, IProgress<double> progress)
public async Task RefreshTimers(CancellationToken cancellationToken)
{
var timers = await GetTimersAsync(cancellationToken).ConfigureAwait(false);

View File

@@ -1087,8 +1087,8 @@ namespace Emby.Server.Implementations.LiveTv
if (coreService != null)
{
await coreService.RefreshSeriesTimers(cancellationToken, new SimpleProgress<double>()).ConfigureAwait(false);
await coreService.RefreshTimers(cancellationToken, new SimpleProgress<double>()).ConfigureAwait(false);
await coreService.RefreshSeriesTimers(cancellationToken).ConfigureAwait(false);
await coreService.RefreshTimers(cancellationToken).ConfigureAwait(false);
}
// Load these now which will prefetch metadata

View File

@@ -10,14 +10,12 @@ 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 Microsoft.Extensions.Logging;
using Microsoft.Net.Http.Headers;
@@ -52,9 +50,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
{
var channelIdPrefix = GetFullChannelIdPrefix(info);
var result = await new M3uParser(Logger, _httpClient, _appHost).Parse(info.Url, channelIdPrefix, info.Id, cancellationToken).ConfigureAwait(false);
return result.Cast<ChannelInfo>().ToList();
return await new M3uParser(Logger, _httpClient, _appHost).Parse(info.Url, channelIdPrefix, info.Id, cancellationToken).ConfigureAwait(false);
}
public Task<List<LiveTvTunerInfo>> GetTunerInfos(CancellationToken cancellationToken)
@@ -73,7 +69,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
return Task.FromResult(list);
}
private string[] _disallowedSharedStreamExtensions = new string[]
private static readonly string[] _disallowedSharedStreamExtensions = new string[]
{
".mkv",
".mp4",
@@ -88,9 +84,9 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
if (tunerCount > 0)
{
var tunerHostId = info.Id;
var liveStreams = currentLiveStreams.Where(i => string.Equals(i.TunerHostId, tunerHostId, StringComparison.OrdinalIgnoreCase)).ToList();
var liveStreams = currentLiveStreams.Where(i => string.Equals(i.TunerHostId, tunerHostId, StringComparison.OrdinalIgnoreCase));
if (liveStreams.Count >= tunerCount)
if (liveStreams.Count() >= tunerCount)
{
throw new LiveTvConflictException("M3U simultaneous stream limit has been reached.");
}
@@ -98,7 +94,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
var sources = await GetChannelStreamMediaSources(info, channelInfo, cancellationToken).ConfigureAwait(false);
var mediaSource = sources.First();
var mediaSource = sources[0];
if (mediaSource.Protocol == MediaProtocol.Http && !mediaSource.RequiresLooping)
{

View File

@@ -11,7 +11,6 @@ using MediaBrowser.Common.Net;
using MediaBrowser.Controller;
using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.IO;
using Microsoft.Extensions.Logging;
namespace Emby.Server.Implementations.LiveTv.TunerHosts
@@ -62,12 +61,13 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
return Task.FromResult((Stream)File.OpenRead(url));
}
const string ExtInfPrefix = "#EXTINF:";
private const string ExtInfPrefix = "#EXTINF:";
private List<ChannelInfo> GetChannels(TextReader reader, string channelIdPrefix, string tunerHostId)
{
var channels = new List<ChannelInfo>();
string line;
string extInf = "";
string extInf = string.Empty;
while ((line = reader.ReadLine()) != null)
{
@@ -101,7 +101,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
channel.Path = line;
channels.Add(channel);
extInf = "";
extInf = string.Empty;
}
}
@@ -110,8 +110,10 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
private ChannelInfo GetChannelnfo(string extInf, string tunerHostId, string mediaUrl)
{
var channel = new ChannelInfo();
channel.TunerHostId = tunerHostId;
var channel = new ChannelInfo()
{
TunerHostId = tunerHostId
};
extInf = extInf.Trim();
@@ -137,13 +139,15 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
{
channelIdValues.Add(channelId);
}
if (!string.IsNullOrWhiteSpace(tvgId))
{
channelIdValues.Add(tvgId);
}
if (channelIdValues.Count > 0)
{
channel.Id = string.Join("_", channelIdValues.ToArray());
channel.Id = string.Join("_", channelIdValues);
}
return channel;
@@ -152,7 +156,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
private string GetChannelNumber(string extInf, Dictionary<string, string> attributes, string mediaUrl)
{
var nameParts = extInf.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
var nameInExtInf = nameParts.Length > 1 ? nameParts.Last().Trim() : null;
var nameInExtInf = nameParts.Length > 1 ? nameParts[nameParts.Length - 1].Trim() : null;
string numberString = null;
string attributeValue;