aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs')
-rw-r--r--Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs92
1 files changed, 30 insertions, 62 deletions
diff --git a/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs b/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs
index b981ad81a..3f7914d3b 100644
--- a/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs
+++ b/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs
@@ -74,10 +74,7 @@ namespace Emby.Server.Implementations.LiveTv.Listings
public async Task<IEnumerable<ProgramInfo>> GetProgramsAsync(ListingsProviderInfo info, string channelId, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken)
{
- if (string.IsNullOrEmpty(channelId))
- {
- throw new ArgumentNullException(nameof(channelId));
- }
+ ArgumentException.ThrowIfNullOrEmpty(channelId);
// Normalize incoming input
channelId = channelId.Replace(".json.schedulesdirect.org", string.Empty, StringComparison.OrdinalIgnoreCase).TrimStart('I');
@@ -111,7 +108,7 @@ namespace Emby.Server.Implementations.LiveTv.Listings
using var response = await Send(options, true, info, cancellationToken).ConfigureAwait(false);
await using var responseStream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
var dailySchedules = await JsonSerializer.DeserializeAsync<IReadOnlyList<DayDto>>(responseStream, _jsonOptions, cancellationToken).ConfigureAwait(false);
- if (dailySchedules == null)
+ if (dailySchedules is null)
{
return Array.Empty<ProgramInfo>();
}
@@ -127,7 +124,7 @@ namespace Emby.Server.Implementations.LiveTv.Listings
using var innerResponse = await Send(programRequestOptions, true, info, cancellationToken).ConfigureAwait(false);
await using var innerResponseStream = await innerResponse.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
var programDetails = await JsonSerializer.DeserializeAsync<IReadOnlyList<ProgramDetailsDto>>(innerResponseStream, _jsonOptions, cancellationToken).ConfigureAwait(false);
- if (programDetails == null)
+ if (programDetails is null)
{
return Array.Empty<ProgramInfo>();
}
@@ -153,7 +150,7 @@ namespace Emby.Server.Implementations.LiveTv.Listings
continue;
}
- if (images != null)
+ if (images is not null)
{
var imageIndex = images.FindIndex(i => i.ProgramId == schedule.ProgramId[..10]);
if (imageIndex > -1)
@@ -228,7 +225,7 @@ namespace Emby.Server.Implementations.LiveTv.Listings
private ProgramInfo GetProgram(string channelId, ProgramDto programInfo, ProgramDetailsDto details)
{
- if (programInfo.AirDateTime == null)
+ if (programInfo.AirDateTime is null)
{
return null;
}
@@ -266,7 +263,7 @@ namespace Emby.Server.Implementations.LiveTv.Listings
}
string episodeTitle = null;
- if (details.EpisodeTitle150 != null)
+ if (details.EpisodeTitle150 is not null)
{
episodeTitle = details.EpisodeTitle150;
}
@@ -283,7 +280,7 @@ namespace Emby.Server.Implementations.LiveTv.Listings
EpisodeTitle = episodeTitle,
Audio = audioType,
// IsNew = programInfo.@new ?? false,
- IsRepeat = programInfo.New == null,
+ IsRepeat = programInfo.New is null,
IsSeries = string.Equals(details.EntityType, "episode", StringComparison.OrdinalIgnoreCase),
ImageUrl = details.PrimaryImage,
ThumbImageUrl = details.ThumbImage,
@@ -315,13 +312,13 @@ namespace Emby.Server.Implementations.LiveTv.Listings
info.ShowId = showId;
- if (programInfo.VideoProperties != null)
+ if (programInfo.VideoProperties is not null)
{
info.IsHD = programInfo.VideoProperties.Contains("hdtv", StringComparison.OrdinalIgnoreCase);
info.Is3D = programInfo.VideoProperties.Contains("3d", StringComparison.OrdinalIgnoreCase);
}
- if (details.ContentRating != null && details.ContentRating.Count > 0)
+ if (details.ContentRating is not null && details.ContentRating.Count > 0)
{
info.OfficialRating = details.ContentRating[0].Code.Replace("TV", "TV-", StringComparison.Ordinal)
.Replace("--", "-", StringComparison.Ordinal);
@@ -333,13 +330,13 @@ namespace Emby.Server.Implementations.LiveTv.Listings
}
}
- if (details.Descriptions != null)
+ if (details.Descriptions is not null)
{
- if (details.Descriptions.Description1000 != null && details.Descriptions.Description1000.Count > 0)
+ if (details.Descriptions.Description1000 is not null && details.Descriptions.Description1000.Count > 0)
{
info.Overview = details.Descriptions.Description1000[0].Description;
}
- else if (details.Descriptions.Description100 != null && details.Descriptions.Description100.Count > 0)
+ else if (details.Descriptions.Description100 is not null && details.Descriptions.Description100.Count > 0)
{
info.Overview = details.Descriptions.Description100[0].Description;
}
@@ -351,12 +348,12 @@ namespace Emby.Server.Implementations.LiveTv.Listings
info.SeriesProviderIds[MetadataProvider.Zap2It.ToString()] = info.SeriesId;
- if (details.Metadata != null)
+ if (details.Metadata is not null)
{
foreach (var metadataProgram in details.Metadata)
{
var gracenote = metadataProgram.Gracenote;
- if (gracenote != null)
+ if (gracenote is not null)
{
info.SeasonNumber = gracenote.Season;
@@ -371,13 +368,13 @@ namespace Emby.Server.Implementations.LiveTv.Listings
}
}
- if (details.OriginalAirDate != null)
+ if (details.OriginalAirDate is not null)
{
info.OriginalAirDate = details.OriginalAirDate;
info.ProductionYear = info.OriginalAirDate.Value.Year;
}
- if (details.Movie != null)
+ if (details.Movie is not null)
{
if (!string.IsNullOrEmpty(details.Movie.Year)
&& int.TryParse(details.Movie.Year, out int year))
@@ -386,7 +383,7 @@ namespace Emby.Server.Implementations.LiveTv.Listings
}
}
- if (details.Genres != null)
+ if (details.Genres is not null)
{
info.Genres = details.Genres.Where(g => !string.IsNullOrWhiteSpace(g)).ToList();
info.IsNews = details.Genres.Contains("news", StringComparison.OrdinalIgnoreCase);
@@ -407,7 +404,7 @@ namespace Emby.Server.Implementations.LiveTv.Listings
.ThenByDescending(i => GetSizeOrder(i))
.FirstOrDefault();
- if (match == null)
+ if (match is null)
{
return null;
}
@@ -518,7 +515,7 @@ namespace Emby.Server.Implementations.LiveTv.Listings
var root = await JsonSerializer.DeserializeAsync<IReadOnlyList<HeadendsDto>>(response, _jsonOptions, cancellationToken).ConfigureAwait(false);
- if (root != null)
+ if (root is not null)
{
foreach (HeadendsDto headend in root)
{
@@ -670,15 +667,8 @@ namespace Emby.Server.Implementations.LiveTv.Listings
{
var token = await GetToken(info, cancellationToken).ConfigureAwait(false);
- if (string.IsNullOrEmpty(token))
- {
- throw new ArgumentException("Authentication required.");
- }
-
- if (string.IsNullOrEmpty(info.ListingsId))
- {
- throw new ArgumentException("Listings Id required");
- }
+ ArgumentException.ThrowIfNullOrEmpty(token);
+ ArgumentException.ThrowIfNullOrEmpty(info.ListingsId);
_logger.LogInformation("Adding new LineUp ");
@@ -689,17 +679,11 @@ namespace Emby.Server.Implementations.LiveTv.Listings
private async Task<bool> HasLineup(ListingsProviderInfo info, CancellationToken cancellationToken)
{
- if (string.IsNullOrEmpty(info.ListingsId))
- {
- throw new ArgumentException("Listings Id required");
- }
+ ArgumentException.ThrowIfNullOrEmpty(info.ListingsId);
var token = await GetToken(info, cancellationToken).ConfigureAwait(false);
- if (string.IsNullOrEmpty(token))
- {
- throw new ArgumentException("token required");
- }
+ ArgumentException.ThrowIfNullOrEmpty(token);
_logger.LogInformation("Headends on account ");
@@ -732,23 +716,13 @@ namespace Emby.Server.Implementations.LiveTv.Listings
{
if (validateLogin)
{
- if (string.IsNullOrEmpty(info.Username))
- {
- throw new ArgumentException("Username is required");
- }
-
- if (string.IsNullOrEmpty(info.Password))
- {
- throw new ArgumentException("Password is required");
- }
+ ArgumentException.ThrowIfNullOrEmpty(info.Username);
+ ArgumentException.ThrowIfNullOrEmpty(info.Password);
}
if (validateListings)
{
- if (string.IsNullOrEmpty(info.ListingsId))
- {
- throw new ArgumentException("Listings Id required");
- }
+ ArgumentException.ThrowIfNullOrEmpty(info.ListingsId);
var hasLineup = await HasLineup(info, CancellationToken.None).ConfigureAwait(false);
@@ -767,17 +741,11 @@ namespace Emby.Server.Implementations.LiveTv.Listings
public async Task<List<ChannelInfo>> GetChannels(ListingsProviderInfo info, CancellationToken cancellationToken)
{
var listingsId = info.ListingsId;
- if (string.IsNullOrEmpty(listingsId))
- {
- throw new ArgumentException("ListingsId required");
- }
+ ArgumentException.ThrowIfNullOrEmpty(listingsId);
var token = await GetToken(info, cancellationToken).ConfigureAwait(false);
- if (string.IsNullOrEmpty(token))
- {
- throw new ArgumentException("token required");
- }
+ ArgumentException.ThrowIfNullOrEmpty(token);
using var options = new HttpRequestMessage(HttpMethod.Get, ApiUrl + "/lineups/" + listingsId);
options.Headers.TryAddWithoutValidation("token", token);
@@ -785,7 +753,7 @@ namespace Emby.Server.Implementations.LiveTv.Listings
using var httpResponse = await Send(options, true, info, cancellationToken).ConfigureAwait(false);
await using var stream = await httpResponse.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
var root = await JsonSerializer.DeserializeAsync<ChannelDto>(stream, _jsonOptions, cancellationToken).ConfigureAwait(false);
- if (root == null)
+ if (root is null)
{
return new List<ChannelInfo>();
}
@@ -814,7 +782,7 @@ namespace Emby.Server.Implementations.LiveTv.Listings
Name = string.IsNullOrWhiteSpace(station.Name) ? channelNumber : station.Name
};
- if (station.Logo != null)
+ if (station.Logo is not null)
{
channelInfo.ImageUrl = station.Logo.Url;
}