2020-02-06 07:20:23 -07:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2019-01-13 12:22:00 -07:00
|
|
|
using System;
|
2019-02-28 15:22:57 -07:00
|
|
|
using System.Globalization;
|
2019-01-13 12:22:00 -07:00
|
|
|
using System.Linq;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
2019-01-06 13:50:43 -07:00
|
|
|
using MediaBrowser.Common;
|
2014-10-29 18:17:31 -07:00
|
|
|
using MediaBrowser.Common.Extensions;
|
2013-12-14 18:17:57 -07:00
|
|
|
using MediaBrowser.Controller.Drawing;
|
|
|
|
using MediaBrowser.Controller.Dto;
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2019-01-13 12:22:00 -07:00
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
2013-12-14 18:17:57 -07:00
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
using MediaBrowser.Controller.LiveTv;
|
2019-01-13 12:22:00 -07:00
|
|
|
using MediaBrowser.Model.Dto;
|
2013-12-14 18:17:57 -07:00
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
using MediaBrowser.Model.LiveTv;
|
2018-12-13 06:18:25 -07:00
|
|
|
using Microsoft.Extensions.Logging;
|
2013-12-14 18:17:57 -07:00
|
|
|
|
2016-11-03 16:35:19 -07:00
|
|
|
namespace Emby.Server.Implementations.LiveTv
|
2013-12-14 18:17:57 -07:00
|
|
|
{
|
|
|
|
public class LiveTvDtoService
|
|
|
|
{
|
2020-04-11 03:03:10 -07:00
|
|
|
private const string InternalVersionNumber = "4";
|
|
|
|
|
|
|
|
private const string ServiceName = "Emby";
|
|
|
|
|
2020-06-05 17:15:56 -07:00
|
|
|
private readonly ILogger<LiveTvDtoService> _logger;
|
2013-12-14 18:17:57 -07:00
|
|
|
private readonly IImageProcessor _imageProcessor;
|
|
|
|
private readonly IDtoService _dtoService;
|
2014-10-29 18:17:31 -07:00
|
|
|
private readonly IApplicationHost _appHost;
|
2016-03-23 23:04:58 -07:00
|
|
|
private readonly ILibraryManager _libraryManager;
|
2013-12-14 18:17:57 -07:00
|
|
|
|
2019-01-17 15:55:05 -07:00
|
|
|
public LiveTvDtoService(
|
|
|
|
IDtoService dtoService,
|
|
|
|
IImageProcessor imageProcessor,
|
2020-04-04 11:40:04 -07:00
|
|
|
ILogger<LiveTvDtoService> logger,
|
2019-01-17 15:55:05 -07:00
|
|
|
IApplicationHost appHost,
|
|
|
|
ILibraryManager libraryManager)
|
2013-12-14 18:17:57 -07:00
|
|
|
{
|
|
|
|
_dtoService = dtoService;
|
|
|
|
_imageProcessor = imageProcessor;
|
2020-04-04 11:40:04 -07:00
|
|
|
_logger = logger;
|
2014-10-29 18:17:31 -07:00
|
|
|
_appHost = appHost;
|
2016-03-23 23:04:58 -07:00
|
|
|
_libraryManager = libraryManager;
|
2013-12-14 18:17:57 -07:00
|
|
|
}
|
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
public TimerInfoDto GetTimerInfoDto(TimerInfo info, ILiveTvService service, LiveTvProgram program, BaseItem channel)
|
2013-12-14 18:17:57 -07:00
|
|
|
{
|
|
|
|
var dto = new TimerInfoDto
|
|
|
|
{
|
2018-09-12 10:26:21 -07:00
|
|
|
Id = GetInternalTimerId(info.Id),
|
2013-12-14 18:17:57 -07:00
|
|
|
Overview = info.Overview,
|
|
|
|
EndDate = info.EndDate,
|
|
|
|
Name = info.Name,
|
|
|
|
StartDate = info.StartDate,
|
|
|
|
ExternalId = info.Id,
|
2018-09-12 10:26:21 -07:00
|
|
|
ChannelId = GetInternalChannelId(service.Name, info.ChannelId),
|
2013-12-14 18:17:57 -07:00
|
|
|
Status = info.Status,
|
2019-02-28 15:22:57 -07:00
|
|
|
SeriesTimerId = string.IsNullOrEmpty(info.SeriesTimerId) ? null : GetInternalSeriesTimerId(info.SeriesTimerId).ToString("N", CultureInfo.InvariantCulture),
|
2013-12-17 22:44:46 -07:00
|
|
|
PrePaddingSeconds = info.PrePaddingSeconds,
|
|
|
|
PostPaddingSeconds = info.PostPaddingSeconds,
|
|
|
|
IsPostPaddingRequired = info.IsPostPaddingRequired,
|
|
|
|
IsPrePaddingRequired = info.IsPrePaddingRequired,
|
2016-09-26 22:13:56 -07:00
|
|
|
KeepUntil = info.KeepUntil,
|
2013-12-14 18:17:57 -07:00
|
|
|
ExternalChannelId = info.ChannelId,
|
2013-12-15 07:19:24 -07:00
|
|
|
ExternalSeriesTimerId = info.SeriesTimerId,
|
2013-12-16 11:44:03 -07:00
|
|
|
ServiceName = service.Name,
|
2013-12-16 23:08:06 -07:00
|
|
|
ExternalProgramId = info.ProgramId,
|
2013-12-20 13:09:49 -07:00
|
|
|
Priority = info.Priority,
|
2014-10-29 18:17:31 -07:00
|
|
|
RunTimeTicks = (info.EndDate - info.StartDate).Ticks,
|
|
|
|
ServerId = _appHost.SystemId
|
2013-12-14 18:17:57 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(info.ProgramId))
|
|
|
|
{
|
2019-02-28 15:22:57 -07:00
|
|
|
dto.ProgramId = GetInternalProgramId(info.ProgramId).ToString("N", CultureInfo.InvariantCulture);
|
2013-12-14 18:17:57 -07:00
|
|
|
}
|
|
|
|
|
2013-12-22 10:16:24 -07:00
|
|
|
if (program != null)
|
|
|
|
{
|
2015-05-31 12:12:58 -07:00
|
|
|
dto.ProgramInfo = _dtoService.GetBaseItemDto(program, new DtoOptions());
|
2013-12-22 10:16:24 -07:00
|
|
|
|
2016-10-17 09:35:29 -07:00
|
|
|
if (info.Status != RecordingStatus.Cancelled && info.Status != RecordingStatus.Error)
|
|
|
|
{
|
|
|
|
dto.ProgramInfo.TimerId = dto.Id;
|
|
|
|
dto.ProgramInfo.Status = info.Status.ToString();
|
|
|
|
}
|
2016-10-03 22:15:39 -07:00
|
|
|
|
2013-12-22 10:16:24 -07:00
|
|
|
dto.ProgramInfo.SeriesTimerId = dto.SeriesTimerId;
|
2016-12-17 19:35:21 -07:00
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
if (!string.IsNullOrEmpty(info.SeriesTimerId))
|
2016-12-17 19:35:21 -07:00
|
|
|
{
|
|
|
|
FillImages(dto.ProgramInfo, info.Name, info.SeriesId);
|
|
|
|
}
|
2013-12-22 10:16:24 -07:00
|
|
|
}
|
|
|
|
|
2013-12-22 20:46:03 -07:00
|
|
|
if (channel != null)
|
|
|
|
{
|
2014-01-23 11:05:41 -07:00
|
|
|
dto.ChannelName = channel.Name;
|
2017-10-18 18:19:48 -07:00
|
|
|
|
|
|
|
if (channel.HasImage(ImageType.Primary))
|
|
|
|
{
|
|
|
|
dto.ChannelPrimaryImageTag = GetImageTag(channel);
|
|
|
|
}
|
2013-12-22 20:46:03 -07:00
|
|
|
}
|
|
|
|
|
2013-12-14 18:17:57 -07:00
|
|
|
return dto;
|
|
|
|
}
|
|
|
|
|
2013-12-22 20:46:03 -07:00
|
|
|
public SeriesTimerInfoDto GetSeriesTimerInfoDto(SeriesTimerInfo info, ILiveTvService service, string channelName)
|
2013-12-14 18:17:57 -07:00
|
|
|
{
|
|
|
|
var dto = new SeriesTimerInfoDto
|
|
|
|
{
|
2019-02-28 15:22:57 -07:00
|
|
|
Id = GetInternalSeriesTimerId(info.Id).ToString("N", CultureInfo.InvariantCulture),
|
2013-12-14 18:17:57 -07:00
|
|
|
Overview = info.Overview,
|
|
|
|
EndDate = info.EndDate,
|
|
|
|
Name = info.Name,
|
|
|
|
StartDate = info.StartDate,
|
|
|
|
ExternalId = info.Id,
|
2013-12-17 22:44:46 -07:00
|
|
|
PrePaddingSeconds = info.PrePaddingSeconds,
|
|
|
|
PostPaddingSeconds = info.PostPaddingSeconds,
|
|
|
|
IsPostPaddingRequired = info.IsPostPaddingRequired,
|
|
|
|
IsPrePaddingRequired = info.IsPrePaddingRequired,
|
2017-08-19 12:43:35 -07:00
|
|
|
Days = info.Days.ToArray(),
|
2013-12-14 18:17:57 -07:00
|
|
|
Priority = info.Priority,
|
2013-12-16 11:44:03 -07:00
|
|
|
RecordAnyChannel = info.RecordAnyChannel,
|
|
|
|
RecordAnyTime = info.RecordAnyTime,
|
2016-09-21 14:09:14 -07:00
|
|
|
SkipEpisodesInLibrary = info.SkipEpisodesInLibrary,
|
|
|
|
KeepUpTo = info.KeepUpTo,
|
2016-09-26 11:59:18 -07:00
|
|
|
KeepUntil = info.KeepUntil,
|
2013-12-16 11:44:03 -07:00
|
|
|
RecordNewOnly = info.RecordNewOnly,
|
2013-12-14 18:17:57 -07:00
|
|
|
ExternalChannelId = info.ChannelId,
|
2013-12-15 07:19:24 -07:00
|
|
|
ExternalProgramId = info.ProgramId,
|
2013-12-22 20:46:03 -07:00
|
|
|
ServiceName = service.Name,
|
2014-10-29 18:17:31 -07:00
|
|
|
ChannelName = channelName,
|
2015-08-16 15:03:22 -07:00
|
|
|
ServerId = _appHost.SystemId
|
2013-12-14 18:17:57 -07:00
|
|
|
};
|
|
|
|
|
2013-12-15 07:19:24 -07:00
|
|
|
if (!string.IsNullOrEmpty(info.ChannelId))
|
|
|
|
{
|
2018-09-12 10:26:21 -07:00
|
|
|
dto.ChannelId = GetInternalChannelId(service.Name, info.ChannelId);
|
2013-12-15 07:19:24 -07:00
|
|
|
}
|
|
|
|
|
2013-12-14 18:17:57 -07:00
|
|
|
if (!string.IsNullOrEmpty(info.ProgramId))
|
|
|
|
{
|
2019-02-28 15:22:57 -07:00
|
|
|
dto.ProgramId = GetInternalProgramId(info.ProgramId).ToString("N", CultureInfo.InvariantCulture);
|
2013-12-14 18:17:57 -07:00
|
|
|
}
|
|
|
|
|
2018-12-28 08:48:26 -07:00
|
|
|
dto.DayPattern = info.Days == null ? null : GetDayPattern(info.Days.ToArray());
|
2013-12-17 22:44:46 -07:00
|
|
|
|
2016-12-17 19:35:21 -07:00
|
|
|
FillImages(dto, info.Name, info.SeriesId);
|
2016-11-17 11:18:19 -07:00
|
|
|
|
|
|
|
return dto;
|
|
|
|
}
|
|
|
|
|
2016-12-17 19:35:21 -07:00
|
|
|
private void FillImages(BaseItemDto dto, string seriesName, string programSeriesId)
|
2016-11-17 11:18:19 -07:00
|
|
|
{
|
|
|
|
var librarySeries = _libraryManager.GetItemList(new InternalItemsQuery
|
|
|
|
{
|
2020-10-17 07:19:57 -07:00
|
|
|
IncludeItemTypes = new string[] { nameof(Series) },
|
2016-12-17 19:35:21 -07:00
|
|
|
Name = seriesName,
|
|
|
|
Limit = 1,
|
2017-05-21 00:25:49 -07:00
|
|
|
ImageTypes = new ImageType[] { ImageType.Thumb },
|
2017-08-19 12:43:35 -07:00
|
|
|
DtoOptions = new DtoOptions(false)
|
2016-12-17 19:35:21 -07:00
|
|
|
}).FirstOrDefault();
|
|
|
|
|
|
|
|
if (librarySeries != null)
|
|
|
|
{
|
|
|
|
var image = librarySeries.GetImageInfo(ImageType.Thumb, 0);
|
|
|
|
if (image != null)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
dto.ParentThumbImageTag = _imageProcessor.GetImageCacheTag(librarySeries, image);
|
2019-02-28 15:22:57 -07:00
|
|
|
dto.ParentThumbItemId = librarySeries.Id.ToString("N", CultureInfo.InvariantCulture);
|
2016-12-17 19:35:21 -07:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2018-12-20 05:11:26 -07:00
|
|
|
_logger.LogError(ex, "Error");
|
2016-12-17 19:35:21 -07:00
|
|
|
}
|
|
|
|
}
|
2020-04-11 03:03:10 -07:00
|
|
|
|
2016-12-17 21:58:20 -07:00
|
|
|
image = librarySeries.GetImageInfo(ImageType.Backdrop, 0);
|
|
|
|
if (image != null)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2017-08-09 12:56:38 -07:00
|
|
|
dto.ParentBackdropImageTags = new string[]
|
2016-12-17 21:58:20 -07:00
|
|
|
{
|
|
|
|
_imageProcessor.GetImageCacheTag(librarySeries, image)
|
|
|
|
};
|
2019-02-28 15:22:57 -07:00
|
|
|
dto.ParentBackdropItemId = librarySeries.Id.ToString("N", CultureInfo.InvariantCulture);
|
2016-12-17 21:58:20 -07:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2018-12-20 05:11:26 -07:00
|
|
|
_logger.LogError(ex, "Error");
|
2016-12-17 21:58:20 -07:00
|
|
|
}
|
|
|
|
}
|
2016-12-17 19:35:21 -07:00
|
|
|
}
|
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
var program = _libraryManager.GetItemList(new InternalItemsQuery
|
2016-12-17 19:35:21 -07:00
|
|
|
{
|
2020-04-11 03:03:10 -07:00
|
|
|
IncludeItemTypes = new string[] { nameof(LiveTvProgram) },
|
2018-09-12 10:26:21 -07:00
|
|
|
ExternalSeriesId = programSeriesId,
|
|
|
|
Limit = 1,
|
|
|
|
ImageTypes = new ImageType[] { ImageType.Primary },
|
|
|
|
DtoOptions = new DtoOptions(false),
|
|
|
|
Name = string.IsNullOrEmpty(programSeriesId) ? seriesName : null
|
|
|
|
}).FirstOrDefault();
|
2016-12-17 19:35:21 -07:00
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
if (program != null)
|
|
|
|
{
|
|
|
|
var image = program.GetImageInfo(ImageType.Primary, 0);
|
|
|
|
if (image != null)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
dto.ParentPrimaryImageTag = _imageProcessor.GetImageCacheTag(program, image);
|
2019-02-28 15:22:57 -07:00
|
|
|
dto.ParentPrimaryImageItemId = program.Id.ToString("N", CultureInfo.InvariantCulture);
|
2018-09-12 10:26:21 -07:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2018-12-20 05:11:26 -07:00
|
|
|
_logger.LogError(ex, "Error");
|
2018-09-12 10:26:21 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dto.ParentBackdropImageTags == null || dto.ParentBackdropImageTags.Length == 0)
|
2016-12-17 19:35:21 -07:00
|
|
|
{
|
2018-09-12 10:26:21 -07:00
|
|
|
image = program.GetImageInfo(ImageType.Backdrop, 0);
|
2016-12-17 19:35:21 -07:00
|
|
|
if (image != null)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2018-09-12 10:26:21 -07:00
|
|
|
dto.ParentBackdropImageTags = new string[]
|
2020-04-11 03:03:10 -07:00
|
|
|
{
|
2018-09-12 10:26:21 -07:00
|
|
|
_imageProcessor.GetImageCacheTag(program, image)
|
2020-04-11 03:03:10 -07:00
|
|
|
};
|
|
|
|
|
2019-02-28 15:22:57 -07:00
|
|
|
dto.ParentBackdropItemId = program.Id.ToString("N", CultureInfo.InvariantCulture);
|
2016-12-17 19:35:21 -07:00
|
|
|
}
|
2018-09-12 10:26:21 -07:00
|
|
|
catch (Exception ex)
|
2016-12-17 21:58:20 -07:00
|
|
|
{
|
2018-12-20 05:11:26 -07:00
|
|
|
_logger.LogError(ex, "Error");
|
2016-12-17 21:58:20 -07:00
|
|
|
}
|
|
|
|
}
|
2016-12-17 19:35:21 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void FillImages(SeriesTimerInfoDto dto, string seriesName, string programSeriesId)
|
|
|
|
{
|
|
|
|
var librarySeries = _libraryManager.GetItemList(new InternalItemsQuery
|
|
|
|
{
|
2020-10-17 07:19:57 -07:00
|
|
|
IncludeItemTypes = new string[] { nameof(Series) },
|
2016-12-17 19:35:21 -07:00
|
|
|
Name = seriesName,
|
2016-11-17 11:18:19 -07:00
|
|
|
Limit = 1,
|
2017-05-21 00:25:49 -07:00
|
|
|
ImageTypes = new ImageType[] { ImageType.Thumb },
|
2017-08-19 12:43:35 -07:00
|
|
|
DtoOptions = new DtoOptions(false)
|
2016-11-17 11:18:19 -07:00
|
|
|
}).FirstOrDefault();
|
|
|
|
|
|
|
|
if (librarySeries != null)
|
|
|
|
{
|
|
|
|
var image = librarySeries.GetImageInfo(ImageType.Thumb, 0);
|
|
|
|
if (image != null)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
dto.ParentThumbImageTag = _imageProcessor.GetImageCacheTag(librarySeries, image);
|
2019-02-28 15:22:57 -07:00
|
|
|
dto.ParentThumbItemId = librarySeries.Id.ToString("N", CultureInfo.InvariantCulture);
|
2016-11-17 11:18:19 -07:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2018-12-20 05:11:26 -07:00
|
|
|
_logger.LogError(ex, "Error");
|
2016-11-17 11:18:19 -07:00
|
|
|
}
|
|
|
|
}
|
2020-04-11 03:03:10 -07:00
|
|
|
|
2016-12-17 21:58:20 -07:00
|
|
|
image = librarySeries.GetImageInfo(ImageType.Backdrop, 0);
|
|
|
|
if (image != null)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2017-08-19 12:43:35 -07:00
|
|
|
dto.ParentBackdropImageTags = new string[]
|
2016-12-17 21:58:20 -07:00
|
|
|
{
|
|
|
|
_imageProcessor.GetImageCacheTag(librarySeries, image)
|
|
|
|
};
|
2019-02-28 15:22:57 -07:00
|
|
|
dto.ParentBackdropItemId = librarySeries.Id.ToString("N", CultureInfo.InvariantCulture);
|
2016-12-17 21:58:20 -07:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2018-12-20 05:11:26 -07:00
|
|
|
_logger.LogError(ex, "Error");
|
2016-12-17 21:58:20 -07:00
|
|
|
}
|
|
|
|
}
|
2016-11-17 11:18:19 -07:00
|
|
|
}
|
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
var program = _libraryManager.GetItemList(new InternalItemsQuery
|
2016-10-09 00:18:43 -07:00
|
|
|
{
|
2020-10-17 07:19:57 -07:00
|
|
|
IncludeItemTypes = new string[] { nameof(Series) },
|
2018-09-12 10:26:21 -07:00
|
|
|
Name = seriesName,
|
|
|
|
Limit = 1,
|
|
|
|
ImageTypes = new ImageType[] { ImageType.Primary },
|
|
|
|
DtoOptions = new DtoOptions(false)
|
|
|
|
}).FirstOrDefault();
|
2017-02-15 14:19:07 -07:00
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
if (program == null)
|
|
|
|
{
|
|
|
|
program = _libraryManager.GetItemList(new InternalItemsQuery
|
2016-10-09 00:18:43 -07:00
|
|
|
{
|
2020-10-17 07:19:57 -07:00
|
|
|
IncludeItemTypes = new string[] { nameof(LiveTvProgram) },
|
2016-12-17 19:35:21 -07:00
|
|
|
ExternalSeriesId = programSeriesId,
|
2016-10-09 00:18:43 -07:00
|
|
|
Limit = 1,
|
2017-05-21 00:25:49 -07:00
|
|
|
ImageTypes = new ImageType[] { ImageType.Primary },
|
2018-09-12 10:26:21 -07:00
|
|
|
DtoOptions = new DtoOptions(false),
|
|
|
|
Name = string.IsNullOrEmpty(programSeriesId) ? seriesName : null
|
2016-10-09 00:18:43 -07:00
|
|
|
}).FirstOrDefault();
|
2018-09-12 10:26:21 -07:00
|
|
|
}
|
2016-10-09 00:18:43 -07:00
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
if (program != null)
|
|
|
|
{
|
|
|
|
var image = program.GetImageInfo(ImageType.Primary, 0);
|
|
|
|
if (image != null)
|
2016-10-09 00:18:43 -07:00
|
|
|
{
|
2018-09-12 10:26:21 -07:00
|
|
|
try
|
|
|
|
{
|
|
|
|
dto.ParentPrimaryImageTag = _imageProcessor.GetImageCacheTag(program, image);
|
2019-02-28 15:22:57 -07:00
|
|
|
dto.ParentPrimaryImageItemId = program.Id.ToString("N", CultureInfo.InvariantCulture);
|
2018-09-12 10:26:21 -07:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2019-01-06 13:50:43 -07:00
|
|
|
_logger.LogDebug(ex, "GetImageCacheTag raised an exception in LiveTvDtoService.FillImages.");
|
2018-09-12 10:26:21 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dto.ParentBackdropImageTags == null || dto.ParentBackdropImageTags.Length == 0)
|
|
|
|
{
|
|
|
|
image = program.GetImageInfo(ImageType.Backdrop, 0);
|
2016-10-09 00:18:43 -07:00
|
|
|
if (image != null)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2019-01-12 13:41:08 -07:00
|
|
|
dto.ParentBackdropImageTags = new[]
|
2019-01-06 13:50:43 -07:00
|
|
|
{
|
|
|
|
_imageProcessor.GetImageCacheTag(program, image)
|
|
|
|
};
|
2019-02-28 15:22:57 -07:00
|
|
|
dto.ParentBackdropItemId = program.Id.ToString("N", CultureInfo.InvariantCulture);
|
2016-10-09 00:18:43 -07:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2018-12-20 05:11:26 -07:00
|
|
|
_logger.LogError(ex, "Error");
|
2016-10-09 00:18:43 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-12-17 22:44:46 -07:00
|
|
|
}
|
|
|
|
|
2017-08-19 12:43:35 -07:00
|
|
|
public DayPattern? GetDayPattern(DayOfWeek[] days)
|
2013-12-17 22:44:46 -07:00
|
|
|
{
|
2013-12-14 18:17:57 -07:00
|
|
|
DayPattern? pattern = null;
|
|
|
|
|
2017-08-19 12:43:35 -07:00
|
|
|
if (days.Length > 0)
|
2013-12-14 18:17:57 -07:00
|
|
|
{
|
2017-08-19 12:43:35 -07:00
|
|
|
if (days.Length == 7)
|
2013-12-14 18:17:57 -07:00
|
|
|
{
|
|
|
|
pattern = DayPattern.Daily;
|
|
|
|
}
|
2017-08-19 12:43:35 -07:00
|
|
|
else if (days.Length == 2)
|
2013-12-14 18:17:57 -07:00
|
|
|
{
|
2013-12-17 22:44:46 -07:00
|
|
|
if (days.Contains(DayOfWeek.Saturday) && days.Contains(DayOfWeek.Sunday))
|
2013-12-14 18:17:57 -07:00
|
|
|
{
|
|
|
|
pattern = DayPattern.Weekends;
|
|
|
|
}
|
|
|
|
}
|
2017-08-19 12:43:35 -07:00
|
|
|
else if (days.Length == 5)
|
2013-12-14 18:17:57 -07:00
|
|
|
{
|
2013-12-17 22:44:46 -07:00
|
|
|
if (days.Contains(DayOfWeek.Monday) && days.Contains(DayOfWeek.Tuesday) && days.Contains(DayOfWeek.Wednesday) && days.Contains(DayOfWeek.Thursday) && days.Contains(DayOfWeek.Friday))
|
2013-12-14 18:17:57 -07:00
|
|
|
{
|
|
|
|
pattern = DayPattern.Weekdays;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-17 22:44:46 -07:00
|
|
|
return pattern;
|
2013-12-14 18:17:57 -07:00
|
|
|
}
|
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
internal string GetImageTag(BaseItem info)
|
2013-12-14 18:17:57 -07:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2014-02-07 13:30:41 -07:00
|
|
|
return _imageProcessor.GetImageCacheTag(info, ImageType.Primary);
|
2013-12-14 18:17:57 -07:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2018-12-20 05:11:26 -07:00
|
|
|
_logger.LogError(ex, "Error getting image info for {name}", info.Name);
|
2013-12-14 18:17:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-12-22 20:46:03 -07:00
|
|
|
public Guid GetInternalChannelId(string serviceName, string externalId)
|
2013-12-14 18:17:57 -07:00
|
|
|
{
|
2014-01-01 11:26:31 -07:00
|
|
|
var name = serviceName + externalId + InternalVersionNumber;
|
2013-12-14 18:17:57 -07:00
|
|
|
|
2019-01-27 04:03:43 -07:00
|
|
|
return _libraryManager.GetNewItemId(name.ToLowerInvariant(), typeof(LiveTvChannel));
|
2013-12-14 18:17:57 -07:00
|
|
|
}
|
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
public string GetInternalTimerId(string externalId)
|
2013-12-14 18:17:57 -07:00
|
|
|
{
|
2018-09-12 10:26:21 -07:00
|
|
|
var name = ServiceName + externalId + InternalVersionNumber;
|
2013-12-14 18:17:57 -07:00
|
|
|
|
2019-02-28 15:22:57 -07:00
|
|
|
return name.ToLowerInvariant().GetMD5().ToString("N", CultureInfo.InvariantCulture);
|
2013-12-14 18:17:57 -07:00
|
|
|
}
|
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
public Guid GetInternalSeriesTimerId(string externalId)
|
2013-12-14 18:17:57 -07:00
|
|
|
{
|
2018-09-12 10:26:21 -07:00
|
|
|
var name = ServiceName + externalId + InternalVersionNumber;
|
2013-12-14 18:17:57 -07:00
|
|
|
|
2019-01-27 04:03:43 -07:00
|
|
|
return name.ToLowerInvariant().GetMD5();
|
2013-12-14 18:17:57 -07:00
|
|
|
}
|
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
public Guid GetInternalProgramId(string externalId)
|
2013-12-14 18:17:57 -07:00
|
|
|
{
|
2018-09-12 10:26:21 -07:00
|
|
|
var name = ServiceName + externalId + InternalVersionNumber;
|
2013-12-14 18:17:57 -07:00
|
|
|
|
2019-01-27 04:03:43 -07:00
|
|
|
return _libraryManager.GetNewItemId(name.ToLowerInvariant(), typeof(LiveTvProgram));
|
2013-12-14 18:17:57 -07:00
|
|
|
}
|
|
|
|
|
2015-05-31 12:12:58 -07:00
|
|
|
public async Task<TimerInfo> GetTimerInfo(TimerInfoDto dto, bool isNew, LiveTvManager liveTv, CancellationToken cancellationToken)
|
2013-12-14 18:17:57 -07:00
|
|
|
{
|
2013-12-17 13:02:12 -07:00
|
|
|
var info = new TimerInfo
|
2013-12-14 18:17:57 -07:00
|
|
|
{
|
|
|
|
Overview = dto.Overview,
|
|
|
|
EndDate = dto.EndDate,
|
|
|
|
Name = dto.Name,
|
|
|
|
StartDate = dto.StartDate,
|
|
|
|
Status = dto.Status,
|
2013-12-17 22:44:46 -07:00
|
|
|
PrePaddingSeconds = dto.PrePaddingSeconds,
|
|
|
|
PostPaddingSeconds = dto.PostPaddingSeconds,
|
|
|
|
IsPostPaddingRequired = dto.IsPostPaddingRequired,
|
|
|
|
IsPrePaddingRequired = dto.IsPrePaddingRequired,
|
2016-09-26 22:13:56 -07:00
|
|
|
KeepUntil = dto.KeepUntil,
|
2013-12-19 14:51:32 -07:00
|
|
|
Priority = dto.Priority,
|
|
|
|
SeriesTimerId = dto.ExternalSeriesTimerId,
|
|
|
|
ProgramId = dto.ExternalProgramId,
|
|
|
|
ChannelId = dto.ExternalChannelId,
|
|
|
|
Id = dto.ExternalId
|
2013-12-14 18:17:57 -07:00
|
|
|
};
|
2013-12-17 13:02:12 -07:00
|
|
|
|
|
|
|
// Convert internal server id's to external tv provider id's
|
2013-12-19 14:51:32 -07:00
|
|
|
if (!isNew && !string.IsNullOrEmpty(dto.Id) && string.IsNullOrEmpty(info.Id))
|
2013-12-17 13:02:12 -07:00
|
|
|
{
|
2013-12-19 14:51:32 -07:00
|
|
|
var timer = await liveTv.GetSeriesTimer(dto.Id, cancellationToken).ConfigureAwait(false);
|
2013-12-17 13:02:12 -07:00
|
|
|
|
|
|
|
info.Id = timer.ExternalId;
|
|
|
|
}
|
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
if (!dto.ChannelId.Equals(Guid.Empty) && string.IsNullOrEmpty(info.ChannelId))
|
2013-12-17 13:02:12 -07:00
|
|
|
{
|
2018-09-12 10:26:21 -07:00
|
|
|
var channel = _libraryManager.GetItemById(dto.ChannelId);
|
2013-12-17 13:02:12 -07:00
|
|
|
|
2013-12-19 14:51:32 -07:00
|
|
|
if (channel != null)
|
|
|
|
{
|
2018-09-12 10:26:21 -07:00
|
|
|
info.ChannelId = channel.ExternalId;
|
2013-12-19 14:51:32 -07:00
|
|
|
}
|
2013-12-17 13:02:12 -07:00
|
|
|
}
|
|
|
|
|
2013-12-19 14:51:32 -07:00
|
|
|
if (!string.IsNullOrEmpty(dto.ProgramId) && string.IsNullOrEmpty(info.ProgramId))
|
2013-12-17 13:02:12 -07:00
|
|
|
{
|
2018-09-12 10:26:21 -07:00
|
|
|
var program = _libraryManager.GetItemById(dto.ProgramId);
|
2013-12-17 13:02:12 -07:00
|
|
|
|
2013-12-19 14:51:32 -07:00
|
|
|
if (program != null)
|
|
|
|
{
|
2018-09-12 10:26:21 -07:00
|
|
|
info.ProgramId = program.ExternalId;
|
2013-12-19 14:51:32 -07:00
|
|
|
}
|
2013-12-17 13:02:12 -07:00
|
|
|
}
|
|
|
|
|
2013-12-19 14:51:32 -07:00
|
|
|
if (!string.IsNullOrEmpty(dto.SeriesTimerId) && string.IsNullOrEmpty(info.SeriesTimerId))
|
2013-12-17 13:02:12 -07:00
|
|
|
{
|
2013-12-19 14:51:32 -07:00
|
|
|
var timer = await liveTv.GetSeriesTimer(dto.SeriesTimerId, cancellationToken).ConfigureAwait(false);
|
2013-12-17 13:02:12 -07:00
|
|
|
|
2013-12-19 14:51:32 -07:00
|
|
|
if (timer != null)
|
|
|
|
{
|
|
|
|
info.SeriesTimerId = timer.ExternalId;
|
|
|
|
}
|
2013-12-17 13:02:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return info;
|
2013-12-14 18:17:57 -07:00
|
|
|
}
|
|
|
|
|
2015-05-31 12:12:58 -07:00
|
|
|
public async Task<SeriesTimerInfo> GetSeriesTimerInfo(SeriesTimerInfoDto dto, bool isNew, LiveTvManager liveTv, CancellationToken cancellationToken)
|
2013-12-14 18:17:57 -07:00
|
|
|
{
|
2013-12-17 13:02:12 -07:00
|
|
|
var info = new SeriesTimerInfo
|
2013-12-14 18:17:57 -07:00
|
|
|
{
|
|
|
|
Overview = dto.Overview,
|
|
|
|
EndDate = dto.EndDate,
|
|
|
|
Name = dto.Name,
|
|
|
|
StartDate = dto.StartDate,
|
2013-12-17 22:44:46 -07:00
|
|
|
PrePaddingSeconds = dto.PrePaddingSeconds,
|
|
|
|
PostPaddingSeconds = dto.PostPaddingSeconds,
|
|
|
|
IsPostPaddingRequired = dto.IsPostPaddingRequired,
|
|
|
|
IsPrePaddingRequired = dto.IsPrePaddingRequired,
|
2017-08-19 12:43:35 -07:00
|
|
|
Days = dto.Days.ToList(),
|
2013-12-14 18:17:57 -07:00
|
|
|
Priority = dto.Priority,
|
2013-12-16 11:44:03 -07:00
|
|
|
RecordAnyChannel = dto.RecordAnyChannel,
|
|
|
|
RecordAnyTime = dto.RecordAnyTime,
|
2016-09-21 14:09:14 -07:00
|
|
|
SkipEpisodesInLibrary = dto.SkipEpisodesInLibrary,
|
|
|
|
KeepUpTo = dto.KeepUpTo,
|
2016-09-26 11:59:18 -07:00
|
|
|
KeepUntil = dto.KeepUntil,
|
2013-12-19 14:51:32 -07:00
|
|
|
RecordNewOnly = dto.RecordNewOnly,
|
|
|
|
ProgramId = dto.ExternalProgramId,
|
|
|
|
ChannelId = dto.ExternalChannelId,
|
2015-08-16 15:03:22 -07:00
|
|
|
Id = dto.ExternalId
|
2013-12-14 18:17:57 -07:00
|
|
|
};
|
2013-12-17 13:02:12 -07:00
|
|
|
|
|
|
|
// Convert internal server id's to external tv provider id's
|
2013-12-19 14:51:32 -07:00
|
|
|
if (!isNew && !string.IsNullOrEmpty(dto.Id) && string.IsNullOrEmpty(info.Id))
|
2013-12-17 13:02:12 -07:00
|
|
|
{
|
|
|
|
var timer = await liveTv.GetSeriesTimer(dto.Id, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
|
|
info.Id = timer.ExternalId;
|
|
|
|
}
|
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
if (!dto.ChannelId.Equals(Guid.Empty) && string.IsNullOrEmpty(info.ChannelId))
|
2013-12-17 13:02:12 -07:00
|
|
|
{
|
2018-09-12 10:26:21 -07:00
|
|
|
var channel = _libraryManager.GetItemById(dto.ChannelId);
|
2013-12-17 13:02:12 -07:00
|
|
|
|
2013-12-19 14:51:32 -07:00
|
|
|
if (channel != null)
|
|
|
|
{
|
2018-09-12 10:26:21 -07:00
|
|
|
info.ChannelId = channel.ExternalId;
|
2013-12-19 14:51:32 -07:00
|
|
|
}
|
2013-12-17 13:02:12 -07:00
|
|
|
}
|
|
|
|
|
2013-12-19 14:51:32 -07:00
|
|
|
if (!string.IsNullOrEmpty(dto.ProgramId) && string.IsNullOrEmpty(info.ProgramId))
|
2013-12-17 13:02:12 -07:00
|
|
|
{
|
2018-09-12 10:26:21 -07:00
|
|
|
var program = _libraryManager.GetItemById(dto.ProgramId);
|
2013-12-17 13:02:12 -07:00
|
|
|
|
2013-12-19 14:51:32 -07:00
|
|
|
if (program != null)
|
|
|
|
{
|
2018-09-12 10:26:21 -07:00
|
|
|
info.ProgramId = program.ExternalId;
|
2013-12-19 14:51:32 -07:00
|
|
|
}
|
2013-12-17 13:02:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return info;
|
2013-12-14 18:17:57 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|