mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-05-26 02:27:06 +01:00
add more methods to file system interface
This commit is contained in:
@@ -4,11 +4,13 @@ using MediaBrowser.Controller.Dto;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.LiveTv;
|
||||
using MediaBrowser.Controller.Persistence;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.LiveTv;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -21,13 +23,15 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
||||
|
||||
private readonly IUserDataManager _userDataManager;
|
||||
private readonly IDtoService _dtoService;
|
||||
private readonly IItemRepository _itemRepo;
|
||||
|
||||
public LiveTvDtoService(IDtoService dtoService, IUserDataManager userDataManager, IImageProcessor imageProcessor, ILogger logger)
|
||||
public LiveTvDtoService(IDtoService dtoService, IUserDataManager userDataManager, IImageProcessor imageProcessor, ILogger logger, IItemRepository itemRepo)
|
||||
{
|
||||
_dtoService = dtoService;
|
||||
_userDataManager = userDataManager;
|
||||
_imageProcessor = imageProcessor;
|
||||
_logger = logger;
|
||||
_itemRepo = itemRepo;
|
||||
}
|
||||
|
||||
public TimerInfoDto GetTimerInfoDto(TimerInfo info, ILiveTvService service, LiveTvProgram program, LiveTvChannel channel)
|
||||
@@ -180,7 +184,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
||||
return status.ToString();
|
||||
}
|
||||
|
||||
public RecordingInfoDto GetRecordingInfoDto(LiveTvRecording recording, LiveTvChannel channel, ILiveTvService service, User user = null)
|
||||
public RecordingInfoDto GetRecordingInfoDto(ILiveTvRecording recording, LiveTvChannel channel, ILiveTvService service, User user = null)
|
||||
{
|
||||
var info = recording.RecordingInfo;
|
||||
|
||||
@@ -216,7 +220,14 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
||||
IsNews = info.IsNews,
|
||||
IsKids = info.IsKids,
|
||||
IsPremiere = info.IsPremiere,
|
||||
RunTimeTicks = (info.EndDate - info.StartDate).Ticks
|
||||
RunTimeTicks = (info.EndDate - info.StartDate).Ticks,
|
||||
LocationType = recording.LocationType,
|
||||
|
||||
MediaStreams = _itemRepo.GetMediaStreams(new MediaStreamQuery
|
||||
{
|
||||
ItemId = recording.Id
|
||||
|
||||
}).ToList()
|
||||
};
|
||||
|
||||
var imageTag = GetImageTag(recording);
|
||||
@@ -330,7 +341,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
||||
return dto;
|
||||
}
|
||||
|
||||
private Guid? GetImageTag(BaseItem info)
|
||||
private Guid? GetImageTag(IHasImages info)
|
||||
{
|
||||
var path = info.PrimaryImagePath;
|
||||
|
||||
@@ -351,39 +362,41 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
||||
return null;
|
||||
}
|
||||
|
||||
private const string InternalVersionNumber = "2";
|
||||
|
||||
public Guid GetInternalChannelId(string serviceName, string externalId)
|
||||
{
|
||||
var name = serviceName + externalId;
|
||||
var name = serviceName + externalId + InternalVersionNumber;
|
||||
|
||||
return name.ToLower().GetMBId(typeof(LiveTvChannel));
|
||||
}
|
||||
|
||||
public Guid GetInternalTimerId(string serviceName, string externalId)
|
||||
{
|
||||
var name = serviceName + externalId;
|
||||
var name = serviceName + externalId + InternalVersionNumber;
|
||||
|
||||
return name.ToLower().GetMD5();
|
||||
}
|
||||
|
||||
public Guid GetInternalSeriesTimerId(string serviceName, string externalId)
|
||||
{
|
||||
var name = serviceName + externalId;
|
||||
var name = serviceName + externalId + InternalVersionNumber;
|
||||
|
||||
return name.ToLower().GetMD5();
|
||||
}
|
||||
|
||||
public Guid GetInternalProgramId(string serviceName, string externalId)
|
||||
{
|
||||
var name = serviceName + externalId;
|
||||
var name = serviceName + externalId + InternalVersionNumber;
|
||||
|
||||
return name.ToLower().GetMD5();
|
||||
return name.ToLower().GetMBId(typeof(LiveTvProgram));
|
||||
}
|
||||
|
||||
public Guid GetInternalRecordingId(string serviceName, string externalId)
|
||||
{
|
||||
var name = serviceName + externalId;
|
||||
var name = serviceName + externalId + InternalVersionNumber;
|
||||
|
||||
return name.ToLower().GetMD5();
|
||||
return name.ToLower().GetMBId(typeof(ILiveTvRecording));
|
||||
}
|
||||
|
||||
public async Task<TimerInfo> GetTimerInfo(TimerInfoDto dto, bool isNew, ILiveTvManager liveTv, CancellationToken cancellationToken)
|
||||
|
||||
@@ -6,8 +6,8 @@ using MediaBrowser.Controller.Dto;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
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;
|
||||
@@ -31,7 +31,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
||||
private readonly IItemRepository _itemRepo;
|
||||
private readonly IUserManager _userManager;
|
||||
|
||||
private readonly ILocalizationManager _localization;
|
||||
private readonly LiveTvDtoService _tvDtoService;
|
||||
|
||||
private readonly List<ILiveTvService> _services = new List<ILiveTvService>();
|
||||
@@ -39,16 +38,15 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
||||
private Dictionary<Guid, LiveTvChannel> _channels = new Dictionary<Guid, LiveTvChannel>();
|
||||
private Dictionary<Guid, LiveTvProgram> _programs = new Dictionary<Guid, LiveTvProgram>();
|
||||
|
||||
public LiveTvManager(IServerApplicationPaths appPaths, IFileSystem fileSystem, ILogger logger, IItemRepository itemRepo, IImageProcessor imageProcessor, ILocalizationManager localization, IUserDataManager userDataManager, IDtoService dtoService, IUserManager userManager)
|
||||
public LiveTvManager(IServerApplicationPaths appPaths, IFileSystem fileSystem, ILogger logger, IItemRepository itemRepo, IImageProcessor imageProcessor, IUserDataManager userDataManager, IDtoService dtoService, IUserManager userManager)
|
||||
{
|
||||
_appPaths = appPaths;
|
||||
_fileSystem = fileSystem;
|
||||
_logger = logger;
|
||||
_itemRepo = itemRepo;
|
||||
_localization = localization;
|
||||
_userManager = userManager;
|
||||
|
||||
_tvDtoService = new LiveTvDtoService(dtoService, userDataManager, imageProcessor, logger);
|
||||
_tvDtoService = new LiveTvDtoService(dtoService, userDataManager, imageProcessor, logger, _itemRepo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -82,7 +80,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
||||
if (user != null)
|
||||
{
|
||||
channels = channels
|
||||
.Where(i => i.IsParentalAllowed(user, _localization))
|
||||
.Where(i => i.IsParentalAllowed(user))
|
||||
.OrderBy(i =>
|
||||
{
|
||||
double number = 0;
|
||||
@@ -144,7 +142,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
||||
return obj;
|
||||
}
|
||||
|
||||
public async Task<LiveTvRecording> GetInternalRecording(string id, CancellationToken cancellationToken)
|
||||
public async Task<ILiveTvRecording> GetInternalRecording(string id, CancellationToken cancellationToken)
|
||||
{
|
||||
var service = ActiveService;
|
||||
|
||||
@@ -255,23 +253,46 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
||||
return item;
|
||||
}
|
||||
|
||||
private async Task<LiveTvRecording> GetRecording(RecordingInfo info, string serviceName, CancellationToken cancellationToken)
|
||||
private async Task<ILiveTvRecording> GetRecording(RecordingInfo info, string serviceName, CancellationToken cancellationToken)
|
||||
{
|
||||
var isNew = false;
|
||||
|
||||
var id = _tvDtoService.GetInternalRecordingId(serviceName, info.Id);
|
||||
|
||||
var item = _itemRepo.RetrieveItem(id) as LiveTvRecording;
|
||||
var item = _itemRepo.RetrieveItem(id) as ILiveTvRecording;
|
||||
|
||||
if (item == null)
|
||||
{
|
||||
item = new LiveTvRecording
|
||||
if (info.ChannelType == ChannelType.TV)
|
||||
{
|
||||
Name = info.Name,
|
||||
Id = id,
|
||||
DateCreated = DateTime.UtcNow,
|
||||
DateModified = DateTime.UtcNow
|
||||
};
|
||||
item = new LiveTvVideoRecording
|
||||
{
|
||||
Name = info.Name,
|
||||
Id = id,
|
||||
DateCreated = DateTime.UtcNow,
|
||||
DateModified = DateTime.UtcNow,
|
||||
VideoType = VideoType.VideoFile
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
item = new LiveTvAudioRecording
|
||||
{
|
||||
Name = info.Name,
|
||||
Id = id,
|
||||
DateCreated = DateTime.UtcNow,
|
||||
DateModified = DateTime.UtcNow
|
||||
};
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(info.Path))
|
||||
{
|
||||
item.Path = info.Path;
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(info.Url))
|
||||
{
|
||||
item.Path = info.Url;
|
||||
}
|
||||
|
||||
isNew = true;
|
||||
}
|
||||
@@ -331,7 +352,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
||||
|
||||
if (user != null)
|
||||
{
|
||||
programs = programs.Where(i => i.IsParentalAllowed(user, _localization));
|
||||
programs = programs.Where(i => i.IsParentalAllowed(user));
|
||||
}
|
||||
|
||||
var returnArray = programs
|
||||
@@ -450,10 +471,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
||||
|
||||
var user = string.IsNullOrEmpty(query.UserId) ? null : _userManager.GetUserById(new Guid(query.UserId));
|
||||
|
||||
var list = new List<RecordingInfo>();
|
||||
|
||||
var recordings = await service.GetRecordingsAsync(cancellationToken).ConfigureAwait(false);
|
||||
list.AddRange(recordings);
|
||||
|
||||
if (!string.IsNullOrEmpty(query.ChannelId))
|
||||
{
|
||||
@@ -461,9 +479,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
||||
|
||||
var currentServiceName = service.Name;
|
||||
|
||||
list = list
|
||||
.Where(i => _tvDtoService.GetInternalChannelId(currentServiceName, i.ChannelId) == guid)
|
||||
.ToList();
|
||||
recordings = recordings
|
||||
.Where(i => _tvDtoService.GetInternalChannelId(currentServiceName, i.ChannelId) == guid);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(query.Id))
|
||||
@@ -472,27 +489,31 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
||||
|
||||
var currentServiceName = service.Name;
|
||||
|
||||
list = list
|
||||
.Where(i => _tvDtoService.GetInternalRecordingId(currentServiceName, i.Id) == guid)
|
||||
.ToList();
|
||||
recordings = recordings
|
||||
.Where(i => _tvDtoService.GetInternalRecordingId(currentServiceName, i.Id) == guid);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(query.GroupId))
|
||||
{
|
||||
var guid = new Guid(query.GroupId);
|
||||
|
||||
list = list.Where(i => GetRecordingGroupIds(i).Contains(guid))
|
||||
.ToList();
|
||||
recordings = recordings.Where(i => GetRecordingGroupIds(i).Contains(guid));
|
||||
}
|
||||
|
||||
IEnumerable<LiveTvRecording> entities = await GetEntities(list, service.Name, cancellationToken).ConfigureAwait(false);
|
||||
if (query.IsRecording.HasValue)
|
||||
{
|
||||
var val = query.IsRecording.Value;
|
||||
recordings = recordings.Where(i => (i.Status == RecordingStatus.InProgress) == val);
|
||||
}
|
||||
|
||||
IEnumerable<ILiveTvRecording> entities = await GetEntities(recordings, service.Name, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
entities = entities.OrderByDescending(i => i.RecordingInfo.StartDate);
|
||||
|
||||
if (user != null)
|
||||
{
|
||||
var currentUser = user;
|
||||
entities = entities.Where(i => i.IsParentalAllowed(currentUser, _localization));
|
||||
entities = entities.Where(i => i.IsParentalAllowed(currentUser));
|
||||
}
|
||||
|
||||
if (query.StartIndex.HasValue)
|
||||
@@ -520,7 +541,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
||||
};
|
||||
}
|
||||
|
||||
private Task<LiveTvRecording[]> GetEntities(IEnumerable<RecordingInfo> recordings, string serviceName, CancellationToken cancellationToken)
|
||||
private Task<ILiveTvRecording[]> GetEntities(IEnumerable<RecordingInfo> recordings, string serviceName, CancellationToken cancellationToken)
|
||||
{
|
||||
var tasks = recordings.Select(i => GetRecording(i, serviceName, cancellationToken));
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
||||
|
||||
public override bool Supports(BaseItem item)
|
||||
{
|
||||
return item is LiveTvRecording;
|
||||
return item is ILiveTvRecording;
|
||||
}
|
||||
|
||||
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
|
||||
@@ -55,7 +55,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
||||
|
||||
try
|
||||
{
|
||||
changed = await DownloadImage((LiveTvRecording)item, cancellationToken).ConfigureAwait(false);
|
||||
changed = await DownloadImage((ILiveTvRecording)item, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (HttpException ex)
|
||||
{
|
||||
@@ -74,7 +74,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
||||
return changed;
|
||||
}
|
||||
|
||||
private async Task<bool> DownloadImage(LiveTvRecording item, CancellationToken cancellationToken)
|
||||
private async Task<bool> DownloadImage(ILiveTvRecording item, CancellationToken cancellationToken)
|
||||
{
|
||||
var recordingInfo = item.RecordingInfo;
|
||||
|
||||
@@ -133,7 +133,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
||||
// Dummy up the original url
|
||||
var url = item.ServiceName + recordingInfo.Id;
|
||||
|
||||
await _providerManager.SaveImage(item, imageStream, contentType, ImageType.Primary, null, url, cancellationToken).ConfigureAwait(false);
|
||||
await _providerManager.SaveImage((BaseItem)item, imageStream, contentType, ImageType.Primary, null, url, cancellationToken).ConfigureAwait(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user