jellyfin/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs

1221 lines
43 KiB
C#
Raw Normal View History

#pragma warning disable CS1591
2015-07-21 06:22:46 +02:00
using System;
2015-07-23 07:25:55 +02:00
using System.Collections.Concurrent;
2015-07-21 06:22:46 +02:00
using System.Collections.Generic;
2015-07-23 07:25:55 +02:00
using System.Globalization;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Mime;
using System.Text;
using System.Text.Json;
2015-07-21 06:22:46 +02:00
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common;
using MediaBrowser.Common.Json;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Model.Cryptography;
using MediaBrowser.Model.Dto;
2018-09-12 19:26:21 +02:00
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.LiveTv;
using Microsoft.Extensions.Logging;
2015-07-21 06:22:46 +02:00
2016-11-04 00:35:19 +01:00
namespace Emby.Server.Implementations.LiveTv.Listings
2015-07-21 06:22:46 +02:00
{
2015-08-15 20:46:57 +02:00
public class SchedulesDirect : IListingsProvider
2015-07-21 06:22:46 +02:00
{
2020-08-31 22:20:19 +02:00
private const string ApiUrl = "https://json.schedulesdirect.org/20141201";
2020-06-06 02:15:56 +02:00
private readonly ILogger<SchedulesDirect> _logger;
private readonly IHttpClientFactory _httpClientFactory;
2015-07-23 07:25:55 +02:00
private readonly SemaphoreSlim _tokenSemaphore = new SemaphoreSlim(1, 1);
2015-07-29 22:31:15 +02:00
private readonly IApplicationHost _appHost;
private readonly ICryptoProvider _cryptoProvider;
2015-07-23 07:25:55 +02:00
2020-11-26 21:54:14 +01:00
private readonly ConcurrentDictionary<string, NameValuePair> _tokens = new ConcurrentDictionary<string, NameValuePair>();
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions();
2021-02-13 00:39:18 +01:00
private DateTime _lastErrorResponse;
2020-11-26 21:54:14 +01:00
public SchedulesDirect(
ILogger<SchedulesDirect> logger,
IHttpClientFactory httpClientFactory,
IApplicationHost appHost,
ICryptoProvider cryptoProvider)
2015-07-23 07:25:55 +02:00
{
_logger = logger;
_httpClientFactory = httpClientFactory;
2015-07-29 22:31:15 +02:00
_appHost = appHost;
_cryptoProvider = cryptoProvider;
2015-07-29 22:31:15 +02:00
}
2019-09-20 12:42:08 +02:00
/// <inheritdoc />
public string Name => "Schedules Direct";
/// <inheritdoc />
public string Type => nameof(SchedulesDirect);
private static List<string> GetScheduleRequestDates(DateTime startDateUtc, DateTime endDateUtc)
2015-07-29 19:16:00 +02:00
{
2019-01-13 21:37:13 +01:00
var dates = new List<string>();
2015-07-29 19:16:00 +02:00
2015-11-12 03:25:12 +01:00
var start = new List<DateTime> { startDateUtc, startDateUtc.ToLocalTime() }.Min().Date;
var end = new List<DateTime> { endDateUtc, endDateUtc.ToLocalTime() }.Max().Date;
2015-07-29 19:16:00 +02:00
2015-11-12 03:25:12 +01:00
while (start <= end)
2015-07-29 19:16:00 +02:00
{
2020-08-31 22:20:19 +02:00
dates.Add(start.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture));
2015-07-29 19:16:00 +02:00
start = start.AddDays(1);
}
return dates;
}
2017-02-05 00:32:16 +01:00
public async Task<IEnumerable<ProgramInfo>> GetProgramsAsync(ListingsProviderInfo info, string channelId, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken)
2015-07-23 07:25:55 +02:00
{
2018-09-12 19:26:21 +02:00
if (string.IsNullOrEmpty(channelId))
2017-02-05 00:32:16 +01:00
{
throw new ArgumentNullException(nameof(channelId));
2017-02-05 00:32:16 +01:00
}
// Normalize incoming input
channelId = channelId.Replace(".json.schedulesdirect.org", string.Empty, StringComparison.OrdinalIgnoreCase).TrimStart('I');
2015-09-01 21:18:25 +02:00
var token = await GetToken(info, cancellationToken).ConfigureAwait(false);
2015-07-23 07:25:55 +02:00
2018-09-12 19:26:21 +02:00
if (string.IsNullOrEmpty(token))
2015-07-23 07:25:55 +02:00
{
_logger.LogWarning("SchedulesDirect token is empty, returning empty program list");
return Enumerable.Empty<ProgramInfo>();
2015-07-23 07:25:55 +02:00
}
2015-07-29 19:16:00 +02:00
var dates = GetScheduleRequestDates(startDateUtc, endDateUtc);
2015-07-23 07:25:55 +02:00
_logger.LogInformation("Channel Station ID is: {ChannelID}", channelId);
var requestList = new List<ScheduleDirect.RequestScheduleForChannel>()
{
new ScheduleDirect.RequestScheduleForChannel()
2015-07-23 07:25:55 +02:00
{
stationID = channelId,
date = dates
}
};
2015-07-23 07:25:55 +02:00
var requestString = JsonSerializer.Serialize(requestList, _jsonOptions);
_logger.LogDebug("Request string for schedules is: {RequestString}", requestString);
2016-03-17 20:29:53 +01:00
using var options = new HttpRequestMessage(HttpMethod.Post, ApiUrl + "/schedules");
options.Content = new StringContent(requestString, Encoding.UTF8, MediaTypeNames.Application.Json);
options.Headers.TryAddWithoutValidation("token", token);
using var response = await Send(options, true, info, cancellationToken).ConfigureAwait(false);
2020-11-17 19:43:00 +01:00
await using var responseStream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
2021-02-15 14:19:08 +01:00
var dailySchedules = await JsonSerializer.DeserializeAsync<List<ScheduleDirect.Day>>(responseStream, _jsonOptions, cancellationToken).ConfigureAwait(false);
_logger.LogDebug("Found {ScheduleCount} programs on {ChannelID} ScheduleDirect", dailySchedules.Count, channelId);
2016-03-17 20:29:53 +01:00
using var programRequestOptions = new HttpRequestMessage(HttpMethod.Post, ApiUrl + "/programs");
programRequestOptions.Headers.TryAddWithoutValidation("token", token);
2015-07-23 07:25:55 +02:00
var programsID = dailySchedules.SelectMany(d => d.programs.Select(s => s.programID)).Distinct();
programRequestOptions.Content = new StringContent("[\"" + string.Join("\", \"", programsID) + "\"]", Encoding.UTF8, MediaTypeNames.Application.Json);
2015-07-23 07:25:55 +02:00
using var innerResponse = await Send(programRequestOptions, true, info, cancellationToken).ConfigureAwait(false);
2020-11-17 19:43:00 +01:00
await using var innerResponseStream = await innerResponse.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
2021-02-15 14:19:08 +01:00
var programDetails = await JsonSerializer.DeserializeAsync<List<ScheduleDirect.ProgramDetails>>(innerResponseStream, _jsonOptions, cancellationToken).ConfigureAwait(false);
var programDict = programDetails.ToDictionary(p => p.programID, y => y);
2017-06-11 22:40:25 +02:00
2021-02-15 14:19:08 +01:00
var programIdsWithImages = programDetails
.Where(p => p.hasImageArtwork).Select(p => p.programID)
.ToList();
2015-07-23 07:25:55 +02:00
var images = await GetImageForPrograms(info, programIdsWithImages, cancellationToken).ConfigureAwait(false);
2017-02-09 04:58:04 +01:00
var programsInfo = new List<ProgramInfo>();
foreach (ScheduleDirect.Program schedule in dailySchedules.SelectMany(d => d.programs))
{
// _logger.LogDebug("Proccesing Schedule for statio ID " + stationID +
// " which corresponds to channel " + channelNumber + " and program id " +
// schedule.programID + " which says it has images? " +
// programDict[schedule.programID].hasImageArtwork);
2015-07-23 07:25:55 +02:00
if (images != null)
{
var imageIndex = images.FindIndex(i => i.programID == schedule.programID.Substring(0, 10));
if (imageIndex > -1)
2015-07-23 07:25:55 +02:00
{
var programEntry = programDict[schedule.programID];
2017-06-11 22:40:25 +02:00
var allImages = images[imageIndex].data ?? new List<ScheduleDirect.ImageData>();
var imagesWithText = allImages.Where(i => string.Equals(i.text, "yes", StringComparison.OrdinalIgnoreCase));
var imagesWithoutText = allImages.Where(i => string.Equals(i.text, "no", StringComparison.OrdinalIgnoreCase));
2017-06-11 22:40:25 +02:00
const double DesiredAspect = 2.0 / 3;
programEntry.primaryImage = GetProgramImage(ApiUrl, imagesWithText, true, DesiredAspect) ??
GetProgramImage(ApiUrl, allImages, true, DesiredAspect);
2017-06-11 22:40:25 +02:00
const double WideAspect = 16.0 / 9;
2016-09-11 09:33:53 +02:00
programEntry.thumbImage = GetProgramImage(ApiUrl, imagesWithText, true, WideAspect);
2017-06-11 23:58:49 +02:00
// Don't supply the same image twice
if (string.Equals(programEntry.primaryImage, programEntry.thumbImage, StringComparison.Ordinal))
{
programEntry.thumbImage = null;
2015-07-23 07:25:55 +02:00
}
programEntry.backdropImage = GetProgramImage(ApiUrl, imagesWithoutText, true, WideAspect);
2019-09-20 12:42:08 +02:00
// programEntry.bannerImage = GetProgramImage(ApiUrl, data, "Banner", false) ??
// GetProgramImage(ApiUrl, data, "Banner-L1", false) ??
// GetProgramImage(ApiUrl, data, "Banner-LO", false) ??
// GetProgramImage(ApiUrl, data, "Banner-LOT", false);
}
2015-07-23 07:25:55 +02:00
}
programsInfo.Add(GetProgram(channelId, schedule, programDict[schedule.programID]));
2015-07-23 07:25:55 +02:00
}
return programsInfo;
2015-07-23 07:25:55 +02:00
}
private static int GetSizeOrder(ScheduleDirect.ImageData image)
2016-09-11 09:33:53 +02:00
{
2021-02-15 14:19:08 +01:00
if (int.TryParse(image.height, out int value))
2016-09-11 09:33:53 +02:00
{
2019-09-20 12:42:08 +02:00
return value;
2016-09-11 09:33:53 +02:00
}
return 0;
}
private static string GetChannelNumber(ScheduleDirect.Map map)
2015-10-11 02:39:30 +02:00
{
2017-02-05 00:32:16 +01:00
var channelNumber = map.logicalChannelNumber;
2016-09-09 08:59:23 +02:00
2017-02-05 00:32:16 +01:00
if (string.IsNullOrWhiteSpace(channelNumber))
2015-10-11 02:39:30 +02:00
{
2017-02-05 00:32:16 +01:00
channelNumber = map.channel;
2015-10-11 02:39:30 +02:00
}
2020-06-15 23:43:52 +02:00
2017-02-05 00:32:16 +01:00
if (string.IsNullOrWhiteSpace(channelNumber))
2016-03-17 20:29:53 +01:00
{
2017-02-05 00:32:16 +01:00
channelNumber = map.atscMajor + "." + map.atscMinor;
2016-03-17 20:29:53 +01:00
}
2015-10-11 02:39:30 +02:00
return channelNumber.TrimStart('0');
2015-10-11 02:39:30 +02:00
}
private static bool IsMovie(ScheduleDirect.ProgramDetails programInfo)
2017-06-11 22:40:25 +02:00
{
2017-06-21 16:51:11 +02:00
return string.Equals(programInfo.entityType, "movie", StringComparison.OrdinalIgnoreCase);
2017-06-11 22:40:25 +02:00
}
2017-02-05 00:32:16 +01:00
private ProgramInfo GetProgram(string channelId, ScheduleDirect.Program programInfo, ScheduleDirect.ProgramDetails details)
2015-07-23 07:25:55 +02:00
{
2019-01-13 21:37:13 +01:00
var startAt = GetDate(programInfo.airDateTime);
var endAt = startAt.AddSeconds(programInfo.duration);
var audioType = ProgramAudio.Stereo;
2015-08-19 08:12:58 +02:00
2017-08-23 18:49:42 +02:00
var programId = programInfo.programID ?? string.Empty;
string newID = programId + "T" + startAt.Ticks + "C" + channelId;
2015-07-23 07:25:55 +02:00
if (programInfo.audioProperties != null)
{
2016-09-08 22:32:30 +02:00
if (programInfo.audioProperties.Exists(item => string.Equals(item, "atmos", StringComparison.OrdinalIgnoreCase)))
{
audioType = ProgramAudio.Atmos;
}
else if (programInfo.audioProperties.Exists(item => string.Equals(item, "dd 5.1", StringComparison.OrdinalIgnoreCase)))
2015-07-29 19:16:00 +02:00
{
audioType = ProgramAudio.DolbyDigital;
}
else if (programInfo.audioProperties.Exists(item => string.Equals(item, "dd", StringComparison.OrdinalIgnoreCase)))
{
audioType = ProgramAudio.DolbyDigital;
}
else if (programInfo.audioProperties.Exists(item => string.Equals(item, "stereo", StringComparison.OrdinalIgnoreCase)))
2015-07-23 07:25:55 +02:00
{
audioType = ProgramAudio.Stereo;
}
else
{
audioType = ProgramAudio.Mono;
}
}
2015-08-04 16:26:36 +02:00
string episodeTitle = null;
2015-07-23 07:25:55 +02:00
if (details.episodeTitle150 != null)
{
2015-08-19 08:12:58 +02:00
episodeTitle = details.episodeTitle150;
2015-07-23 07:25:55 +02:00
}
2015-08-04 16:26:36 +02:00
2015-07-23 07:25:55 +02:00
var info = new ProgramInfo
{
2017-02-05 00:32:16 +01:00
ChannelId = channelId,
2015-07-23 07:25:55 +02:00
Id = newID,
StartDate = startAt,
EndDate = endAt,
2020-11-18 14:23:45 +01:00
Name = details.titles[0].title120 ?? "Unknown",
2015-08-16 20:37:53 +02:00
OfficialRating = null,
2015-07-23 07:25:55 +02:00
CommunityRating = null,
2015-08-04 16:26:36 +02:00
EpisodeTitle = episodeTitle,
2015-07-23 07:25:55 +02:00
Audio = audioType,
2020-06-14 11:11:11 +02:00
// IsNew = programInfo.@new ?? false,
2018-09-12 19:26:21 +02:00
IsRepeat = programInfo.@new == null,
2017-06-21 16:51:11 +02:00
IsSeries = string.Equals(details.entityType, "episode", StringComparison.OrdinalIgnoreCase),
2016-09-11 09:33:53 +02:00
ImageUrl = details.primaryImage,
2017-06-11 22:40:25 +02:00
ThumbImageUrl = details.thumbImage,
2015-08-19 08:12:58 +02:00
IsKids = string.Equals(details.audience, "children", StringComparison.OrdinalIgnoreCase),
2017-06-21 16:51:11 +02:00
IsSports = string.Equals(details.entityType, "sports", StringComparison.OrdinalIgnoreCase),
2017-06-11 22:40:25 +02:00
IsMovie = IsMovie(details),
2018-09-12 19:26:21 +02:00
Etag = programInfo.md5,
IsLive = string.Equals(programInfo.liveTapeDelay, "live", StringComparison.OrdinalIgnoreCase),
IsPremiere = programInfo.premiere || (programInfo.isPremiereOrFinale ?? string.Empty).IndexOf("premiere", StringComparison.OrdinalIgnoreCase) != -1
2015-07-23 07:25:55 +02:00
};
2015-08-04 16:26:36 +02:00
2017-08-23 18:49:42 +02:00
var showId = programId;
2016-12-22 16:58:09 +01:00
2017-03-01 21:30:05 +01:00
if (!info.IsSeries)
{
// It's also a series if it starts with SH
info.IsSeries = showId.StartsWith("SH", StringComparison.OrdinalIgnoreCase) && showId.Length >= 14;
}
2016-12-22 16:58:09 +01:00
// According to SchedulesDirect, these are generic, unidentified episodes
// SH005316560000
var hasUniqueShowId = !showId.StartsWith("SH", StringComparison.OrdinalIgnoreCase) ||
!showId.EndsWith("0000", StringComparison.OrdinalIgnoreCase);
if (!hasUniqueShowId)
{
showId = newID;
}
info.ShowId = showId;
2015-08-19 08:12:58 +02:00
if (programInfo.videoProperties != null)
{
info.IsHD = programInfo.videoProperties.Contains("hdtv", StringComparer.OrdinalIgnoreCase);
2016-09-08 22:32:30 +02:00
info.Is3D = programInfo.videoProperties.Contains("3d", StringComparer.OrdinalIgnoreCase);
2015-08-19 08:12:58 +02:00
}
if (details.contentRating != null && details.contentRating.Count > 0)
{
2020-11-26 21:54:14 +01:00
info.OfficialRating = details.contentRating[0].code.Replace("TV", "TV-", StringComparison.Ordinal)
.Replace("--", "-", StringComparison.Ordinal);
2015-08-21 17:34:42 +02:00
2015-08-26 20:17:38 +02:00
var invalid = new[] { "N/A", "Approved", "Not Rated", "Passed" };
2015-08-21 17:34:42 +02:00
if (invalid.Contains(info.OfficialRating, StringComparer.OrdinalIgnoreCase))
{
info.OfficialRating = null;
}
2015-08-19 08:12:58 +02:00
}
if (details.descriptions != null)
{
2017-08-23 18:49:42 +02:00
if (details.descriptions.description1000 != null && details.descriptions.description1000.Count > 0)
2015-08-19 08:12:58 +02:00
{
info.Overview = details.descriptions.description1000[0].description;
}
2017-08-23 18:49:42 +02:00
else if (details.descriptions.description100 != null && details.descriptions.description100.Count > 0)
2015-08-19 08:12:58 +02:00
{
2017-01-26 21:27:12 +01:00
info.Overview = details.descriptions.description100[0].description;
2015-08-19 08:12:58 +02:00
}
}
2015-08-16 20:37:53 +02:00
if (info.IsSeries)
{
2017-08-23 18:49:42 +02:00
info.SeriesId = programId.Substring(0, 10);
2015-08-19 08:12:58 +02:00
2020-06-06 21:17:49 +02:00
info.SeriesProviderIds[MetadataProvider.Zap2It.ToString()] = info.SeriesId;
2018-09-12 19:26:21 +02:00
2015-08-19 08:12:58 +02:00
if (details.metadata != null)
{
2017-08-24 21:52:48 +02:00
foreach (var metadataProgram in details.metadata)
2017-03-01 21:30:05 +01:00
{
2017-08-24 21:52:48 +02:00
var gracenote = metadataProgram.Gracenote;
if (gracenote != null)
2017-08-23 18:49:42 +02:00
{
2017-08-24 21:52:48 +02:00
info.SeasonNumber = gracenote.season;
if (gracenote.episode > 0)
{
info.EpisodeNumber = gracenote.episode;
}
break;
2017-08-23 18:49:42 +02:00
}
2017-03-01 21:30:05 +01:00
}
2015-08-19 08:12:58 +02:00
}
2015-08-16 20:37:53 +02:00
}
2018-09-12 19:26:21 +02:00
if (!string.IsNullOrWhiteSpace(details.originalAirDate))
2015-07-23 07:25:55 +02:00
{
2020-08-31 22:20:19 +02:00
info.OriginalAirDate = DateTime.Parse(details.originalAirDate, CultureInfo.InvariantCulture);
2016-10-22 16:50:21 +02:00
info.ProductionYear = info.OriginalAirDate.Value.Year;
2015-07-23 07:25:55 +02:00
}
2018-09-12 19:26:21 +02:00
if (details.movie != null)
{
2020-08-31 22:20:19 +02:00
if (!string.IsNullOrEmpty(details.movie.year)
&& int.TryParse(details.movie.year, out int year))
2018-09-12 19:26:21 +02:00
{
info.ProductionYear = year;
}
}
2015-07-23 07:25:55 +02:00
if (details.genres != null)
{
info.Genres = details.genres.Where(g => !string.IsNullOrWhiteSpace(g)).ToList();
info.IsNews = details.genres.Contains("news", StringComparer.OrdinalIgnoreCase);
2015-08-19 19:58:41 +02:00
if (info.Genres.Contains("children", StringComparer.OrdinalIgnoreCase))
{
info.IsKids = true;
}
2015-07-23 07:25:55 +02:00
}
2015-08-19 08:12:58 +02:00
2015-07-23 07:25:55 +02:00
return info;
}
private static DateTime GetDate(string value)
2015-09-18 03:51:22 +02:00
{
2015-09-21 18:26:05 +02:00
var date = DateTime.ParseExact(value, "yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'", CultureInfo.InvariantCulture);
if (date.Kind != DateTimeKind.Utc)
{
date = DateTime.SpecifyKind(date, DateTimeKind.Utc);
}
2020-06-15 23:43:52 +02:00
2015-09-21 18:26:05 +02:00
return date;
2015-09-18 03:51:22 +02:00
}
private string GetProgramImage(string apiUrl, IEnumerable<ScheduleDirect.ImageData> images, bool returnDefaultImage, double desiredAspect)
2015-07-23 07:25:55 +02:00
{
var match = images
.OrderBy(i => Math.Abs(desiredAspect - GetAspectRatio(i)))
2017-06-11 22:40:25 +02:00
.ThenByDescending(GetSizeOrder)
.FirstOrDefault();
2016-09-20 17:21:44 +02:00
2016-09-16 01:19:27 +02:00
if (match == null)
{
return null;
}
var uri = match.uri;
2016-09-11 09:33:53 +02:00
if (string.IsNullOrWhiteSpace(uri))
2016-09-11 09:33:53 +02:00
{
return null;
}
else if (uri.IndexOf("http", StringComparison.OrdinalIgnoreCase) != -1)
{
return uri;
}
else
{
return apiUrl + "/image/" + uri;
2015-07-23 07:25:55 +02:00
}
}
private static double GetAspectRatio(ScheduleDirect.ImageData i)
2017-06-11 22:40:25 +02:00
{
int width = 0;
int height = 0;
if (!string.IsNullOrWhiteSpace(i.width))
{
int.TryParse(i.width, out width);
}
if (!string.IsNullOrWhiteSpace(i.height))
{
int.TryParse(i.height, out height);
}
if (height == 0 || width == 0)
{
return 0;
}
double result = width;
result /= height;
return result;
}
private async Task<List<ScheduleDirect.ShowImages>> GetImageForPrograms(
2016-06-08 23:04:52 +02:00
ListingsProviderInfo info,
2020-11-26 21:54:14 +01:00
IReadOnlyList<string> programIds,
CancellationToken cancellationToken)
2015-07-23 07:25:55 +02:00
{
2017-02-09 04:58:04 +01:00
if (programIds.Count == 0)
{
return new List<ScheduleDirect.ShowImages>();
}
2020-11-26 21:54:14 +01:00
StringBuilder str = new StringBuilder("[", 1 + (programIds.Count * 13));
foreach (ReadOnlySpan<char> i in programIds)
2015-07-23 07:25:55 +02:00
{
2020-11-26 21:54:14 +01:00
str.Append('"')
.Append(i.Slice(0, 10))
.Append("\",");
2016-11-04 00:35:19 +01:00
}
2020-11-26 21:54:14 +01:00
// Remove last ,
str.Length--;
str.Append(']');
2015-08-22 04:59:10 +02:00
2020-09-07 13:20:39 +02:00
using var message = new HttpRequestMessage(HttpMethod.Post, ApiUrl + "/metadata/programs")
{
2020-11-26 21:54:14 +01:00
Content = new StringContent(str.ToString(), Encoding.UTF8, MediaTypeNames.Application.Json)
2020-09-07 13:20:39 +02:00
};
2017-02-09 04:58:04 +01:00
try
2015-07-23 07:25:55 +02:00
{
using var innerResponse2 = await Send(message, true, info, cancellationToken).ConfigureAwait(false);
2020-11-17 19:43:00 +01:00
await using var response = await innerResponse2.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
return await JsonSerializer.DeserializeAsync<List<ScheduleDirect.ShowImages>>(response, _jsonOptions, cancellationToken).ConfigureAwait(false);
2015-07-23 07:25:55 +02:00
}
2017-02-09 04:58:04 +01:00
catch (Exception ex)
{
2018-12-20 13:11:26 +01:00
_logger.LogError(ex, "Error getting image info from schedules direct");
2015-07-23 07:25:55 +02:00
2017-02-09 04:58:04 +01:00
return new List<ScheduleDirect.ShowImages>();
}
2015-07-23 07:25:55 +02:00
}
2015-07-23 19:58:20 +02:00
public async Task<List<NameIdPair>> GetHeadends(ListingsProviderInfo info, string country, string location, CancellationToken cancellationToken)
2015-07-23 07:25:55 +02:00
{
2019-10-25 12:47:20 +02:00
var token = await GetToken(info, cancellationToken).ConfigureAwait(false);
2015-07-23 07:25:55 +02:00
var lineups = new List<NameIdPair>();
if (string.IsNullOrWhiteSpace(token))
{
return lineups;
}
using var options = new HttpRequestMessage(HttpMethod.Get, ApiUrl + "/headends?country=" + country + "&postalcode=" + location);
options.Headers.TryAddWithoutValidation("token", token);
2015-07-23 07:25:55 +02:00
try
{
using var httpResponse = await Send(options, false, info, cancellationToken).ConfigureAwait(false);
2020-11-17 19:43:00 +01:00
await using var response = await httpResponse.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
var root = await JsonSerializer.DeserializeAsync<List<ScheduleDirect.Headends>>(response, _jsonOptions, cancellationToken).ConfigureAwait(false);
2017-10-20 18:16:56 +02:00
if (root != null)
{
foreach (ScheduleDirect.Headends headend in root)
2018-12-20 13:11:26 +01:00
{
foreach (ScheduleDirect.Lineup lineup in headend.lineups)
2015-07-23 07:25:55 +02:00
{
lineups.Add(new NameIdPair
2015-07-23 07:25:55 +02:00
{
Name = string.IsNullOrWhiteSpace(lineup.name) ? lineup.lineup : lineup.name,
Id = lineup.uri.Substring(18)
});
2015-07-23 07:25:55 +02:00
}
2018-12-20 13:11:26 +01:00
}
}
else
{
_logger.LogInformation("No lineups available");
2015-07-23 07:25:55 +02:00
}
}
catch (Exception ex)
{
2018-12-20 13:11:26 +01:00
_logger.LogError(ex, "Error getting headends");
2015-07-23 07:25:55 +02:00
}
return lineups;
}
private async Task<string> GetToken(ListingsProviderInfo info, CancellationToken cancellationToken)
{
2015-07-23 15:23:22 +02:00
var username = info.Username;
2015-07-23 07:25:55 +02:00
2015-07-23 15:23:22 +02:00
// Reset the token if there's no username
if (string.IsNullOrWhiteSpace(username))
{
return null;
}
2015-07-23 07:25:55 +02:00
2015-07-23 15:23:22 +02:00
var password = info.Password;
2018-09-12 19:26:21 +02:00
if (string.IsNullOrEmpty(password))
2015-07-23 15:23:22 +02:00
{
return null;
}
2015-07-23 07:25:55 +02:00
2015-09-01 21:18:25 +02:00
// Avoid hammering SD
if ((DateTime.UtcNow - _lastErrorResponse).TotalMinutes < 1)
{
return null;
}
2020-11-26 21:54:14 +01:00
if (!_tokens.TryGetValue(username, out NameValuePair savedToken))
2015-07-23 15:23:22 +02:00
{
savedToken = new NameValuePair();
_tokens.TryAdd(username, savedToken);
}
2015-07-23 07:25:55 +02:00
2018-09-12 19:26:21 +02:00
if (!string.IsNullOrEmpty(savedToken.Name) && !string.IsNullOrEmpty(savedToken.Value))
2015-07-23 15:23:22 +02:00
{
if (long.TryParse(savedToken.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out long ticks))
2015-07-23 07:25:55 +02:00
{
2015-07-23 15:23:22 +02:00
// If it's under 24 hours old we can still use it
2016-03-27 23:11:27 +02:00
if (DateTime.UtcNow.Ticks - ticks < TimeSpan.FromHours(20).Ticks)
2015-07-23 07:25:55 +02:00
{
2015-07-23 15:23:22 +02:00
return savedToken.Name;
2015-07-23 07:25:55 +02:00
}
}
2015-07-23 15:23:22 +02:00
}
2015-07-23 07:25:55 +02:00
2015-07-23 15:23:22 +02:00
await _tokenSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false);
try
{
2015-07-23 07:25:55 +02:00
var result = await GetTokenInternal(username, password, cancellationToken).ConfigureAwait(false);
savedToken.Name = result;
savedToken.Value = DateTime.UtcNow.Ticks.ToString(CultureInfo.InvariantCulture);
return result;
}
2020-11-14 22:30:34 +01:00
catch (HttpRequestException ex)
2015-09-01 21:18:25 +02:00
{
if (ex.StatusCode.HasValue)
{
if ((int)ex.StatusCode.Value == 400)
{
_tokens.Clear();
_lastErrorResponse = DateTime.UtcNow;
}
}
2020-06-15 23:43:52 +02:00
2015-09-01 21:18:25 +02:00
throw;
}
2015-07-23 07:25:55 +02:00
finally
{
_tokenSemaphore.Release();
}
}
private async Task<HttpResponseMessage> Send(
HttpRequestMessage options,
2016-06-08 23:04:52 +02:00
bool enableRetry,
ListingsProviderInfo providerInfo,
CancellationToken cancellationToken,
HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead)
2015-11-21 04:13:03 +01:00
{
2020-12-10 16:25:05 +01:00
var response = await _httpClientFactory.CreateClient(NamedClient.Default)
.SendAsync(options, completionOption, cancellationToken).ConfigureAwait(false);
if (response.IsSuccessStatusCode)
2015-11-21 04:13:03 +01:00
{
2020-12-08 16:28:19 +01:00
return response;
2016-06-08 23:04:52 +02:00
}
2020-12-10 16:25:05 +01:00
// Response is automatically disposed in the calling function,
// so dispose manually if not returning.
response.Dispose();
if (!enableRetry || (int)response.StatusCode >= 500)
{
throw new HttpRequestException(
string.Format(CultureInfo.InvariantCulture, "Request failed: {0}", response.ReasonPhrase),
null,
response.StatusCode);
2016-06-08 23:04:52 +02:00
}
2020-12-10 16:25:05 +01:00
_tokens.Clear();
options.Headers.TryAddWithoutValidation("token", await GetToken(providerInfo, cancellationToken).ConfigureAwait(false));
return await Send(options, false, providerInfo, cancellationToken).ConfigureAwait(false);
2015-11-21 04:13:03 +01:00
}
private async Task<string> GetTokenInternal(
string username,
string password,
2015-07-23 07:25:55 +02:00
CancellationToken cancellationToken)
2015-07-21 06:22:46 +02:00
{
using var options = new HttpRequestMessage(HttpMethod.Post, ApiUrl + "/token");
var hashedPasswordBytes = _cryptoProvider.ComputeHash("SHA1", Encoding.ASCII.GetBytes(password), Array.Empty<byte>());
// TODO: remove ToLower when Convert.ToHexString supports lowercase
// Schedules Direct requires the hex to be lowercase
string hashedPassword = Convert.ToHexString(hashedPasswordBytes).ToLowerInvariant();
options.Content = new StringContent("{\"username\":\"" + username + "\",\"password\":\"" + hashedPassword + "\"}", Encoding.UTF8, MediaTypeNames.Application.Json);
2015-07-23 07:25:55 +02:00
using var response = await Send(options, false, null, cancellationToken).ConfigureAwait(false);
2020-12-08 16:28:19 +01:00
response.EnsureSuccessStatusCode();
2020-11-17 19:43:00 +01:00
await using var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
var root = await JsonSerializer.DeserializeAsync<ScheduleDirect.Token>(stream, _jsonOptions, cancellationToken).ConfigureAwait(false);
2020-11-26 21:54:14 +01:00
if (string.Equals(root.message, "OK", StringComparison.Ordinal))
2015-07-23 07:25:55 +02:00
{
_logger.LogInformation("Authenticated with Schedules Direct token: " + root.token);
return root.token;
2015-07-23 07:25:55 +02:00
}
throw new Exception("Could not authenticate with Schedules Direct Error: " + root.message);
2015-07-23 07:25:55 +02:00
}
2015-07-23 19:04:54 +02:00
private async Task AddLineupToAccount(ListingsProviderInfo info, CancellationToken cancellationToken)
{
2019-10-25 12:47:20 +02:00
var token = await GetToken(info, cancellationToken).ConfigureAwait(false);
2015-07-23 19:04:54 +02:00
2018-09-12 19:26:21 +02:00
if (string.IsNullOrEmpty(token))
2015-07-23 19:04:54 +02:00
{
throw new ArgumentException("Authentication required.");
}
2018-09-12 19:26:21 +02:00
if (string.IsNullOrEmpty(info.ListingsId))
2015-07-24 23:44:25 +02:00
{
throw new ArgumentException("Listings Id required");
}
_logger.LogInformation("Adding new LineUp ");
2015-07-23 19:04:54 +02:00
using var options = new HttpRequestMessage(HttpMethod.Put, ApiUrl + "/lineups/" + info.ListingsId);
options.Headers.TryAddWithoutValidation("token", token);
2020-09-03 15:30:34 +02:00
using var response = await _httpClientFactory.CreateClient(NamedClient.Default).SendAsync(options, HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
2015-07-23 19:04:54 +02:00
}
2015-07-24 01:40:54 +02:00
private async Task<bool> HasLineup(ListingsProviderInfo info, CancellationToken cancellationToken)
{
2018-09-12 19:26:21 +02:00
if (string.IsNullOrEmpty(info.ListingsId))
2015-07-24 23:44:25 +02:00
{
throw new ArgumentException("Listings Id required");
}
2019-10-25 12:47:20 +02:00
var token = await GetToken(info, cancellationToken).ConfigureAwait(false);
2015-07-24 01:40:54 +02:00
2018-09-12 19:26:21 +02:00
if (string.IsNullOrEmpty(token))
2015-07-26 23:02:23 +02:00
{
throw new Exception("token required");
}
_logger.LogInformation("Headends on account ");
2015-07-24 01:40:54 +02:00
using var options = new HttpRequestMessage(HttpMethod.Get, ApiUrl + "/lineups");
options.Headers.TryAddWithoutValidation("token", token);
2015-07-24 01:40:54 +02:00
2015-08-21 07:00:56 +02:00
try
{
using var httpResponse = await Send(options, false, null, cancellationToken).ConfigureAwait(false);
2020-12-08 16:28:19 +01:00
httpResponse.EnsureSuccessStatusCode();
2020-11-17 19:43:00 +01:00
await using var stream = await httpResponse.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
using var response = httpResponse.Content;
2021-02-15 14:19:08 +01:00
var root = await JsonSerializer.DeserializeAsync<ScheduleDirect.Lineups>(stream, _jsonOptions, cancellationToken).ConfigureAwait(false);
2015-08-21 07:00:56 +02:00
return root.lineups.Any(i => string.Equals(info.ListingsId, i.lineup, StringComparison.OrdinalIgnoreCase));
2015-08-21 07:00:56 +02:00
}
2020-11-14 22:30:34 +01:00
catch (HttpRequestException ex)
2015-07-24 01:40:54 +02:00
{
2020-12-08 16:28:19 +01:00
// SchedulesDirect returns 400 if no lineups are configured.
2015-08-21 07:00:56 +02:00
if (ex.StatusCode.HasValue && ex.StatusCode.Value == HttpStatusCode.BadRequest)
{
return false;
}
2015-07-24 01:40:54 +02:00
2015-08-21 07:00:56 +02:00
throw;
2015-07-24 01:40:54 +02:00
}
}
2015-07-25 19:21:10 +02:00
public async Task Validate(ListingsProviderInfo info, bool validateLogin, bool validateListings)
2015-07-24 01:40:54 +02:00
{
2015-07-25 19:21:10 +02:00
if (validateLogin)
2015-07-24 23:44:25 +02:00
{
2018-09-12 19:26:21 +02:00
if (string.IsNullOrEmpty(info.Username))
2015-07-25 19:21:10 +02:00
{
throw new ArgumentException("Username is required");
}
2020-06-15 23:43:52 +02:00
2018-09-12 19:26:21 +02:00
if (string.IsNullOrEmpty(info.Password))
2015-07-25 19:21:10 +02:00
{
throw new ArgumentException("Password is required");
}
2015-07-24 23:44:25 +02:00
}
2020-06-15 23:43:52 +02:00
2015-07-25 19:21:10 +02:00
if (validateListings)
{
2018-09-12 19:26:21 +02:00
if (string.IsNullOrEmpty(info.ListingsId))
2015-07-25 19:21:10 +02:00
{
throw new ArgumentException("Listings Id required");
}
2015-07-24 23:44:25 +02:00
2015-07-25 19:21:10 +02:00
var hasLineup = await HasLineup(info, CancellationToken.None).ConfigureAwait(false);
2015-07-24 01:40:54 +02:00
2015-07-25 19:21:10 +02:00
if (!hasLineup)
{
await AddLineupToAccount(info, CancellationToken.None).ConfigureAwait(false);
}
2015-07-24 01:40:54 +02:00
}
}
public Task<List<NameIdPair>> GetLineups(ListingsProviderInfo info, string country, string location)
{
return GetHeadends(info, country, location, CancellationToken.None);
}
2016-06-08 07:24:25 +02:00
public async Task<List<ChannelInfo>> GetChannels(ListingsProviderInfo info, CancellationToken cancellationToken)
{
2016-06-08 23:04:52 +02:00
var listingsId = info.ListingsId;
2018-09-12 19:26:21 +02:00
if (string.IsNullOrEmpty(listingsId))
2016-06-08 23:04:52 +02:00
{
throw new Exception("ListingsId required");
}
2019-10-25 12:47:20 +02:00
var token = await GetToken(info, cancellationToken).ConfigureAwait(false);
2016-06-08 23:04:52 +02:00
2018-09-12 19:26:21 +02:00
if (string.IsNullOrEmpty(token))
2016-06-08 23:04:52 +02:00
{
throw new Exception("token required");
}
using var options = new HttpRequestMessage(HttpMethod.Get, ApiUrl + "/lineups/" + listingsId);
options.Headers.TryAddWithoutValidation("token", token);
2016-06-08 23:04:52 +02:00
using var httpResponse = await Send(options, true, info, cancellationToken).ConfigureAwait(false);
2020-11-17 19:43:00 +01:00
await using var stream = await httpResponse.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
2021-02-15 14:19:08 +01:00
var root = await JsonSerializer.DeserializeAsync<ScheduleDirect.Channel>(stream, _jsonOptions, cancellationToken).ConfigureAwait(false);
_logger.LogInformation("Found {ChannelCount} channels on the lineup on ScheduleDirect", root.map.Count);
_logger.LogInformation("Mapping Stations to Channel");
2017-02-05 00:32:16 +01:00
2020-11-26 21:54:14 +01:00
var allStations = root.stations ?? new List<ScheduleDirect.Station>();
2017-02-05 00:32:16 +01:00
2020-11-26 21:54:14 +01:00
var map = root.map;
var list = new List<ChannelInfo>(map.Count);
foreach (var channel in map)
{
var channelNumber = GetChannelNumber(channel);
2017-10-20 18:16:56 +02:00
var station = allStations.Find(item => string.Equals(item.stationID, channel.stationID, StringComparison.OrdinalIgnoreCase));
if (station == null)
{
2020-11-26 21:54:14 +01:00
station = new ScheduleDirect.Station
{
stationID = channel.stationID
2020-11-26 21:54:14 +01:00
};
}
2017-02-05 00:32:16 +01:00
2020-09-01 15:58:05 +02:00
var channelInfo = new ChannelInfo
{
Id = station.stationID,
CallSign = station.callsign,
Number = channelNumber,
Name = string.IsNullOrWhiteSpace(station.name) ? channelNumber : station.name
};
if (station.logo != null)
{
channelInfo.ImageUrl = station.logo.URL;
2016-06-08 23:04:52 +02:00
}
list.Add(channelInfo);
2017-02-05 00:32:16 +01:00
}
return list;
2017-02-05 00:32:16 +01:00
}
private static string NormalizeName(string value)
2017-02-05 00:32:16 +01:00
{
return value.Replace(" ", string.Empty, StringComparison.Ordinal).Replace("-", string.Empty, StringComparison.Ordinal);
2017-02-05 00:32:16 +01:00
}
2015-07-23 07:25:55 +02:00
public class ScheduleDirect
{
public class Token
{
public int code { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string message { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string serverID { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string token { get; set; }
}
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public class Lineup
{
public string lineup { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string name { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string transport { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string location { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string uri { get; set; }
}
public class Lineups
{
public int code { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string serverID { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string datetime { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public List<Lineup> lineups { get; set; }
}
public class Headends
{
public string headend { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string transport { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string location { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public List<Lineup> lineups { get; set; }
}
public class Map
{
public string stationID { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string channel { get; set; }
2020-06-15 23:43:52 +02:00
2015-10-01 18:28:24 +02:00
public string logicalChannelNumber { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public int uhfVhf { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public int atscMajor { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public int atscMinor { get; set; }
}
public class Broadcaster
{
public string city { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string state { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string postalcode { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string country { get; set; }
}
public class Logo
{
public string URL { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public int height { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public int width { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string md5 { get; set; }
}
public class Station
{
public string stationID { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string name { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string callsign { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public List<string> broadcastLanguage { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public List<string> descriptionLanguage { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public Broadcaster broadcaster { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string affiliate { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public Logo logo { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public bool? isCommercialFree { get; set; }
}
public class Metadata
{
public string lineup { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string modified { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string transport { get; set; }
}
public class Channel
{
public List<Map> map { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public List<Station> stations { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public Metadata metadata { get; set; }
}
public class RequestScheduleForChannel
{
public string stationID { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public List<string> date { get; set; }
}
public class Rating
{
public string body { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string code { get; set; }
}
public class Multipart
{
public int partNumber { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public int totalParts { get; set; }
}
public class Program
{
public string programID { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string airDateTime { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public int duration { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string md5 { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public List<string> audioProperties { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public List<string> videoProperties { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public List<Rating> ratings { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public bool? @new { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public Multipart multipart { get; set; }
2020-06-15 23:43:52 +02:00
2018-09-12 19:26:21 +02:00
public string liveTapeDelay { get; set; }
2020-06-15 23:43:52 +02:00
2018-09-12 19:26:21 +02:00
public bool premiere { get; set; }
2020-06-15 23:43:52 +02:00
2018-09-12 19:26:21 +02:00
public bool repeat { get; set; }
2020-06-15 23:43:52 +02:00
2018-09-12 19:26:21 +02:00
public string isPremiereOrFinale { get; set; }
2015-07-23 07:25:55 +02:00
}
public class MetadataSchedule
{
public string modified { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string md5 { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string startDate { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string endDate { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public int days { get; set; }
}
public class Day
{
public string stationID { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public List<Program> programs { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public MetadataSchedule metadata { get; set; }
2016-03-01 05:23:58 +01:00
public Day()
{
programs = new List<Program>();
}
2015-07-23 07:25:55 +02:00
}
public class Title
{
public string title120 { get; set; }
}
public class EventDetails
{
public string subType { get; set; }
}
public class Description100
{
public string descriptionLanguage { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string description { get; set; }
}
public class Description1000
{
public string descriptionLanguage { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string description { get; set; }
}
public class DescriptionsProgram
{
public List<Description100> description100 { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public List<Description1000> description1000 { get; set; }
}
public class Gracenote
{
public int season { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public int episode { get; set; }
}
public class MetadataPrograms
{
public Gracenote Gracenote { get; set; }
}
public class ContentRating
{
public string body { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string code { get; set; }
}
public class Cast
{
public string billingOrder { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string role { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string nameId { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string personId { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string name { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string characterName { get; set; }
}
public class Crew
{
public string billingOrder { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string role { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string nameId { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string personId { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string name { get; set; }
}
public class QualityRating
{
public string ratingsBody { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string rating { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string minRating { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string maxRating { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string increment { get; set; }
}
public class Movie
{
public string year { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public int duration { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public List<QualityRating> qualityRating { get; set; }
}
public class Recommendation
{
public string programID { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string title120 { get; set; }
}
public class ProgramDetails
{
2015-08-19 08:12:58 +02:00
public string audience { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string programID { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public List<Title> titles { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public EventDetails eventDetails { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public DescriptionsProgram descriptions { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string originalAirDate { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public List<string> genres { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string episodeTitle150 { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public List<MetadataPrograms> metadata { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public List<ContentRating> contentRating { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public List<Cast> cast { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public List<Crew> crew { get; set; }
2020-06-15 23:43:52 +02:00
2017-06-21 16:51:11 +02:00
public string entityType { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string showType { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public bool hasImageArtwork { get; set; }
2020-06-15 23:43:52 +02:00
2016-09-11 09:33:53 +02:00
public string primaryImage { get; set; }
2020-06-15 23:43:52 +02:00
2016-09-11 09:33:53 +02:00
public string thumbImage { get; set; }
2020-06-15 23:43:52 +02:00
2017-06-11 23:58:49 +02:00
public string backdropImage { get; set; }
2020-06-15 23:43:52 +02:00
2016-09-11 09:33:53 +02:00
public string bannerImage { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string imageID { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string md5 { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public List<string> contentAdvisory { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public Movie movie { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public List<Recommendation> recommendations { get; set; }
}
public class Caption
{
public string content { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string lang { get; set; }
}
public class ImageData
{
public string width { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string height { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string uri { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string size { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string aspect { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string category { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string text { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string primary { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public string tier { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public Caption caption { get; set; }
}
public class ShowImages
{
public string programID { get; set; }
2020-06-15 23:43:52 +02:00
2015-07-23 07:25:55 +02:00
public List<ImageData> data { get; set; }
}
2015-07-21 06:22:46 +02:00
}
}
2018-12-30 18:30:29 +01:00
}