2014-10-29 21:17:31 -04:00
|
|
|
|
using MediaBrowser.Common;
|
|
|
|
|
using MediaBrowser.Common.Extensions;
|
2013-12-14 20:17:57 -05:00
|
|
|
|
using MediaBrowser.Controller.Drawing;
|
|
|
|
|
using MediaBrowser.Controller.Dto;
|
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
using MediaBrowser.Controller.LiveTv;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using MediaBrowser.Model.LiveTv;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using System;
|
2013-12-18 00:44:46 -05:00
|
|
|
|
using System.Collections.Generic;
|
2016-10-09 03:18:43 -04:00
|
|
|
|
using System.Linq;
|
2013-12-18 00:44:46 -05:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2016-11-17 13:18:19 -05:00
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
2016-12-17 21:35:21 -05:00
|
|
|
|
using MediaBrowser.Model.Dto;
|
2013-12-14 20:17:57 -05:00
|
|
|
|
|
2016-11-03 19:35:19 -04:00
|
|
|
|
namespace Emby.Server.Implementations.LiveTv
|
2013-12-14 20:17:57 -05:00
|
|
|
|
{
|
|
|
|
|
public class LiveTvDtoService
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly IImageProcessor _imageProcessor;
|
|
|
|
|
|
|
|
|
|
private readonly IUserDataManager _userDataManager;
|
|
|
|
|
private readonly IDtoService _dtoService;
|
2014-10-29 21:17:31 -04:00
|
|
|
|
private readonly IApplicationHost _appHost;
|
2016-03-24 02:04:58 -04:00
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
2013-12-14 20:17:57 -05:00
|
|
|
|
|
2016-03-24 02:04:58 -04:00
|
|
|
|
public LiveTvDtoService(IDtoService dtoService, IUserDataManager userDataManager, IImageProcessor imageProcessor, ILogger logger, IApplicationHost appHost, ILibraryManager libraryManager)
|
2013-12-14 20:17:57 -05:00
|
|
|
|
{
|
|
|
|
|
_dtoService = dtoService;
|
|
|
|
|
_userDataManager = userDataManager;
|
|
|
|
|
_imageProcessor = imageProcessor;
|
|
|
|
|
_logger = logger;
|
2014-10-29 21:17:31 -04:00
|
|
|
|
_appHost = appHost;
|
2016-03-24 02:04:58 -04:00
|
|
|
|
_libraryManager = libraryManager;
|
2013-12-14 20:17:57 -05:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-22 22:46:03 -05:00
|
|
|
|
public TimerInfoDto GetTimerInfoDto(TimerInfo info, ILiveTvService service, LiveTvProgram program, LiveTvChannel channel)
|
2013-12-14 20:17:57 -05:00
|
|
|
|
{
|
|
|
|
|
var dto = new TimerInfoDto
|
|
|
|
|
{
|
|
|
|
|
Id = GetInternalTimerId(service.Name, info.Id).ToString("N"),
|
|
|
|
|
Overview = info.Overview,
|
|
|
|
|
EndDate = info.EndDate,
|
|
|
|
|
Name = info.Name,
|
|
|
|
|
StartDate = info.StartDate,
|
|
|
|
|
ExternalId = info.Id,
|
2013-12-22 22:46:03 -05:00
|
|
|
|
ChannelId = GetInternalChannelId(service.Name, info.ChannelId).ToString("N"),
|
2013-12-14 20:17:57 -05:00
|
|
|
|
Status = info.Status,
|
|
|
|
|
SeriesTimerId = string.IsNullOrEmpty(info.SeriesTimerId) ? null : GetInternalSeriesTimerId(service.Name, info.SeriesTimerId).ToString("N"),
|
2013-12-18 00:44:46 -05:00
|
|
|
|
PrePaddingSeconds = info.PrePaddingSeconds,
|
|
|
|
|
PostPaddingSeconds = info.PostPaddingSeconds,
|
|
|
|
|
IsPostPaddingRequired = info.IsPostPaddingRequired,
|
|
|
|
|
IsPrePaddingRequired = info.IsPrePaddingRequired,
|
2016-09-27 01:13:56 -04:00
|
|
|
|
KeepUntil = info.KeepUntil,
|
2013-12-14 20:17:57 -05:00
|
|
|
|
ExternalChannelId = info.ChannelId,
|
2013-12-15 09:19:24 -05:00
|
|
|
|
ExternalSeriesTimerId = info.SeriesTimerId,
|
2013-12-16 13:44:03 -05:00
|
|
|
|
ServiceName = service.Name,
|
2013-12-17 01:08:06 -05:00
|
|
|
|
ExternalProgramId = info.ProgramId,
|
2013-12-20 15:09:49 -05:00
|
|
|
|
Priority = info.Priority,
|
2014-10-29 21:17:31 -04:00
|
|
|
|
RunTimeTicks = (info.EndDate - info.StartDate).Ticks,
|
|
|
|
|
ServerId = _appHost.SystemId
|
2013-12-14 20:17:57 -05:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(info.ProgramId))
|
|
|
|
|
{
|
|
|
|
|
dto.ProgramId = GetInternalProgramId(service.Name, info.ProgramId).ToString("N");
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-22 12:16:24 -05:00
|
|
|
|
if (program != null)
|
|
|
|
|
{
|
2015-05-31 15:12:58 -04:00
|
|
|
|
dto.ProgramInfo = _dtoService.GetBaseItemDto(program, new DtoOptions());
|
2013-12-22 12:16:24 -05:00
|
|
|
|
|
2016-10-17 12:35:29 -04:00
|
|
|
|
if (info.Status != RecordingStatus.Cancelled && info.Status != RecordingStatus.Error)
|
|
|
|
|
{
|
|
|
|
|
dto.ProgramInfo.TimerId = dto.Id;
|
|
|
|
|
dto.ProgramInfo.Status = info.Status.ToString();
|
|
|
|
|
}
|
2016-10-04 01:15:39 -04:00
|
|
|
|
|
2013-12-22 12:16:24 -05:00
|
|
|
|
dto.ProgramInfo.SeriesTimerId = dto.SeriesTimerId;
|
2016-12-17 21:35:21 -05:00
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(info.SeriesTimerId))
|
|
|
|
|
{
|
|
|
|
|
FillImages(dto.ProgramInfo, info.Name, info.SeriesId);
|
|
|
|
|
}
|
2013-12-22 12:16:24 -05:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-22 22:46:03 -05:00
|
|
|
|
if (channel != null)
|
|
|
|
|
{
|
2014-01-23 13:05:41 -05:00
|
|
|
|
dto.ChannelName = channel.Name;
|
2013-12-22 22:46:03 -05:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-14 20:17:57 -05:00
|
|
|
|
return dto;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-22 22:46:03 -05:00
|
|
|
|
public SeriesTimerInfoDto GetSeriesTimerInfoDto(SeriesTimerInfo info, ILiveTvService service, string channelName)
|
2013-12-14 20:17:57 -05:00
|
|
|
|
{
|
|
|
|
|
var dto = new SeriesTimerInfoDto
|
|
|
|
|
{
|
|
|
|
|
Id = GetInternalSeriesTimerId(service.Name, info.Id).ToString("N"),
|
|
|
|
|
Overview = info.Overview,
|
|
|
|
|
EndDate = info.EndDate,
|
|
|
|
|
Name = info.Name,
|
|
|
|
|
StartDate = info.StartDate,
|
|
|
|
|
ExternalId = info.Id,
|
2013-12-18 00:44:46 -05:00
|
|
|
|
PrePaddingSeconds = info.PrePaddingSeconds,
|
|
|
|
|
PostPaddingSeconds = info.PostPaddingSeconds,
|
|
|
|
|
IsPostPaddingRequired = info.IsPostPaddingRequired,
|
|
|
|
|
IsPrePaddingRequired = info.IsPrePaddingRequired,
|
2013-12-14 20:17:57 -05:00
|
|
|
|
Days = info.Days,
|
|
|
|
|
Priority = info.Priority,
|
2013-12-16 13:44:03 -05:00
|
|
|
|
RecordAnyChannel = info.RecordAnyChannel,
|
|
|
|
|
RecordAnyTime = info.RecordAnyTime,
|
2016-09-21 17:09:14 -04:00
|
|
|
|
SkipEpisodesInLibrary = info.SkipEpisodesInLibrary,
|
|
|
|
|
KeepUpTo = info.KeepUpTo,
|
2016-09-26 14:59:18 -04:00
|
|
|
|
KeepUntil = info.KeepUntil,
|
2013-12-16 13:44:03 -05:00
|
|
|
|
RecordNewOnly = info.RecordNewOnly,
|
2013-12-14 20:17:57 -05:00
|
|
|
|
ExternalChannelId = info.ChannelId,
|
2013-12-15 09:19:24 -05:00
|
|
|
|
ExternalProgramId = info.ProgramId,
|
2013-12-22 22:46:03 -05:00
|
|
|
|
ServiceName = service.Name,
|
2014-10-29 21:17:31 -04:00
|
|
|
|
ChannelName = channelName,
|
2015-08-16 18:03:22 -04:00
|
|
|
|
ServerId = _appHost.SystemId
|
2013-12-14 20:17:57 -05:00
|
|
|
|
};
|
|
|
|
|
|
2013-12-15 09:19:24 -05:00
|
|
|
|
if (!string.IsNullOrEmpty(info.ChannelId))
|
|
|
|
|
{
|
2013-12-22 22:46:03 -05:00
|
|
|
|
dto.ChannelId = GetInternalChannelId(service.Name, info.ChannelId).ToString("N");
|
2013-12-15 09:19:24 -05:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-14 20:17:57 -05:00
|
|
|
|
if (!string.IsNullOrEmpty(info.ProgramId))
|
|
|
|
|
{
|
|
|
|
|
dto.ProgramId = GetInternalProgramId(service.Name, info.ProgramId).ToString("N");
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-18 00:44:46 -05:00
|
|
|
|
dto.DayPattern = info.Days == null ? null : GetDayPattern(info.Days);
|
|
|
|
|
|
2016-12-17 21:35:21 -05:00
|
|
|
|
FillImages(dto, info.Name, info.SeriesId);
|
2016-11-17 13:18:19 -05:00
|
|
|
|
|
|
|
|
|
return dto;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-17 21:35:21 -05:00
|
|
|
|
private void FillImages(BaseItemDto dto, string seriesName, string programSeriesId)
|
2016-11-17 13:18:19 -05:00
|
|
|
|
{
|
|
|
|
|
var librarySeries = _libraryManager.GetItemList(new InternalItemsQuery
|
|
|
|
|
{
|
|
|
|
|
IncludeItemTypes = new string[] { typeof(Series).Name },
|
2016-12-17 21:35:21 -05:00
|
|
|
|
Name = seriesName,
|
|
|
|
|
Limit = 1,
|
|
|
|
|
ImageTypes = new ImageType[] { ImageType.Thumb }
|
|
|
|
|
|
|
|
|
|
}).FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
if (librarySeries != null)
|
|
|
|
|
{
|
|
|
|
|
var image = librarySeries.GetImageInfo(ImageType.Thumb, 0);
|
|
|
|
|
if (image != null)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
dto.ParentThumbImageTag = _imageProcessor.GetImageCacheTag(librarySeries, image);
|
|
|
|
|
dto.ParentThumbItemId = librarySeries.Id.ToString("N");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-17 23:58:20 -05:00
|
|
|
|
image = librarySeries.GetImageInfo(ImageType.Backdrop, 0);
|
|
|
|
|
if (image != null)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
dto.ParentBackdropImageTags = new List<string>
|
|
|
|
|
{
|
|
|
|
|
_imageProcessor.GetImageCacheTag(librarySeries, image)
|
|
|
|
|
};
|
|
|
|
|
dto.ParentBackdropItemId = librarySeries.Id.ToString("N");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-17 21:35:21 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(programSeriesId))
|
|
|
|
|
{
|
|
|
|
|
var program = _libraryManager.GetItemList(new InternalItemsQuery
|
|
|
|
|
{
|
|
|
|
|
IncludeItemTypes = new string[] { typeof(LiveTvProgram).Name },
|
|
|
|
|
ExternalSeriesId = programSeriesId,
|
|
|
|
|
Limit = 1,
|
|
|
|
|
ImageTypes = new ImageType[] { ImageType.Primary }
|
|
|
|
|
|
|
|
|
|
}).FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
if (program != null)
|
|
|
|
|
{
|
|
|
|
|
var image = program.GetImageInfo(ImageType.Primary, 0);
|
|
|
|
|
if (image != null)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
dto.ParentPrimaryImageTag = _imageProcessor.GetImageCacheTag(program, image);
|
|
|
|
|
dto.ParentPrimaryImageItemId = program.Id.ToString("N");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-17 23:58:20 -05:00
|
|
|
|
|
|
|
|
|
if (dto.ParentBackdropImageTags == null || dto.ParentBackdropImageTags.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
image = program.GetImageInfo(ImageType.Backdrop, 0);
|
|
|
|
|
if (image != null)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
dto.ParentBackdropImageTags = new List<string>
|
|
|
|
|
{
|
|
|
|
|
_imageProcessor.GetImageCacheTag(program, image)
|
|
|
|
|
};
|
|
|
|
|
dto.ParentBackdropItemId = program.Id.ToString("N");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-17 21:35:21 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FillImages(SeriesTimerInfoDto dto, string seriesName, string programSeriesId)
|
|
|
|
|
{
|
|
|
|
|
var librarySeries = _libraryManager.GetItemList(new InternalItemsQuery
|
|
|
|
|
{
|
|
|
|
|
IncludeItemTypes = new string[] { typeof(Series).Name },
|
|
|
|
|
Name = seriesName,
|
2016-11-17 13:18:19 -05:00
|
|
|
|
Limit = 1,
|
|
|
|
|
ImageTypes = new ImageType[] { ImageType.Thumb }
|
|
|
|
|
|
|
|
|
|
}).FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
if (librarySeries != null)
|
|
|
|
|
{
|
|
|
|
|
var image = librarySeries.GetImageInfo(ImageType.Thumb, 0);
|
|
|
|
|
if (image != null)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
dto.ParentThumbImageTag = _imageProcessor.GetImageCacheTag(librarySeries, image);
|
|
|
|
|
dto.ParentThumbItemId = librarySeries.Id.ToString("N");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-17 23:58:20 -05:00
|
|
|
|
image = librarySeries.GetImageInfo(ImageType.Backdrop, 0);
|
|
|
|
|
if (image != null)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
dto.ParentBackdropImageTags = new List<string>
|
|
|
|
|
{
|
|
|
|
|
_imageProcessor.GetImageCacheTag(librarySeries, image)
|
|
|
|
|
};
|
|
|
|
|
dto.ParentBackdropItemId = librarySeries.Id.ToString("N");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-17 13:18:19 -05:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-17 21:35:21 -05:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(programSeriesId))
|
2016-10-09 03:18:43 -04:00
|
|
|
|
{
|
|
|
|
|
var program = _libraryManager.GetItemList(new InternalItemsQuery
|
2017-02-15 16:19:07 -05:00
|
|
|
|
{
|
|
|
|
|
IncludeItemTypes = new string[] { typeof(Series).Name },
|
|
|
|
|
Name = seriesName,
|
|
|
|
|
Limit = 1,
|
|
|
|
|
ImageTypes = new ImageType[] { ImageType.Primary }
|
|
|
|
|
|
|
|
|
|
}).FirstOrDefault() ?? _libraryManager.GetItemList(new InternalItemsQuery
|
2016-10-09 03:18:43 -04:00
|
|
|
|
{
|
|
|
|
|
IncludeItemTypes = new string[] { typeof(LiveTvProgram).Name },
|
2016-12-17 21:35:21 -05:00
|
|
|
|
ExternalSeriesId = programSeriesId,
|
2016-10-09 03:18:43 -04:00
|
|
|
|
Limit = 1,
|
|
|
|
|
ImageTypes = new ImageType[] { ImageType.Primary }
|
|
|
|
|
|
|
|
|
|
}).FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
if (program != null)
|
|
|
|
|
{
|
|
|
|
|
var image = program.GetImageInfo(ImageType.Primary, 0);
|
|
|
|
|
if (image != null)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
dto.ParentPrimaryImageTag = _imageProcessor.GetImageCacheTag(program, image);
|
|
|
|
|
dto.ParentPrimaryImageItemId = program.Id.ToString("N");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-17 23:58:20 -05:00
|
|
|
|
|
|
|
|
|
if (dto.ParentBackdropImageTags == null || dto.ParentBackdropImageTags.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
image = program.GetImageInfo(ImageType.Backdrop, 0);
|
|
|
|
|
if (image != null)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
dto.ParentBackdropImageTags = new List<string>
|
|
|
|
|
{
|
|
|
|
|
_imageProcessor.GetImageCacheTag(program, image)
|
|
|
|
|
};
|
|
|
|
|
dto.ParentBackdropItemId = program.Id.ToString("N");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-09 03:18:43 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-18 00:44:46 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DayPattern? GetDayPattern(List<DayOfWeek> days)
|
|
|
|
|
{
|
2013-12-14 20:17:57 -05:00
|
|
|
|
DayPattern? pattern = null;
|
|
|
|
|
|
2013-12-18 00:44:46 -05:00
|
|
|
|
if (days.Count > 0)
|
2013-12-14 20:17:57 -05:00
|
|
|
|
{
|
2013-12-18 00:44:46 -05:00
|
|
|
|
if (days.Count == 7)
|
2013-12-14 20:17:57 -05:00
|
|
|
|
{
|
|
|
|
|
pattern = DayPattern.Daily;
|
|
|
|
|
}
|
2013-12-18 00:44:46 -05:00
|
|
|
|
else if (days.Count == 2)
|
2013-12-14 20:17:57 -05:00
|
|
|
|
{
|
2013-12-18 00:44:46 -05:00
|
|
|
|
if (days.Contains(DayOfWeek.Saturday) && days.Contains(DayOfWeek.Sunday))
|
2013-12-14 20:17:57 -05:00
|
|
|
|
{
|
|
|
|
|
pattern = DayPattern.Weekends;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-18 00:44:46 -05:00
|
|
|
|
else if (days.Count == 5)
|
2013-12-14 20:17:57 -05:00
|
|
|
|
{
|
2013-12-18 00:44:46 -05: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 20:17:57 -05:00
|
|
|
|
{
|
|
|
|
|
pattern = DayPattern.Weekdays;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-18 00:44:46 -05:00
|
|
|
|
return pattern;
|
2013-12-14 20:17:57 -05:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-24 13:09:50 -05:00
|
|
|
|
public LiveTvTunerInfoDto GetTunerInfoDto(string serviceName, LiveTvTunerInfo info, string channelName)
|
2014-01-23 17:15:15 -05:00
|
|
|
|
{
|
|
|
|
|
var dto = new LiveTvTunerInfoDto
|
|
|
|
|
{
|
|
|
|
|
Name = info.Name,
|
|
|
|
|
Id = info.Id,
|
|
|
|
|
Clients = info.Clients,
|
|
|
|
|
ProgramName = info.ProgramName,
|
|
|
|
|
SourceType = info.SourceType,
|
2014-01-24 13:09:50 -05:00
|
|
|
|
Status = info.Status,
|
2015-04-18 02:15:31 -04:00
|
|
|
|
ChannelName = channelName,
|
2016-02-21 12:37:57 -05:00
|
|
|
|
Url = info.Url,
|
|
|
|
|
CanReset = info.CanReset
|
2014-01-23 17:15:15 -05:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(info.ChannelId))
|
|
|
|
|
{
|
|
|
|
|
dto.ChannelId = GetInternalChannelId(serviceName, info.ChannelId).ToString("N");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(info.RecordingId))
|
|
|
|
|
{
|
|
|
|
|
dto.RecordingId = GetInternalRecordingId(serviceName, info.RecordingId).ToString("N");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dto;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-31 14:22:51 -04:00
|
|
|
|
internal string GetImageTag(IHasImages info)
|
2013-12-14 20:17:57 -05:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2014-02-07 15:30:41 -05:00
|
|
|
|
return _imageProcessor.GetImageCacheTag(info, ImageType.Primary);
|
2013-12-14 20:17:57 -05:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2013-12-19 16:51:32 -05:00
|
|
|
|
_logger.ErrorException("Error getting image info for {0}", ex, info.Name);
|
2013-12-14 20:17:57 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-25 13:11:49 -05:00
|
|
|
|
private const string InternalVersionNumber = "4";
|
2014-01-01 13:26:31 -05:00
|
|
|
|
|
2013-12-22 22:46:03 -05:00
|
|
|
|
public Guid GetInternalChannelId(string serviceName, string externalId)
|
2013-12-14 20:17:57 -05:00
|
|
|
|
{
|
2014-01-01 13:26:31 -05:00
|
|
|
|
var name = serviceName + externalId + InternalVersionNumber;
|
2013-12-14 20:17:57 -05:00
|
|
|
|
|
2016-03-24 02:04:58 -04:00
|
|
|
|
return _libraryManager.GetNewItemId(name.ToLower(), typeof(LiveTvChannel));
|
2013-12-14 20:17:57 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Guid GetInternalTimerId(string serviceName, string externalId)
|
|
|
|
|
{
|
2014-01-01 13:26:31 -05:00
|
|
|
|
var name = serviceName + externalId + InternalVersionNumber;
|
2013-12-14 20:17:57 -05:00
|
|
|
|
|
|
|
|
|
return name.ToLower().GetMD5();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Guid GetInternalSeriesTimerId(string serviceName, string externalId)
|
|
|
|
|
{
|
2014-01-01 13:26:31 -05:00
|
|
|
|
var name = serviceName + externalId + InternalVersionNumber;
|
2013-12-14 20:17:57 -05:00
|
|
|
|
|
|
|
|
|
return name.ToLower().GetMD5();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Guid GetInternalProgramId(string serviceName, string externalId)
|
|
|
|
|
{
|
2014-01-01 13:26:31 -05:00
|
|
|
|
var name = serviceName + externalId + InternalVersionNumber;
|
2013-12-14 20:17:57 -05:00
|
|
|
|
|
2016-03-24 02:04:58 -04:00
|
|
|
|
return _libraryManager.GetNewItemId(name.ToLower(), typeof(LiveTvProgram));
|
2013-12-14 20:17:57 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Guid GetInternalRecordingId(string serviceName, string externalId)
|
|
|
|
|
{
|
2015-06-01 13:07:55 -04:00
|
|
|
|
var name = serviceName + externalId + InternalVersionNumber + "0";
|
2013-12-14 20:17:57 -05:00
|
|
|
|
|
2016-03-24 02:04:58 -04:00
|
|
|
|
return _libraryManager.GetNewItemId(name.ToLower(), typeof(ILiveTvRecording));
|
2013-12-14 20:17:57 -05:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-13 16:04:21 -05:00
|
|
|
|
private string GetItemExternalId(BaseItem item)
|
|
|
|
|
{
|
|
|
|
|
var externalId = item.ExternalId;
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(externalId))
|
|
|
|
|
{
|
|
|
|
|
externalId = item.GetProviderId("ProviderExternalId");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return externalId;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-31 15:12:58 -04:00
|
|
|
|
public async Task<TimerInfo> GetTimerInfo(TimerInfoDto dto, bool isNew, LiveTvManager liveTv, CancellationToken cancellationToken)
|
2013-12-14 20:17:57 -05:00
|
|
|
|
{
|
2013-12-17 15:02:12 -05:00
|
|
|
|
var info = new TimerInfo
|
2013-12-14 20:17:57 -05:00
|
|
|
|
{
|
|
|
|
|
Overview = dto.Overview,
|
|
|
|
|
EndDate = dto.EndDate,
|
|
|
|
|
Name = dto.Name,
|
|
|
|
|
StartDate = dto.StartDate,
|
|
|
|
|
Status = dto.Status,
|
2013-12-18 00:44:46 -05:00
|
|
|
|
PrePaddingSeconds = dto.PrePaddingSeconds,
|
|
|
|
|
PostPaddingSeconds = dto.PostPaddingSeconds,
|
|
|
|
|
IsPostPaddingRequired = dto.IsPostPaddingRequired,
|
|
|
|
|
IsPrePaddingRequired = dto.IsPrePaddingRequired,
|
2016-09-27 01:13:56 -04:00
|
|
|
|
KeepUntil = dto.KeepUntil,
|
2013-12-19 16:51:32 -05:00
|
|
|
|
Priority = dto.Priority,
|
|
|
|
|
SeriesTimerId = dto.ExternalSeriesTimerId,
|
|
|
|
|
ProgramId = dto.ExternalProgramId,
|
|
|
|
|
ChannelId = dto.ExternalChannelId,
|
|
|
|
|
Id = dto.ExternalId
|
2013-12-14 20:17:57 -05:00
|
|
|
|
};
|
2013-12-17 15:02:12 -05:00
|
|
|
|
|
|
|
|
|
// Convert internal server id's to external tv provider id's
|
2013-12-19 16:51:32 -05:00
|
|
|
|
if (!isNew && !string.IsNullOrEmpty(dto.Id) && string.IsNullOrEmpty(info.Id))
|
2013-12-17 15:02:12 -05:00
|
|
|
|
{
|
2013-12-19 16:51:32 -05:00
|
|
|
|
var timer = await liveTv.GetSeriesTimer(dto.Id, cancellationToken).ConfigureAwait(false);
|
2013-12-17 15:02:12 -05:00
|
|
|
|
|
|
|
|
|
info.Id = timer.ExternalId;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 16:51:32 -05:00
|
|
|
|
if (!string.IsNullOrEmpty(dto.ChannelId) && string.IsNullOrEmpty(info.ChannelId))
|
2013-12-17 15:02:12 -05:00
|
|
|
|
{
|
2016-03-22 02:49:36 -04:00
|
|
|
|
var channel = liveTv.GetInternalChannel(dto.ChannelId);
|
2013-12-17 15:02:12 -05:00
|
|
|
|
|
2013-12-19 16:51:32 -05:00
|
|
|
|
if (channel != null)
|
|
|
|
|
{
|
2016-11-13 16:04:21 -05:00
|
|
|
|
info.ChannelId = GetItemExternalId(channel);
|
2013-12-19 16:51:32 -05:00
|
|
|
|
}
|
2013-12-17 15:02:12 -05:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 16:51:32 -05:00
|
|
|
|
if (!string.IsNullOrEmpty(dto.ProgramId) && string.IsNullOrEmpty(info.ProgramId))
|
2013-12-17 15:02:12 -05:00
|
|
|
|
{
|
2015-05-31 15:12:58 -04:00
|
|
|
|
var program = liveTv.GetInternalProgram(dto.ProgramId);
|
2013-12-17 15:02:12 -05:00
|
|
|
|
|
2013-12-19 16:51:32 -05:00
|
|
|
|
if (program != null)
|
|
|
|
|
{
|
2016-11-13 16:04:21 -05:00
|
|
|
|
info.ProgramId = GetItemExternalId(program);
|
2013-12-19 16:51:32 -05:00
|
|
|
|
}
|
2013-12-17 15:02:12 -05:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 16:51:32 -05:00
|
|
|
|
if (!string.IsNullOrEmpty(dto.SeriesTimerId) && string.IsNullOrEmpty(info.SeriesTimerId))
|
2013-12-17 15:02:12 -05:00
|
|
|
|
{
|
2013-12-19 16:51:32 -05:00
|
|
|
|
var timer = await liveTv.GetSeriesTimer(dto.SeriesTimerId, cancellationToken).ConfigureAwait(false);
|
2013-12-17 15:02:12 -05:00
|
|
|
|
|
2013-12-19 16:51:32 -05:00
|
|
|
|
if (timer != null)
|
|
|
|
|
{
|
|
|
|
|
info.SeriesTimerId = timer.ExternalId;
|
|
|
|
|
}
|
2013-12-17 15:02:12 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return info;
|
2013-12-14 20:17:57 -05:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-31 15:12:58 -04:00
|
|
|
|
public async Task<SeriesTimerInfo> GetSeriesTimerInfo(SeriesTimerInfoDto dto, bool isNew, LiveTvManager liveTv, CancellationToken cancellationToken)
|
2013-12-14 20:17:57 -05:00
|
|
|
|
{
|
2013-12-17 15:02:12 -05:00
|
|
|
|
var info = new SeriesTimerInfo
|
2013-12-14 20:17:57 -05:00
|
|
|
|
{
|
|
|
|
|
Overview = dto.Overview,
|
|
|
|
|
EndDate = dto.EndDate,
|
|
|
|
|
Name = dto.Name,
|
|
|
|
|
StartDate = dto.StartDate,
|
2013-12-18 00:44:46 -05:00
|
|
|
|
PrePaddingSeconds = dto.PrePaddingSeconds,
|
|
|
|
|
PostPaddingSeconds = dto.PostPaddingSeconds,
|
|
|
|
|
IsPostPaddingRequired = dto.IsPostPaddingRequired,
|
|
|
|
|
IsPrePaddingRequired = dto.IsPrePaddingRequired,
|
2013-12-14 20:17:57 -05:00
|
|
|
|
Days = dto.Days,
|
|
|
|
|
Priority = dto.Priority,
|
2013-12-16 13:44:03 -05:00
|
|
|
|
RecordAnyChannel = dto.RecordAnyChannel,
|
|
|
|
|
RecordAnyTime = dto.RecordAnyTime,
|
2016-09-21 17:09:14 -04:00
|
|
|
|
SkipEpisodesInLibrary = dto.SkipEpisodesInLibrary,
|
|
|
|
|
KeepUpTo = dto.KeepUpTo,
|
2016-09-26 14:59:18 -04:00
|
|
|
|
KeepUntil = dto.KeepUntil,
|
2013-12-19 16:51:32 -05:00
|
|
|
|
RecordNewOnly = dto.RecordNewOnly,
|
|
|
|
|
ProgramId = dto.ExternalProgramId,
|
|
|
|
|
ChannelId = dto.ExternalChannelId,
|
2015-08-16 18:03:22 -04:00
|
|
|
|
Id = dto.ExternalId
|
2013-12-14 20:17:57 -05:00
|
|
|
|
};
|
2013-12-17 15:02:12 -05:00
|
|
|
|
|
|
|
|
|
// Convert internal server id's to external tv provider id's
|
2013-12-19 16:51:32 -05:00
|
|
|
|
if (!isNew && !string.IsNullOrEmpty(dto.Id) && string.IsNullOrEmpty(info.Id))
|
2013-12-17 15:02:12 -05:00
|
|
|
|
{
|
|
|
|
|
var timer = await liveTv.GetSeriesTimer(dto.Id, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
info.Id = timer.ExternalId;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 16:51:32 -05:00
|
|
|
|
if (!string.IsNullOrEmpty(dto.ChannelId) && string.IsNullOrEmpty(info.ChannelId))
|
2013-12-17 15:02:12 -05:00
|
|
|
|
{
|
2016-03-22 02:49:36 -04:00
|
|
|
|
var channel = liveTv.GetInternalChannel(dto.ChannelId);
|
2013-12-17 15:02:12 -05:00
|
|
|
|
|
2013-12-19 16:51:32 -05:00
|
|
|
|
if (channel != null)
|
|
|
|
|
{
|
2016-11-13 16:04:21 -05:00
|
|
|
|
info.ChannelId = GetItemExternalId(channel);
|
2013-12-19 16:51:32 -05:00
|
|
|
|
}
|
2013-12-17 15:02:12 -05:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 16:51:32 -05:00
|
|
|
|
if (!string.IsNullOrEmpty(dto.ProgramId) && string.IsNullOrEmpty(info.ProgramId))
|
2013-12-17 15:02:12 -05:00
|
|
|
|
{
|
2015-05-31 15:12:58 -04:00
|
|
|
|
var program = liveTv.GetInternalProgram(dto.ProgramId);
|
2013-12-17 15:02:12 -05:00
|
|
|
|
|
2013-12-19 16:51:32 -05:00
|
|
|
|
if (program != null)
|
|
|
|
|
{
|
2016-11-13 16:04:21 -05:00
|
|
|
|
info.ProgramId = GetItemExternalId(program);
|
2013-12-19 16:51:32 -05:00
|
|
|
|
}
|
2013-12-17 15:02:12 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return info;
|
2013-12-14 20:17:57 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|