aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2013-12-14 20:17:57 -0500
committerLuke Pulverenti <luke.pulverenti@gmail.com>2013-12-14 20:17:57 -0500
commit01e65c93eeeddff27fc2e0e4833678c5cc2829a0 (patch)
tree628d2359e6d723c8f9f8865104e518add252bee1 /MediaBrowser.Server.Implementations
parentd576108411d254afcbefa627cea6a2d3585ab823 (diff)
updated live tv + nuget
Diffstat (limited to 'MediaBrowser.Server.Implementations')
-rw-r--r--MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs31
-rw-r--r--MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs38
-rw-r--r--MediaBrowser.Server.Implementations/LiveTv/ChannelImageProvider.cs8
-rw-r--r--MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs324
-rw-r--r--MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs296
-rw-r--r--MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj3
6 files changed, 463 insertions, 237 deletions
diff --git a/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs b/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs
index 8165e11eb..94438e3e0 100644
--- a/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs
+++ b/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs
@@ -69,10 +69,9 @@ namespace MediaBrowser.Server.Implementations.Configuration
/// </summary>
private void UpdateItemsByNamePath()
{
- if (!string.IsNullOrEmpty(Configuration.ItemsByNamePath))
- {
- ApplicationPaths.ItemsByNamePath = Configuration.ItemsByNamePath;
- }
+ ((ServerApplicationPaths) ApplicationPaths).ItemsByNamePath = string.IsNullOrEmpty(Configuration.ItemsByNamePath) ?
+ null :
+ Configuration.ItemsByNamePath;
}
/// <summary>
@@ -84,19 +83,29 @@ namespace MediaBrowser.Server.Implementations.Configuration
{
var newConfig = (ServerConfiguration) newConfiguration;
- var newIbnPath = newConfig.ItemsByNamePath;
+ ValidateItemByNamePath(newConfig);
+
+ base.ReplaceConfiguration(newConfiguration);
+ }
+
+ /// <summary>
+ /// Replaces the item by name path.
+ /// </summary>
+ /// <param name="newConfig">The new configuration.</param>
+ /// <exception cref="System.IO.DirectoryNotFoundException"></exception>
+ private void ValidateItemByNamePath(ServerConfiguration newConfig)
+ {
+ var newPath = newConfig.ItemsByNamePath;
- if (!string.IsNullOrWhiteSpace(newIbnPath)
- && !string.Equals(Configuration.ItemsByNamePath ?? string.Empty, newIbnPath))
+ if (!string.IsNullOrWhiteSpace(newPath)
+ && !string.Equals(Configuration.ItemsByNamePath ?? string.Empty, newPath))
{
// Validate
- if (!Directory.Exists(newIbnPath))
+ if (!Directory.Exists(newPath))
{
- throw new DirectoryNotFoundException(string.Format("{0} does not exist.", newConfig.ItemsByNamePath));
+ throw new DirectoryNotFoundException(string.Format("{0} does not exist.", newPath));
}
}
-
- base.ReplaceConfiguration(newConfiguration);
}
}
}
diff --git a/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs b/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs
index 27ce90787..36b6e5a90 100644
--- a/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs
+++ b/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs
@@ -53,10 +53,6 @@ namespace MediaBrowser.Server.Implementations.Drawing
private readonly IJsonSerializer _jsonSerializer;
private readonly IServerApplicationPaths _appPaths;
- private readonly string _croppedWhitespaceImageCachePath;
- private readonly string _enhancedImageCachePath;
- private readonly string _resizedImageCachePath;
-
public ImageProcessor(ILogger logger, IServerApplicationPaths appPaths, IFileSystem fileSystem, IJsonSerializer jsonSerializer)
{
_logger = logger;
@@ -64,10 +60,6 @@ namespace MediaBrowser.Server.Implementations.Drawing
_jsonSerializer = jsonSerializer;
_appPaths = appPaths;
- _croppedWhitespaceImageCachePath = Path.Combine(appPaths.ImageCachePath, "cropped-images");
- _enhancedImageCachePath = Path.Combine(appPaths.ImageCachePath, "enhanced-images");
- _resizedImageCachePath = Path.Combine(appPaths.ImageCachePath, "resized-images");
-
_saveImageSizeTimer = new Timer(SaveImageSizeCallback, null, Timeout.Infinite, Timeout.Infinite);
Dictionary<Guid, ImageSize> sizeDictionary;
@@ -92,6 +84,30 @@ namespace MediaBrowser.Server.Implementations.Drawing
_cachedImagedSizes = new ConcurrentDictionary<Guid, ImageSize>(sizeDictionary);
}
+ private string ResizedImageCachePath
+ {
+ get
+ {
+ return Path.Combine(_appPaths.ImageCachePath, "resized-images");
+ }
+ }
+
+ private string EnhancedImageCachePath
+ {
+ get
+ {
+ return Path.Combine(_appPaths.ImageCachePath, "enhanced-images");
+ }
+ }
+
+ private string CroppedWhitespaceImageCachePath
+ {
+ get
+ {
+ return Path.Combine(_appPaths.ImageCachePath, "cropped-images");
+ }
+ }
+
public void AddParts(IEnumerable<IImageEnhancer> enhancers)
{
ImageEnhancers = enhancers.ToArray();
@@ -391,7 +407,7 @@ namespace MediaBrowser.Server.Implementations.Drawing
var name = originalImagePath;
name += "datemodified=" + dateModified.Ticks;
- var croppedImagePath = GetCachePath(_croppedWhitespaceImageCachePath, name, Path.GetExtension(originalImagePath));
+ var croppedImagePath = GetCachePath(CroppedWhitespaceImageCachePath, name, Path.GetExtension(originalImagePath));
var semaphore = GetLock(croppedImagePath);
@@ -480,7 +496,7 @@ namespace MediaBrowser.Server.Implementations.Drawing
filename += "b=" + backgroundColor;
}
- return GetCachePath(_resizedImageCachePath, filename, Path.GetExtension(originalPath));
+ return GetCachePath(ResizedImageCachePath, filename, Path.GetExtension(originalPath));
}
/// <summary>
@@ -708,7 +724,7 @@ namespace MediaBrowser.Server.Implementations.Drawing
var cacheGuid = GetImageCacheTag(item, imageType, originalImagePath, dateModified, supportedEnhancers);
// All enhanced images are saved as png to allow transparency
- var enhancedImagePath = GetCachePath(_enhancedImageCachePath, cacheGuid + ".png");
+ var enhancedImagePath = GetCachePath(EnhancedImageCachePath, cacheGuid + ".png");
var semaphore = GetLock(enhancedImagePath);
diff --git a/MediaBrowser.Server.Implementations/LiveTv/ChannelImageProvider.cs b/MediaBrowser.Server.Implementations/LiveTv/ChannelImageProvider.cs
index 3a2413540..4a8b2d638 100644
--- a/MediaBrowser.Server.Implementations/LiveTv/ChannelImageProvider.cs
+++ b/MediaBrowser.Server.Implementations/LiveTv/ChannelImageProvider.cs
@@ -1,4 +1,5 @@
-using MediaBrowser.Controller.Configuration;
+using MediaBrowser.Common.IO;
+using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.LiveTv;
@@ -7,6 +8,7 @@ using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Net;
using System;
+using System.IO;
using System.Linq;
using System.Net;
using System.Threading;
@@ -18,12 +20,14 @@ namespace MediaBrowser.Server.Implementations.LiveTv
{
private readonly ILiveTvManager _liveTvManager;
private readonly IProviderManager _providerManager;
+ private readonly IFileSystem _fileSystem;
- public ChannelImageProvider(ILogManager logManager, IServerConfigurationManager configurationManager, ILiveTvManager liveTvManager, IProviderManager providerManager)
+ public ChannelImageProvider(ILogManager logManager, IServerConfigurationManager configurationManager, ILiveTvManager liveTvManager, IProviderManager providerManager, IFileSystem fileSystem)
: base(logManager, configurationManager)
{
_liveTvManager = liveTvManager;
_providerManager = providerManager;
+ _fileSystem = fileSystem;
}
public override bool Supports(BaseItem item)
diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs
new file mode 100644
index 000000000..f93821cc9
--- /dev/null
+++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs
@@ -0,0 +1,324 @@
+using MediaBrowser.Common.Extensions;
+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;
+
+namespace MediaBrowser.Server.Implementations.LiveTv
+{
+ public class LiveTvDtoService
+ {
+ private readonly ILogger _logger;
+ private readonly IImageProcessor _imageProcessor;
+
+ private readonly IUserDataManager _userDataManager;
+ private readonly IDtoService _dtoService;
+
+ public LiveTvDtoService(IDtoService dtoService, IUserDataManager userDataManager, IImageProcessor imageProcessor, ILogger logger)
+ {
+ _dtoService = dtoService;
+ _userDataManager = userDataManager;
+ _imageProcessor = imageProcessor;
+ _logger = logger;
+ }
+
+ public TimerInfoDto GetTimerInfoDto(TimerInfo info, ILiveTvService service)
+ {
+ var dto = new TimerInfoDto
+ {
+ Id = GetInternalTimerId(service.Name, info.Id).ToString("N"),
+ ChannelName = info.ChannelName,
+ Overview = info.Overview,
+ EndDate = info.EndDate,
+ Name = info.Name,
+ StartDate = info.StartDate,
+ ExternalId = info.Id,
+ ChannelId = GetInternalChannelId(service.Name, info.ChannelId, info.ChannelName).ToString("N"),
+ Status = info.Status,
+ SeriesTimerId = string.IsNullOrEmpty(info.SeriesTimerId) ? null : GetInternalSeriesTimerId(service.Name, info.SeriesTimerId).ToString("N"),
+ RequestedPostPaddingSeconds = info.RequestedPostPaddingSeconds,
+ RequestedPrePaddingSeconds = info.RequestedPrePaddingSeconds,
+ RequiredPostPaddingSeconds = info.RequiredPostPaddingSeconds,
+ RequiredPrePaddingSeconds = info.RequiredPrePaddingSeconds,
+ ExternalChannelId = info.ChannelId,
+ ExternalSeriesTimerId = info.SeriesTimerId
+ };
+
+ var duration = info.EndDate - info.StartDate;
+ dto.DurationMs = Convert.ToInt32(duration.TotalMilliseconds);
+
+ if (!string.IsNullOrEmpty(info.ProgramId))
+ {
+ dto.ProgramId = GetInternalProgramId(service.Name, info.ProgramId).ToString("N");
+ }
+
+ return dto;
+ }
+
+ public SeriesTimerInfoDto GetSeriesTimerInfoDto(SeriesTimerInfo info, ILiveTvService service)
+ {
+ var dto = new SeriesTimerInfoDto
+ {
+ Id = GetInternalSeriesTimerId(service.Name, info.Id).ToString("N"),
+ ChannelName = info.ChannelName,
+ Overview = info.Overview,
+ EndDate = info.EndDate,
+ Name = info.Name,
+ StartDate = info.StartDate,
+ ExternalId = info.Id,
+ ChannelId = GetInternalChannelId(service.Name, info.ChannelId, info.ChannelName).ToString("N"),
+ RequestedPostPaddingSeconds = info.RequestedPostPaddingSeconds,
+ RequestedPrePaddingSeconds = info.RequestedPrePaddingSeconds,
+ RequiredPostPaddingSeconds = info.RequiredPostPaddingSeconds,
+ RequiredPrePaddingSeconds = info.RequiredPrePaddingSeconds,
+ Days = info.Days,
+ Priority = info.Priority,
+ RecurrenceType = info.RecurrenceType,
+ ExternalChannelId = info.ChannelId,
+ ExternalProgramId = info.ProgramId
+ };
+
+ if (!string.IsNullOrEmpty(info.ProgramId))
+ {
+ dto.ProgramId = GetInternalProgramId(service.Name, info.ProgramId).ToString("N");
+ }
+
+ DayPattern? pattern = null;
+
+ if (info.Days != null && info.Days.Count > 0)
+ {
+ if (info.Days.Count == 7)
+ {
+ pattern = DayPattern.Daily;
+ }
+ else if (info.Days.Count == 2)
+ {
+ if (info.Days.Contains(DayOfWeek.Saturday) && info.Days.Contains(DayOfWeek.Sunday))
+ {
+ pattern = DayPattern.Weekends;
+ }
+ }
+ else if (info.Days.Count == 5)
+ {
+ if (info.Days.Contains(DayOfWeek.Monday) && info.Days.Contains(DayOfWeek.Tuesday) && info.Days.Contains(DayOfWeek.Wednesday) && info.Days.Contains(DayOfWeek.Thursday) && info.Days.Contains(DayOfWeek.Friday))
+ {
+ pattern = DayPattern.Weekdays;
+ }
+ }
+ }
+
+ dto.DayPattern = pattern;
+
+ return dto;
+ }
+
+ public RecordingInfoDto GetRecordingInfoDto(RecordingInfo info, ILiveTvService service, User user = null)
+ {
+ var dto = new RecordingInfoDto
+ {
+ Id = GetInternalRecordingId(service.Name, info.Id).ToString("N"),
+ ChannelName = info.ChannelName,
+ Overview = info.Overview,
+ EndDate = info.EndDate,
+ Name = info.Name,
+ StartDate = info.StartDate,
+ ExternalId = info.Id,
+ ChannelId = GetInternalChannelId(service.Name, info.ChannelId, info.ChannelName).ToString("N"),
+ Status = info.Status,
+ Path = info.Path,
+ Genres = info.Genres,
+ IsRepeat = info.IsRepeat,
+ EpisodeTitle = info.EpisodeTitle,
+ ChannelType = info.ChannelType,
+ MediaType = info.ChannelType == ChannelType.Radio ? MediaType.Audio : MediaType.Video,
+ CommunityRating = info.CommunityRating,
+ OfficialRating = info.OfficialRating,
+ Audio = info.Audio,
+ IsHD = info.IsHD
+ };
+
+ if (user != null)
+ {
+ //dto.UserData = _dtoService.GetUserItemDataDto(_userDataManager.GetUserData(user.Id, info.GetUserDataKey()));
+ }
+
+ var duration = info.EndDate - info.StartDate;
+ dto.DurationMs = Convert.ToInt32(duration.TotalMilliseconds);
+
+ if (!string.IsNullOrEmpty(info.ProgramId))
+ {
+ dto.ProgramId = GetInternalProgramId(service.Name, info.ProgramId).ToString("N");
+ }
+
+ return dto;
+ }
+
+ /// <summary>
+ /// Gets the channel info dto.
+ /// </summary>
+ /// <param name="info">The info.</param>
+ /// <param name="user">The user.</param>
+ /// <returns>ChannelInfoDto.</returns>
+ public ChannelInfoDto GetChannelInfoDto(Channel info, User user = null)
+ {
+ var dto = new ChannelInfoDto
+ {
+ Name = info.Name,
+ ServiceName = info.ServiceName,
+ ChannelType = info.ChannelType,
+ Number = info.ChannelNumber,
+ Type = info.GetType().Name,
+ Id = info.Id.ToString("N"),
+ MediaType = info.MediaType
+ };
+
+ if (user != null)
+ {
+ dto.UserData = _dtoService.GetUserItemDataDto(_userDataManager.GetUserData(user.Id, info.GetUserDataKey()));
+ }
+
+ var imageTag = GetLogoImageTag(info);
+
+ if (imageTag.HasValue)
+ {
+ dto.ImageTags[ImageType.Primary] = imageTag.Value;
+ }
+
+ return dto;
+ }
+
+ public ProgramInfoDto GetProgramInfoDto(ProgramInfo program, Channel channel, User user = null)
+ {
+ var dto = new ProgramInfoDto
+ {
+ Id = GetInternalProgramId(channel.ServiceName, program.Id).ToString("N"),
+ ChannelId = channel.Id.ToString("N"),
+ Overview = program.Overview,
+ EndDate = program.EndDate,
+ Genres = program.Genres,
+ ExternalId = program.Id,
+ Name = program.Name,
+ ServiceName = channel.ServiceName,
+ StartDate = program.StartDate,
+ OfficialRating = program.OfficialRating,
+ IsHD = program.IsHD,
+ OriginalAirDate = program.OriginalAirDate,
+ Audio = program.Audio,
+ CommunityRating = program.CommunityRating,
+ AspectRatio = program.AspectRatio,
+ IsRepeat = program.IsRepeat,
+ EpisodeTitle = program.EpisodeTitle
+ };
+
+ if (user != null)
+ {
+ //dto.UserData = _dtoService.GetUserItemDataDto(_userDataManager.GetUserData(user.Id, info.GetUserDataKey()));
+ }
+
+ return dto;
+ }
+
+ private Guid? GetLogoImageTag(Channel info)
+ {
+ var path = info.PrimaryImagePath;
+
+ if (string.IsNullOrEmpty(path))
+ {
+ return null;
+ }
+
+ try
+ {
+ return _imageProcessor.GetImageCacheTag(info, ImageType.Primary, path);
+ }
+ catch (Exception ex)
+ {
+ _logger.ErrorException("Error getting channel image info for {0}", ex, info.Name);
+ }
+
+ return null;
+ }
+
+ public Guid GetInternalChannelId(string serviceName, string externalId, string channelName)
+ {
+ var name = serviceName + externalId + channelName;
+
+ return name.ToLower().GetMBId(typeof(Channel));
+ }
+
+ public Guid GetInternalTimerId(string serviceName, string externalId)
+ {
+ var name = serviceName + externalId;
+
+ return name.ToLower().GetMD5();
+ }
+
+ public Guid GetInternalSeriesTimerId(string serviceName, string externalId)
+ {
+ var name = serviceName + externalId;
+
+ return name.ToLower().GetMD5();
+ }
+
+ public Guid GetInternalProgramId(string serviceName, string externalId)
+ {
+ var name = serviceName + externalId;
+
+ return name.ToLower().GetMD5();
+ }
+
+ public Guid GetInternalRecordingId(string serviceName, string externalId)
+ {
+ var name = serviceName + externalId;
+
+ return name.ToLower().GetMD5();
+ }
+
+ public TimerInfo GetTimerInfo(TimerInfoDto dto)
+ {
+ return new TimerInfo
+ {
+ Id = dto.ExternalId,
+ ChannelName = dto.ChannelName,
+ Overview = dto.Overview,
+ EndDate = dto.EndDate,
+ Name = dto.Name,
+ StartDate = dto.StartDate,
+ ChannelId = dto.ExternalChannelId,
+ Status = dto.Status,
+ SeriesTimerId = dto.ExternalSeriesTimerId,
+ RequestedPostPaddingSeconds = dto.RequestedPostPaddingSeconds,
+ RequestedPrePaddingSeconds = dto.RequestedPrePaddingSeconds,
+ RequiredPostPaddingSeconds = dto.RequiredPostPaddingSeconds,
+ RequiredPrePaddingSeconds = dto.RequiredPrePaddingSeconds
+ };
+ }
+
+ public SeriesTimerInfo GetSeriesTimerInfo(SeriesTimerInfoDto dto)
+ {
+ return new SeriesTimerInfo
+ {
+ Id = dto.ExternalId,
+ ChannelName = dto.ChannelName,
+ Overview = dto.Overview,
+ EndDate = dto.EndDate,
+ Name = dto.Name,
+ StartDate = dto.StartDate,
+ ChannelId = dto.ExternalChannelId,
+ RequestedPostPaddingSeconds = dto.RequestedPostPaddingSeconds,
+ RequestedPrePaddingSeconds = dto.RequestedPrePaddingSeconds,
+ RequiredPostPaddingSeconds = dto.RequiredPostPaddingSeconds,
+ RequiredPrePaddingSeconds = dto.RequiredPrePaddingSeconds,
+ Days = dto.Days,
+ Priority = dto.Priority,
+ RecurrenceType = dto.RecurrenceType,
+ ProgramId = dto.ExternalProgramId
+ };
+ }
+ }
+}
diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs
index 4cd18a523..318f450f1 100644
--- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs
+++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs
@@ -8,7 +8,6 @@ using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Controller.Localization;
using MediaBrowser.Controller.Persistence;
-using MediaBrowser.Model.Entities;
using MediaBrowser.Model.LiveTv;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Querying;
@@ -30,29 +29,26 @@ namespace MediaBrowser.Server.Implementations.LiveTv
private readonly IFileSystem _fileSystem;
private readonly ILogger _logger;
private readonly IItemRepository _itemRepo;
- private readonly IImageProcessor _imageProcessor;
-
private readonly IUserManager _userManager;
+
private readonly ILocalizationManager _localization;
- private readonly IUserDataManager _userDataManager;
- private readonly IDtoService _dtoService;
+ private readonly LiveTvDtoService _tvDtoService;
private readonly List<ILiveTvService> _services = new List<ILiveTvService>();
private List<Channel> _channels = new List<Channel>();
private List<ProgramInfoDto> _programs = new List<ProgramInfoDto>();
- public LiveTvManager(IServerApplicationPaths appPaths, IFileSystem fileSystem, ILogger logger, IItemRepository itemRepo, IImageProcessor imageProcessor, IUserManager userManager, ILocalizationManager localization, IUserDataManager userDataManager, IDtoService dtoService)
+ public LiveTvManager(IServerApplicationPaths appPaths, IFileSystem fileSystem, ILogger logger, IItemRepository itemRepo, IImageProcessor imageProcessor, ILocalizationManager localization, IUserDataManager userDataManager, IDtoService dtoService, IUserManager userManager)
{
_appPaths = appPaths;
_fileSystem = fileSystem;
_logger = logger;
_itemRepo = itemRepo;
- _imageProcessor = imageProcessor;
- _userManager = userManager;
_localization = localization;
- _userDataManager = userDataManager;
- _dtoService = dtoService;
+ _userManager = userManager;
+
+ _tvDtoService = new LiveTvDtoService(dtoService, userDataManager, imageProcessor, logger);
}
/// <summary>
@@ -77,62 +73,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
ActiveService = _services.FirstOrDefault();
}
- /// <summary>
- /// Gets the channel info dto.
- /// </summary>
- /// <param name="info">The info.</param>
- /// <param name="user">The user.</param>
- /// <returns>ChannelInfoDto.</returns>
- public ChannelInfoDto GetChannelInfoDto(Channel info, User user)
- {
- var dto = new ChannelInfoDto
- {
- Name = info.Name,
- ServiceName = info.ServiceName,
- ChannelType = info.ChannelType,
- Number = info.ChannelNumber,
- Type = info.GetType().Name,
- Id = info.Id.ToString("N"),
- MediaType = info.MediaType
- };
-
- if (user != null)
- {
- dto.UserData = _dtoService.GetUserItemDataDto(_userDataManager.GetUserData(user.Id, info.GetUserDataKey()));
- }
-
- var imageTag = GetLogoImageTag(info);
-
- if (imageTag.HasValue)
- {
- dto.ImageTags[ImageType.Primary] = imageTag.Value;
- }
-
- return dto;
- }
-
- private Guid? GetLogoImageTag(Channel info)
- {
- var path = info.PrimaryImagePath;
-
- if (string.IsNullOrEmpty(path))
- {
- return null;
- }
-
- try
- {
- return _imageProcessor.GetImageCacheTag(info, ImageType.Primary, path);
- }
- catch (Exception ex)
- {
- _logger.ErrorException("Error getting channel image info for {0}", ex, info.Name);
- }
-
- return null;
- }
-
- public QueryResult<ChannelInfoDto> GetChannels(ChannelQuery query)
+ public Task<QueryResult<ChannelInfoDto>> GetChannels(ChannelQuery query, CancellationToken cancellationToken)
{
var user = string.IsNullOrEmpty(query.UserId) ? null : _userManager.GetUserById(new Guid(query.UserId));
@@ -167,14 +108,16 @@ namespace MediaBrowser.Server.Implementations.LiveTv
return number;
}).ThenBy(i => i.Name)
- .Select(i => GetChannelInfoDto(i, user))
+ .Select(i => _tvDtoService.GetChannelInfoDto(i, user))
.ToArray();
- return new QueryResult<ChannelInfoDto>
+ var result = new QueryResult<ChannelInfoDto>
{
Items = returnChannels,
TotalRecordCount = returnChannels.Length
};
+
+ return Task.FromResult(result);
}
public Channel GetChannel(string id)
@@ -184,55 +127,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv
return _channels.FirstOrDefault(i => i.Id == guid);
}
- public ChannelInfoDto GetChannelInfoDto(string id, string userId)
- {
- var channel = GetChannel(id);
-
- var user = string.IsNullOrEmpty(userId) ? null : _userManager.GetUserById(new Guid(userId));
-
- return channel == null ? null : GetChannelInfoDto(channel, user);
- }
-
- private ProgramInfoDto GetProgramInfoDto(ProgramInfo program, Channel channel)
- {
- var id = GetInternalProgramIdId(channel.ServiceName, program.Id).ToString("N");
-
- return new ProgramInfoDto
- {
- ChannelId = channel.Id.ToString("N"),
- Overview = program.Overview,
- EndDate = program.EndDate,
- Genres = program.Genres,
- ExternalId = program.Id,
- Id = id,
- Name = program.Name,
- ServiceName = channel.ServiceName,
- StartDate = program.StartDate,
- OfficialRating = program.OfficialRating,
- IsHD = program.IsHD,
- OriginalAirDate = program.OriginalAirDate,
- Audio = program.Audio,
- CommunityRating = program.CommunityRating,
- AspectRatio = program.AspectRatio,
- IsRepeat = program.IsRepeat,
- EpisodeTitle = program.EpisodeTitle
- };
- }
-
- private Guid GetInternalChannelId(string serviceName, string externalChannelId, string channelName)
- {
- var name = serviceName + externalChannelId + channelName;
-
- return name.ToLower().GetMBId(typeof(Channel));
- }
-
- private Guid GetInternalProgramIdId(string serviceName, string externalProgramId)
- {
- var name = serviceName + externalProgramId;
-
- return name.ToLower().GetMD5();
- }
-
private async Task<Channel> GetChannel(ChannelInfo channelInfo, string serviceName, CancellationToken cancellationToken)
{
var path = Path.Combine(_appPaths.ItemsByNamePath, "channels", _fileSystem.GetValidFilename(serviceName), _fileSystem.GetValidFilename(channelInfo.Name));
@@ -254,7 +148,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
isNew = true;
}
- var id = GetInternalChannelId(serviceName, channelInfo.Id, channelInfo.Name);
+ var id = _tvDtoService.GetInternalChannelId(serviceName, channelInfo.Id, channelInfo.Name);
var item = _itemRepo.RetrieveItem(id) as Channel;
@@ -335,7 +229,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
var channelPrograms = await service.GetProgramsAsync(channelInfo.Item2.Id, cancellationToken).ConfigureAwait(false);
- programs.AddRange(channelPrograms.Select(program => GetProgramInfoDto(program, item)));
+ programs.AddRange(channelPrograms.Select(program => _tvDtoService.GetProgramInfoDto(program, item)));
list.Add(item);
}
@@ -366,61 +260,19 @@ namespace MediaBrowser.Server.Implementations.LiveTv
return channels.Select(i => new Tuple<string, ChannelInfo>(service.Name, i));
}
- private async Task<IEnumerable<RecordingInfoDto>> GetRecordings(ILiveTvService service, CancellationToken cancellationToken)
- {
- var recordings = await service.GetRecordingsAsync(cancellationToken).ConfigureAwait(false);
-
- return recordings.Select(i => GetRecordingInfoDto(i, service));
- }
-
- private RecordingInfoDto GetRecordingInfoDto(RecordingInfo info, ILiveTvService service)
- {
- var id = service.Name + info.ChannelId + info.Id;
- id = id.GetMD5().ToString("N");
-
- var dto = new RecordingInfoDto
- {
- ChannelName = info.ChannelName,
- Overview = info.Overview,
- EndDate = info.EndDate,
- Name = info.Name,
- StartDate = info.StartDate,
- Id = id,
- ExternalId = info.Id,
- ChannelId = GetInternalChannelId(service.Name, info.ChannelId, info.ChannelName).ToString("N"),
- Status = info.Status,
- Path = info.Path,
- Genres = info.Genres,
- IsRepeat = info.IsRepeat,
- EpisodeTitle = info.EpisodeTitle,
- ChannelType = info.ChannelType,
- MediaType = info.ChannelType == ChannelType.Radio ? MediaType.Audio : MediaType.Video,
- CommunityRating = info.CommunityRating,
- OfficialRating = info.OfficialRating,
- Audio = info.Audio,
- IsHD = info.IsHD
- };
-
- var duration = info.EndDate - info.StartDate;
- dto.DurationMs = Convert.ToInt32(duration.TotalMilliseconds);
-
- if (!string.IsNullOrEmpty(info.ProgramId))
- {
- dto.ProgramId = GetInternalProgramIdId(service.Name, info.ProgramId).ToString("N");
- }
-
- return dto;
- }
-
public async Task<QueryResult<RecordingInfoDto>> GetRecordings(RecordingQuery query, CancellationToken cancellationToken)
{
+ var user = string.IsNullOrEmpty(query.UserId) ? null : _userManager.GetUserById(new Guid(query.UserId));
+
var list = new List<RecordingInfoDto>();
if (ActiveService != null)
{
- var recordings = await GetRecordings(ActiveService, cancellationToken).ConfigureAwait(false);
+ var recordings = await ActiveService.GetRecordingsAsync(cancellationToken).ConfigureAwait(false);
+
+ var dtos = recordings.Select(i => _tvDtoService.GetRecordingInfoDto(i, ActiveService, user));
- list.AddRange(recordings);
+ list.AddRange(dtos);
}
if (!string.IsNullOrEmpty(query.ChannelId))
@@ -471,9 +323,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv
if (ActiveService != null)
{
- var timers = await GetTimers(ActiveService, cancellationToken).ConfigureAwait(false);
+ var timers = await ActiveService.GetTimersAsync(cancellationToken).ConfigureAwait(false);
- list.AddRange(timers);
+ var dtos = timers.Select(i => _tvDtoService.GetTimerInfoDto(i, ActiveService));
+
+ list.AddRange(dtos);
}
if (!string.IsNullOrEmpty(query.ChannelId))
@@ -492,47 +346,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv
};
}
- private async Task<IEnumerable<TimerInfoDto>> GetTimers(ILiveTvService service, CancellationToken cancellationToken)
- {
- var timers = await service.GetTimersAsync(cancellationToken).ConfigureAwait(false);
-
- return timers.Select(i => GetTimerInfoDto(i, service));
- }
-
- private TimerInfoDto GetTimerInfoDto(TimerInfo info, ILiveTvService service)
- {
- var id = service.Name + info.ChannelId + info.Id;
- id = id.GetMD5().ToString("N");
-
- var dto = new TimerInfoDto
- {
- ChannelName = info.ChannelName,
- Overview = info.Overview,
- EndDate = info.EndDate,
- Name = info.Name,
- StartDate = info.StartDate,
- Id = id,
- ExternalId = info.Id,
- ChannelId = GetInternalChannelId(service.Name, info.ChannelId, info.ChannelName).ToString("N"),
- Status = info.Status,
- SeriesTimerId = info.SeriesTimerId,
- RequestedPostPaddingSeconds = info.RequestedPostPaddingSeconds,
- RequestedPrePaddingSeconds = info.RequestedPrePaddingSeconds,
- RequiredPostPaddingSeconds = info.RequiredPostPaddingSeconds,
- RequiredPrePaddingSeconds = info.RequiredPrePaddingSeconds
- };
-
- var duration = info.EndDate - info.StartDate;
- dto.DurationMs = Convert.ToInt32(duration.TotalMilliseconds);
-
- if (!string.IsNullOrEmpty(info.ProgramId))
- {
- dto.ProgramId = GetInternalProgramIdId(service.Name, info.ProgramId).ToString("N");
- }
-
- return dto;
- }
-
public async Task DeleteRecording(string recordingId)
{
var recordings = await GetRecordings(new RecordingQuery
@@ -579,9 +392,13 @@ namespace MediaBrowser.Server.Implementations.LiveTv
await service.CancelTimerAsync(timer.ExternalId, CancellationToken.None).ConfigureAwait(false);
}
- public async Task<RecordingInfoDto> GetRecording(string id, CancellationToken cancellationToken)
+ public async Task<RecordingInfoDto> GetRecording(string id, CancellationToken cancellationToken, User user = null)
{
- var results = await GetRecordings(new RecordingQuery(), cancellationToken).ConfigureAwait(false);
+ var results = await GetRecordings(new RecordingQuery
+ {
+ UserId = user == null ? null : user.Id.ToString("N")
+
+ }, cancellationToken).ConfigureAwait(false);
return results.Items.FirstOrDefault(i => string.Equals(i.Id, id, StringComparison.CurrentCulture));
}
@@ -592,5 +409,60 @@ namespace MediaBrowser.Server.Implementations.LiveTv
return results.Items.FirstOrDefault(i => string.Equals(i.Id, id, StringComparison.CurrentCulture));
}
+
+ public async Task<SeriesTimerInfoDto> GetSeriesTimer(string id, CancellationToken cancellationToken)
+ {
+ var results = await GetSeriesTimers(new SeriesTimerQuery(), cancellationToken).ConfigureAwait(false);
+
+ return results.Items.FirstOrDefault(i => string.Equals(i.Id, id, StringComparison.CurrentCulture));
+ }
+
+ public Task UpdateTimer(TimerInfoDto timer, CancellationToken cancellationToken)
+ {
+ var info = _tvDtoService.GetTimerInfo(timer);
+
+ return ActiveService.UpdateTimerAsync(info, cancellationToken);
+ }
+
+ public Task UpdateSeriesTimer(SeriesTimerInfoDto timer, CancellationToken cancellationToken)
+ {
+ var info = _tvDtoService.GetSeriesTimerInfo(timer);
+
+ return ActiveService.UpdateSeriesTimerAsync(info, cancellationToken);
+ }
+
+ public async Task<QueryResult<SeriesTimerInfoDto>> GetSeriesTimers(SeriesTimerQuery query, CancellationToken cancellationToken)
+ {
+ var list = new List<SeriesTimerInfoDto>();
+
+ if (ActiveService != null)
+ {
+ var timers = await ActiveService.GetSeriesTimersAsync(cancellationToken).ConfigureAwait(false);
+
+ var dtos = timers.Select(i => _tvDtoService.GetSeriesTimerInfoDto(i, ActiveService));
+
+ list.AddRange(dtos);
+ }
+
+ var returnArray = list.OrderByDescending(i => i.StartDate)
+ .ToArray();
+
+ return new QueryResult<SeriesTimerInfoDto>
+ {
+ Items = returnArray,
+ TotalRecordCount = returnArray.Length
+ };
+ }
+
+ public async Task<ChannelInfoDto> GetChannel(string id, CancellationToken cancellationToken, User user = null)
+ {
+ var results = await GetChannels(new ChannelQuery
+ {
+ UserId = user == null ? null : user.Id.ToString("N")
+
+ }, cancellationToken).ConfigureAwait(false);
+
+ return results.Items.FirstOrDefault(i => string.Equals(i.Id, id, StringComparison.CurrentCulture));
+ }
}
}
diff --git a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj
index 031fc6e92..2516a3ae3 100644
--- a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj
+++ b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj
@@ -151,6 +151,7 @@
<Compile Include="Library\Validators\StudiosValidator.cs" />
<Compile Include="Library\Validators\YearsPostScanTask.cs" />
<Compile Include="LiveTv\ChannelImageProvider.cs" />
+ <Compile Include="LiveTv\LiveTvDtoService.cs" />
<Compile Include="LiveTv\LiveTvManager.cs" />
<Compile Include="LiveTv\RefreshChannelsScheduledTask.cs" />
<Compile Include="Localization\LocalizationManager.cs" />
@@ -338,7 +339,7 @@
<Link>swagger-ui\swagger-ui.min.js</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
- <Content Include="Localization\Ratings\be.txt" />
+ <EmbeddedResource Include="Localization\Ratings\be.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\nuget.targets" Condition=" '$(ConfigurationName)' != 'Release Mono' " />