mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-05 09:52:10 +01:00
channel improvements
This commit is contained in:
@@ -547,7 +547,8 @@ namespace MediaBrowser.Server.Implementations.Channels
|
||||
SupportsLatestMedia = supportsLatest,
|
||||
Name = channel.Name,
|
||||
Id = channel.Id.ToString("N"),
|
||||
SupportsContentDownloading = isIndexable || supportsLatest
|
||||
SupportsContentDownloading = isIndexable || supportsLatest,
|
||||
AutoRefreshLevels = features.AutoRefreshLevels
|
||||
};
|
||||
}
|
||||
|
||||
@@ -627,6 +628,13 @@ namespace MediaBrowser.Server.Implementations.Channels
|
||||
|
||||
items = items.Where(i => contentTypes.Contains(i.Item2.ContentType));
|
||||
}
|
||||
if (query.ExtraTypes.Length > 0)
|
||||
{
|
||||
// Avoid implicitly captured closure
|
||||
var contentTypes = query.ExtraTypes;
|
||||
|
||||
items = items.Where(i => contentTypes.Contains(i.Item2.ExtraType));
|
||||
}
|
||||
|
||||
// Avoid implicitly captured closure
|
||||
var token = cancellationToken;
|
||||
@@ -776,6 +784,13 @@ namespace MediaBrowser.Server.Implementations.Channels
|
||||
|
||||
items = items.Where(i => contentTypes.Contains(i.Item2.ContentType));
|
||||
}
|
||||
if (query.ExtraTypes.Length > 0)
|
||||
{
|
||||
// Avoid implicitly captured closure
|
||||
var contentTypes = query.ExtraTypes;
|
||||
|
||||
items = items.Where(i => contentTypes.Contains(i.Item2.ExtraType));
|
||||
}
|
||||
|
||||
if (query.StartIndex.HasValue)
|
||||
{
|
||||
@@ -806,7 +821,7 @@ namespace MediaBrowser.Server.Implementations.Channels
|
||||
Items = returnItemArray
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public async Task<QueryResult<BaseItemDto>> GetAllMedia(AllChannelMediaQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
var user = string.IsNullOrWhiteSpace(query.UserId)
|
||||
@@ -1161,60 +1176,62 @@ namespace MediaBrowser.Server.Implementations.Channels
|
||||
};
|
||||
}
|
||||
|
||||
private string GetIdToHash(string externalId, IChannel channelProvider)
|
||||
private string GetIdToHash(string externalId, string channelName)
|
||||
{
|
||||
// Increment this as needed to force new downloads
|
||||
// Incorporate Name because it's being used to convert channel entity to provider
|
||||
return externalId + (channelProvider.DataVersion ?? string.Empty) +
|
||||
(channelProvider.Name ?? string.Empty) + "16";
|
||||
return externalId + (channelName ?? string.Empty) + "16";
|
||||
}
|
||||
|
||||
private T GetItemById<T>(string idString, string channelName, string channnelDataVersion, out bool isNew)
|
||||
where T : BaseItem, IChannelItem, new()
|
||||
{
|
||||
var id = GetIdToHash(idString, channelName).GetMBId(typeof(T));
|
||||
|
||||
T item = null;
|
||||
|
||||
try
|
||||
{
|
||||
item = _libraryManager.GetItemById(id) as T;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error retrieving channel item from database", ex);
|
||||
}
|
||||
|
||||
if (item == null || !string.Equals(item.DataVersion, channnelDataVersion, StringComparison.Ordinal))
|
||||
{
|
||||
item = new T();
|
||||
isNew = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
isNew = false;
|
||||
}
|
||||
|
||||
item.DataVersion = channnelDataVersion;
|
||||
item.Id = id;
|
||||
return item;
|
||||
}
|
||||
|
||||
private async Task<BaseItem> GetChannelItemEntity(ChannelItemInfo info, IChannel channelProvider, Guid internalChannelId, CancellationToken cancellationToken)
|
||||
{
|
||||
BaseItem item;
|
||||
Guid id;
|
||||
var isNew = false;
|
||||
|
||||
var idToHash = GetIdToHash(info.Id, channelProvider);
|
||||
bool isNew;
|
||||
|
||||
if (info.Type == ChannelItemType.Folder)
|
||||
{
|
||||
id = idToHash.GetMBId(typeof(ChannelFolderItem));
|
||||
|
||||
item = _libraryManager.GetItemById(id) as ChannelFolderItem;
|
||||
|
||||
if (item == null)
|
||||
{
|
||||
isNew = true;
|
||||
item = new ChannelFolderItem();
|
||||
}
|
||||
item = GetItemById<ChannelFolderItem>(info.Id, channelProvider.Name, channelProvider.DataVersion, out isNew);
|
||||
}
|
||||
else if (info.MediaType == ChannelMediaType.Audio)
|
||||
{
|
||||
id = idToHash.GetMBId(typeof(ChannelAudioItem));
|
||||
|
||||
item = _libraryManager.GetItemById(id) as ChannelAudioItem;
|
||||
|
||||
if (item == null)
|
||||
{
|
||||
isNew = true;
|
||||
item = new ChannelAudioItem();
|
||||
}
|
||||
item = GetItemById<ChannelAudioItem>(info.Id, channelProvider.Name, channelProvider.DataVersion, out isNew);
|
||||
}
|
||||
else
|
||||
{
|
||||
id = idToHash.GetMBId(typeof(ChannelVideoItem));
|
||||
|
||||
item = _libraryManager.GetItemById(id) as ChannelVideoItem;
|
||||
|
||||
if (item == null)
|
||||
{
|
||||
isNew = true;
|
||||
item = new ChannelVideoItem();
|
||||
}
|
||||
item = GetItemById<ChannelVideoItem>(info.Id, channelProvider.Name, channelProvider.DataVersion, out isNew);
|
||||
}
|
||||
|
||||
item.Id = id;
|
||||
item.RunTimeTicks = info.RunTimeTicks;
|
||||
|
||||
if (isNew)
|
||||
@@ -1254,6 +1271,7 @@ namespace MediaBrowser.Server.Implementations.Channels
|
||||
if (channelMediaItem != null)
|
||||
{
|
||||
channelMediaItem.ContentType = info.ContentType;
|
||||
channelMediaItem.ExtraType = info.ExtraType;
|
||||
channelMediaItem.ChannelMediaSources = info.MediaSources;
|
||||
|
||||
var mediaSource = info.MediaSources.FirstOrDefault();
|
||||
|
||||
@@ -64,9 +64,16 @@ namespace MediaBrowser.Server.Implementations.Channels
|
||||
|
||||
foreach (var channel in channels.Items)
|
||||
{
|
||||
var channelId = channel.Id.ToString("N");
|
||||
|
||||
var features = _channelManager.GetChannelFeatures(channelId);
|
||||
|
||||
const int currentRefreshLevel = 1;
|
||||
var maxRefreshLevel = features.AutoRefreshLevels ?? 1;
|
||||
|
||||
try
|
||||
{
|
||||
await GetAllItems(user, channel.Id.ToString("N"), null, false, cancellationToken).ConfigureAwait(false);
|
||||
await GetAllItems(user, channelId, null, currentRefreshLevel, maxRefreshLevel, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -83,7 +90,7 @@ namespace MediaBrowser.Server.Implementations.Channels
|
||||
|
||||
}
|
||||
|
||||
private async Task GetAllItems(string user, string channelId, string folderId, bool recursive, CancellationToken cancellationToken)
|
||||
private async Task GetAllItems(string user, string channelId, string folderId, int currentRefreshLevel, int maxRefreshLevel, CancellationToken cancellationToken)
|
||||
{
|
||||
var folderItems = new List<string>();
|
||||
|
||||
@@ -117,13 +124,13 @@ namespace MediaBrowser.Server.Implementations.Channels
|
||||
totalCount = result.TotalRecordCount;
|
||||
}
|
||||
|
||||
if (recursive)
|
||||
if (currentRefreshLevel < maxRefreshLevel)
|
||||
{
|
||||
foreach (var folder in folderItems)
|
||||
{
|
||||
try
|
||||
{
|
||||
await GetAllItems(user, channelId, folder, false, cancellationToken).ConfigureAwait(false);
|
||||
await GetAllItems(user, channelId, folder, currentRefreshLevel + 1, maxRefreshLevel, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -99,7 +99,8 @@ namespace MediaBrowser.Server.Implementations.Intros
|
||||
{
|
||||
var channelTrailers = await _channelManager.GetAllMediaInternal(new AllChannelMediaQuery
|
||||
{
|
||||
ContentTypes = new[] { ChannelMediaContentType.Trailer },
|
||||
ContentTypes = new[] { ChannelMediaContentType.MovieExtra },
|
||||
ExtraTypes = new[] { ExtraType.Trailer },
|
||||
UserId = user.Id.ToString("N")
|
||||
|
||||
}, CancellationToken.None);
|
||||
|
||||
@@ -449,10 +449,10 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||
{
|
||||
var list = new List<string>
|
||||
{
|
||||
ConfigurationManager.ApplicationPaths.GetInternalMetadataPath(item.Id)
|
||||
item.GetInternalMetadataPath()
|
||||
};
|
||||
|
||||
list.AddRange(children.Select(i => ConfigurationManager.ApplicationPaths.GetInternalMetadataPath(i.Id)));
|
||||
list.AddRange(children.Select(i => i.GetInternalMetadataPath()));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Controller.Chapters;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Movies;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
using MediaBrowser.Controller.MediaEncoding;
|
||||
using MediaBrowser.Model.Configuration;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.MediaInfo;
|
||||
@@ -22,20 +19,17 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder
|
||||
{
|
||||
public class EncodingManager : IEncodingManager
|
||||
{
|
||||
private readonly IServerConfigurationManager _config;
|
||||
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IMediaEncoder _encoder;
|
||||
private readonly IChapterManager _chapterManager;
|
||||
|
||||
public EncodingManager(IServerConfigurationManager config,
|
||||
IFileSystem fileSystem,
|
||||
public EncodingManager(IFileSystem fileSystem,
|
||||
ILogger logger,
|
||||
IMediaEncoder encoder,
|
||||
IChapterManager chapterManager)
|
||||
{
|
||||
_config = config;
|
||||
_fileSystem = fileSystem;
|
||||
_logger = logger;
|
||||
_encoder = encoder;
|
||||
@@ -46,9 +40,9 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder
|
||||
/// Gets the chapter images data path.
|
||||
/// </summary>
|
||||
/// <value>The chapter images data path.</value>
|
||||
private string GetChapterImagesPath(Guid itemId)
|
||||
private string GetChapterImagesPath(IHasImages item)
|
||||
{
|
||||
return Path.Combine(_config.ApplicationPaths.GetInternalMetadataPath(itemId), "chapters");
|
||||
return Path.Combine(item.GetInternalMetadataPath(), "chapters");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -190,12 +184,12 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder
|
||||
{
|
||||
var filename = video.DateModified.Ticks.ToString(_usCulture) + "_" + chapterPositionTicks.ToString(_usCulture) + ".jpg";
|
||||
|
||||
return Path.Combine(GetChapterImagesPath(video.Id), filename);
|
||||
return Path.Combine(GetChapterImagesPath(video), filename);
|
||||
}
|
||||
|
||||
private List<string> GetSavedChapterImages(Video video)
|
||||
{
|
||||
var path = GetChapterImagesPath(video.Id);
|
||||
var path = GetChapterImagesPath(video);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
@@ -251,13 +251,5 @@ namespace MediaBrowser.Server.Implementations
|
||||
_internalMetadataPath = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public string GetInternalMetadataPath(Guid id)
|
||||
{
|
||||
var idString = id.ToString("N");
|
||||
|
||||
return Path.Combine(InternalMetadataPath, idString.Substring(0, 2), idString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user