2013-12-18 00:44:46 -05:00
|
|
|
|
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;
|
2014-01-01 13:26:31 -05:00
|
|
|
|
using MediaBrowser.Controller.Persistence;
|
2013-12-14 20:17:57 -05:00
|
|
|
|
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;
|
2014-01-01 13:26:31 -05:00
|
|
|
|
using System.Linq;
|
2013-12-18 00:44:46 -05:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2013-12-14 20:17:57 -05:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Server.Implementations.LiveTv
|
|
|
|
|
{
|
|
|
|
|
public class LiveTvDtoService
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly IImageProcessor _imageProcessor;
|
|
|
|
|
|
|
|
|
|
private readonly IUserDataManager _userDataManager;
|
|
|
|
|
private readonly IDtoService _dtoService;
|
2014-01-01 13:26:31 -05:00
|
|
|
|
private readonly IItemRepository _itemRepo;
|
2013-12-14 20:17:57 -05:00
|
|
|
|
|
2014-01-01 13:26:31 -05:00
|
|
|
|
public LiveTvDtoService(IDtoService dtoService, IUserDataManager userDataManager, IImageProcessor imageProcessor, ILogger logger, IItemRepository itemRepo)
|
2013-12-14 20:17:57 -05:00
|
|
|
|
{
|
|
|
|
|
_dtoService = dtoService;
|
|
|
|
|
_userDataManager = userDataManager;
|
|
|
|
|
_imageProcessor = imageProcessor;
|
|
|
|
|
_logger = logger;
|
2014-01-01 13:26:31 -05:00
|
|
|
|
_itemRepo = itemRepo;
|
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,
|
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,
|
|
|
|
|
RunTimeTicks = (info.EndDate - info.StartDate).Ticks
|
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)
|
|
|
|
|
{
|
2014-01-17 15:51:29 -05:00
|
|
|
|
dto.ProgramInfo = GetProgramInfoDto(program, channel);
|
2013-12-22 12:16:24 -05:00
|
|
|
|
|
|
|
|
|
dto.ProgramInfo.TimerId = dto.Id;
|
|
|
|
|
dto.ProgramInfo.SeriesTimerId = dto.SeriesTimerId;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-22 22:46:03 -05:00
|
|
|
|
if (channel != null)
|
|
|
|
|
{
|
|
|
|
|
dto.ChannelName = channel.ChannelInfo.Name;
|
|
|
|
|
}
|
|
|
|
|
|
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,
|
|
|
|
|
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,
|
|
|
|
|
ChannelName = channelName
|
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);
|
|
|
|
|
|
|
|
|
|
return dto;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 16:51:32 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Convert the provider 0-5 scale to our 0-10 scale
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="val"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private float? GetClientCommunityRating(float? val)
|
|
|
|
|
{
|
|
|
|
|
if (!val.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-13 00:41:00 -05:00
|
|
|
|
return val.Value;
|
2013-12-19 16:51:32 -05:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-28 16:37:01 -05:00
|
|
|
|
public string GetStatusName(RecordingStatus status)
|
|
|
|
|
{
|
|
|
|
|
if (status == RecordingStatus.InProgress)
|
|
|
|
|
{
|
|
|
|
|
return "In Progress";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (status == RecordingStatus.ConflictedNotOk)
|
|
|
|
|
{
|
|
|
|
|
return "Conflicted";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (status == RecordingStatus.ConflictedOk)
|
|
|
|
|
{
|
|
|
|
|
return "Scheduled";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return status.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-01 13:26:31 -05:00
|
|
|
|
public RecordingInfoDto GetRecordingInfoDto(ILiveTvRecording recording, LiveTvChannel channel, ILiveTvService service, User user = null)
|
2013-12-14 20:17:57 -05:00
|
|
|
|
{
|
2013-12-19 16:51:32 -05:00
|
|
|
|
var info = recording.RecordingInfo;
|
2013-12-28 16:37:01 -05:00
|
|
|
|
|
2013-12-14 20:17:57 -05:00
|
|
|
|
var dto = new RecordingInfoDto
|
|
|
|
|
{
|
|
|
|
|
Id = GetInternalRecordingId(service.Name, info.Id).ToString("N"),
|
2013-12-22 12:16:24 -05:00
|
|
|
|
SeriesTimerId = string.IsNullOrEmpty(info.SeriesTimerId) ? null : GetInternalSeriesTimerId(service.Name, info.SeriesTimerId).ToString("N"),
|
2013-12-19 16:51:32 -05:00
|
|
|
|
Type = recording.GetClientTypeName(),
|
2013-12-14 20:17:57 -05:00
|
|
|
|
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,
|
2013-12-28 16:37:01 -05:00
|
|
|
|
StatusName = GetStatusName(info.Status),
|
2013-12-14 20:17:57 -05:00
|
|
|
|
Path = info.Path,
|
|
|
|
|
Genres = info.Genres,
|
|
|
|
|
IsRepeat = info.IsRepeat,
|
|
|
|
|
EpisodeTitle = info.EpisodeTitle,
|
|
|
|
|
ChannelType = info.ChannelType,
|
|
|
|
|
MediaType = info.ChannelType == ChannelType.Radio ? MediaType.Audio : MediaType.Video,
|
2013-12-19 16:51:32 -05:00
|
|
|
|
CommunityRating = GetClientCommunityRating(info.CommunityRating),
|
2013-12-14 20:17:57 -05:00
|
|
|
|
OfficialRating = info.OfficialRating,
|
|
|
|
|
Audio = info.Audio,
|
2013-12-15 09:19:24 -05:00
|
|
|
|
IsHD = info.IsHD,
|
2013-12-16 13:44:03 -05:00
|
|
|
|
ServiceName = service.Name,
|
2013-12-20 15:09:49 -05:00
|
|
|
|
IsMovie = info.IsMovie,
|
|
|
|
|
IsSeries = info.IsSeries,
|
|
|
|
|
IsSports = info.IsSports,
|
|
|
|
|
IsLive = info.IsLive,
|
|
|
|
|
IsNews = info.IsNews,
|
|
|
|
|
IsKids = info.IsKids,
|
|
|
|
|
IsPremiere = info.IsPremiere,
|
2014-01-01 13:26:31 -05:00
|
|
|
|
RunTimeTicks = (info.EndDate - info.StartDate).Ticks,
|
2014-01-13 00:41:00 -05:00
|
|
|
|
OriginalAirDate = info.OriginalAirDate,
|
2014-01-01 13:26:31 -05:00
|
|
|
|
|
|
|
|
|
MediaStreams = _itemRepo.GetMediaStreams(new MediaStreamQuery
|
|
|
|
|
{
|
|
|
|
|
ItemId = recording.Id
|
|
|
|
|
|
|
|
|
|
}).ToList()
|
2013-12-14 20:17:57 -05:00
|
|
|
|
};
|
|
|
|
|
|
2014-01-14 15:24:56 -05:00
|
|
|
|
if (info.Status == RecordingStatus.InProgress)
|
|
|
|
|
{
|
|
|
|
|
var now = DateTime.UtcNow.Ticks;
|
|
|
|
|
var start = info.StartDate.Ticks;
|
|
|
|
|
var end = info.EndDate.Ticks;
|
|
|
|
|
|
|
|
|
|
var pct = now - start;
|
|
|
|
|
pct /= end;
|
|
|
|
|
pct *= 100;
|
|
|
|
|
dto.CompletionPercentage = pct;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 16:51:32 -05:00
|
|
|
|
var imageTag = GetImageTag(recording);
|
|
|
|
|
|
|
|
|
|
if (imageTag.HasValue)
|
|
|
|
|
{
|
|
|
|
|
dto.ImageTags[ImageType.Primary] = imageTag.Value;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-14 20:17:57 -05:00
|
|
|
|
if (user != null)
|
|
|
|
|
{
|
2013-12-19 16:51:32 -05:00
|
|
|
|
dto.UserData = _dtoService.GetUserItemDataDto(_userDataManager.GetUserData(user.Id, recording.GetUserDataKey()));
|
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 22:46:03 -05:00
|
|
|
|
if (channel != null)
|
|
|
|
|
{
|
2014-01-17 15:51:29 -05:00
|
|
|
|
dto.ChannelName = channel.Name;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(channel.PrimaryImagePath))
|
|
|
|
|
{
|
|
|
|
|
dto.ChannelPrimaryImageTag = GetImageTag(channel);
|
|
|
|
|
}
|
2013-12-22 22:46:03 -05:00
|
|
|
|
}
|
2013-12-28 16:37:01 -05:00
|
|
|
|
|
2013-12-14 20:17:57 -05:00
|
|
|
|
return dto;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the channel info dto.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="info">The info.</param>
|
2014-01-02 16:21:06 -05:00
|
|
|
|
/// <param name="currentProgram">The current program.</param>
|
2013-12-14 20:17:57 -05:00
|
|
|
|
/// <param name="user">The user.</param>
|
|
|
|
|
/// <returns>ChannelInfoDto.</returns>
|
2014-01-02 16:21:06 -05:00
|
|
|
|
public ChannelInfoDto GetChannelInfoDto(LiveTvChannel info, LiveTvProgram currentProgram, User user = null)
|
2013-12-14 20:17:57 -05:00
|
|
|
|
{
|
2013-12-19 16:51:32 -05:00
|
|
|
|
var channelInfo = info.ChannelInfo;
|
|
|
|
|
|
2013-12-14 20:17:57 -05:00
|
|
|
|
var dto = new ChannelInfoDto
|
|
|
|
|
{
|
|
|
|
|
Name = info.Name,
|
|
|
|
|
ServiceName = info.ServiceName,
|
2013-12-19 16:51:32 -05:00
|
|
|
|
ChannelType = channelInfo.ChannelType,
|
|
|
|
|
Number = channelInfo.Number,
|
|
|
|
|
Type = info.GetClientTypeName(),
|
2013-12-14 20:17:57 -05:00
|
|
|
|
Id = info.Id.ToString("N"),
|
2013-12-17 15:02:12 -05:00
|
|
|
|
MediaType = info.MediaType,
|
2013-12-19 16:51:32 -05:00
|
|
|
|
ExternalId = channelInfo.Id
|
2013-12-14 20:17:57 -05:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (user != null)
|
|
|
|
|
{
|
|
|
|
|
dto.UserData = _dtoService.GetUserItemDataDto(_userDataManager.GetUserData(user.Id, info.GetUserDataKey()));
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 16:51:32 -05:00
|
|
|
|
var imageTag = GetImageTag(info);
|
2013-12-14 20:17:57 -05:00
|
|
|
|
|
|
|
|
|
if (imageTag.HasValue)
|
|
|
|
|
{
|
|
|
|
|
dto.ImageTags[ImageType.Primary] = imageTag.Value;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-02 16:21:06 -05:00
|
|
|
|
if (currentProgram != null)
|
|
|
|
|
{
|
2014-01-17 15:51:29 -05:00
|
|
|
|
dto.CurrentProgram = GetProgramInfoDto(currentProgram, info, user);
|
2014-01-02 16:21:06 -05:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-14 20:17:57 -05:00
|
|
|
|
return dto;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-17 15:51:29 -05:00
|
|
|
|
public ProgramInfoDto GetProgramInfoDto(LiveTvProgram item, LiveTvChannel channel, User user = null)
|
2013-12-14 20:17:57 -05:00
|
|
|
|
{
|
2013-12-21 13:37:34 -05:00
|
|
|
|
var program = item.ProgramInfo;
|
2013-12-28 16:37:01 -05:00
|
|
|
|
|
2013-12-14 20:17:57 -05:00
|
|
|
|
var dto = new ProgramInfoDto
|
|
|
|
|
{
|
2013-12-21 13:37:34 -05:00
|
|
|
|
Id = GetInternalProgramId(item.ServiceName, program.Id).ToString("N"),
|
2013-12-22 22:46:03 -05:00
|
|
|
|
ChannelId = GetInternalChannelId(item.ServiceName, program.ChannelId).ToString("N"),
|
2013-12-14 20:17:57 -05:00
|
|
|
|
Overview = program.Overview,
|
|
|
|
|
EndDate = program.EndDate,
|
|
|
|
|
Genres = program.Genres,
|
|
|
|
|
ExternalId = program.Id,
|
|
|
|
|
Name = program.Name,
|
2013-12-21 13:37:34 -05:00
|
|
|
|
ServiceName = item.ServiceName,
|
2013-12-14 20:17:57 -05:00
|
|
|
|
StartDate = program.StartDate,
|
|
|
|
|
OfficialRating = program.OfficialRating,
|
|
|
|
|
IsHD = program.IsHD,
|
|
|
|
|
OriginalAirDate = program.OriginalAirDate,
|
|
|
|
|
Audio = program.Audio,
|
2013-12-19 16:51:32 -05:00
|
|
|
|
CommunityRating = GetClientCommunityRating(program.CommunityRating),
|
2013-12-14 20:17:57 -05:00
|
|
|
|
IsRepeat = program.IsRepeat,
|
2013-12-16 13:44:03 -05:00
|
|
|
|
EpisodeTitle = program.EpisodeTitle,
|
2013-12-18 00:44:46 -05:00
|
|
|
|
IsMovie = program.IsMovie,
|
|
|
|
|
IsSeries = program.IsSeries,
|
2013-12-20 15:09:49 -05:00
|
|
|
|
IsSports = program.IsSports,
|
|
|
|
|
IsLive = program.IsLive,
|
|
|
|
|
IsNews = program.IsNews,
|
|
|
|
|
IsKids = program.IsKids,
|
|
|
|
|
IsPremiere = program.IsPremiere,
|
2013-12-28 16:37:01 -05:00
|
|
|
|
RunTimeTicks = (program.EndDate - program.StartDate).Ticks,
|
|
|
|
|
Type = "Program"
|
2013-12-14 20:17:57 -05:00
|
|
|
|
};
|
|
|
|
|
|
2014-01-17 15:51:29 -05:00
|
|
|
|
if (channel != null)
|
|
|
|
|
{
|
|
|
|
|
dto.ChannelName = channel.Name;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(channel.PrimaryImagePath))
|
|
|
|
|
{
|
|
|
|
|
dto.ChannelPrimaryImageTag = GetImageTag(channel);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-28 16:37:01 -05:00
|
|
|
|
var imageTag = GetImageTag(item);
|
|
|
|
|
|
|
|
|
|
if (imageTag.HasValue)
|
|
|
|
|
{
|
|
|
|
|
dto.ImageTags[ImageType.Primary] = imageTag.Value;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-14 20:17:57 -05:00
|
|
|
|
if (user != null)
|
|
|
|
|
{
|
2013-12-21 13:37:34 -05:00
|
|
|
|
dto.UserData = _dtoService.GetUserItemDataDto(_userDataManager.GetUserData(user.Id, item.GetUserDataKey()));
|
2013-12-14 20:17:57 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dto;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-01 13:26:31 -05:00
|
|
|
|
private Guid? GetImageTag(IHasImages info)
|
2013-12-14 20:17:57 -05:00
|
|
|
|
{
|
|
|
|
|
var path = info.PrimaryImagePath;
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(path))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _imageProcessor.GetImageCacheTag(info, ImageType.Primary, path);
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-12 01:31:21 -05:00
|
|
|
|
private const string InternalVersionNumber = "3";
|
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
|
|
|
|
|
2013-12-19 16:51:32 -05:00
|
|
|
|
return name.ToLower().GetMBId(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
|
|
|
|
|
2014-01-01 13:26:31 -05:00
|
|
|
|
return name.ToLower().GetMBId(typeof(LiveTvProgram));
|
2013-12-14 20:17:57 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Guid GetInternalRecordingId(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
|
|
|
|
|
2014-01-01 13:26:31 -05:00
|
|
|
|
return name.ToLower().GetMBId(typeof(ILiveTvRecording));
|
2013-12-14 20:17:57 -05:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-17 15:02:12 -05:00
|
|
|
|
public async Task<TimerInfo> GetTimerInfo(TimerInfoDto dto, bool isNew, ILiveTvManager 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,
|
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
|
|
|
|
{
|
2013-12-19 16:51:32 -05:00
|
|
|
|
var channel = await liveTv.GetChannel(dto.ChannelId, cancellationToken).ConfigureAwait(false);
|
2013-12-17 15:02:12 -05:00
|
|
|
|
|
2013-12-19 16:51:32 -05:00
|
|
|
|
if (channel != null)
|
|
|
|
|
{
|
|
|
|
|
info.ChannelId = channel.ExternalId;
|
|
|
|
|
}
|
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
|
|
|
|
{
|
2013-12-19 16:51:32 -05:00
|
|
|
|
var program = await liveTv.GetProgram(dto.ProgramId, cancellationToken).ConfigureAwait(false);
|
2013-12-17 15:02:12 -05:00
|
|
|
|
|
2013-12-19 16:51:32 -05:00
|
|
|
|
if (program != null)
|
|
|
|
|
{
|
|
|
|
|
info.ProgramId = program.ExternalId;
|
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
|
2013-12-17 15:02:12 -05:00
|
|
|
|
public async Task<SeriesTimerInfo> GetSeriesTimerInfo(SeriesTimerInfoDto dto, bool isNew, ILiveTvManager 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,
|
2013-12-19 16:51:32 -05:00
|
|
|
|
RecordNewOnly = dto.RecordNewOnly,
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
var channel = await liveTv.GetChannel(dto.ChannelId, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
2013-12-19 16:51:32 -05:00
|
|
|
|
if (channel != null)
|
|
|
|
|
{
|
|
|
|
|
info.ChannelId = channel.ExternalId;
|
|
|
|
|
}
|
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
|
|
|
|
{
|
|
|
|
|
var program = await liveTv.GetProgram(dto.ProgramId, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
2013-12-19 16:51:32 -05:00
|
|
|
|
if (program != null)
|
|
|
|
|
{
|
|
|
|
|
info.ProgramId = program.ExternalId;
|
|
|
|
|
}
|
2013-12-17 15:02:12 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return info;
|
2013-12-14 20:17:57 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|