update channel manager
This commit is contained in:
parent
a67c8df252
commit
5013fddc2d
|
@ -104,6 +104,11 @@ namespace MediaBrowser.Server.Implementations.Channels
|
|||
.OrderBy(i => i.Name);
|
||||
}
|
||||
|
||||
public IEnumerable<Guid> GetInstalledChannelIds()
|
||||
{
|
||||
return GetAllChannels().Select(i => GetInternalChannelId(i.Name));
|
||||
}
|
||||
|
||||
public Task<QueryResult<Channel>> GetChannelsInternal(ChannelQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
var user = string.IsNullOrWhiteSpace(query.UserId)
|
||||
|
@ -408,25 +413,15 @@ namespace MediaBrowser.Server.Implementations.Channels
|
|||
|
||||
private async Task<Channel> GetChannel(IChannel channelInfo, CancellationToken cancellationToken)
|
||||
{
|
||||
var parentFolder = await GetInternalChannelFolder(cancellationToken).ConfigureAwait(false);
|
||||
var parentFolderId = parentFolder.Id;
|
||||
|
||||
var id = GetInternalChannelId(channelInfo.Name);
|
||||
|
||||
var path = Channel.GetInternalMetadataPath(_config.ApplicationPaths.InternalMetadataPath, id);
|
||||
|
||||
var isNew = false;
|
||||
|
||||
if (!_fileSystem.DirectoryExists(path))
|
||||
{
|
||||
_logger.Debug("Creating directory {0}", path);
|
||||
|
||||
_fileSystem.CreateDirectory(path);
|
||||
|
||||
if (!_fileSystem.DirectoryExists(path))
|
||||
{
|
||||
throw new IOException("Path not created: " + path);
|
||||
}
|
||||
|
||||
isNew = true;
|
||||
}
|
||||
var forceUpdate = false;
|
||||
|
||||
var item = _libraryManager.GetItemById(id) as Channel;
|
||||
var channelId = channelInfo.Name.GetMD5().ToString("N");
|
||||
|
@ -438,18 +433,29 @@ namespace MediaBrowser.Server.Implementations.Channels
|
|||
Name = channelInfo.Name,
|
||||
Id = id,
|
||||
DateCreated = _fileSystem.GetCreationTimeUtc(path),
|
||||
DateModified = _fileSystem.GetLastWriteTimeUtc(path),
|
||||
Path = path,
|
||||
ChannelId = channelId
|
||||
DateModified = _fileSystem.GetLastWriteTimeUtc(path)
|
||||
};
|
||||
|
||||
isNew = true;
|
||||
}
|
||||
|
||||
if (!string.Equals(item.ChannelId, channelId, StringComparison.OrdinalIgnoreCase))
|
||||
if (!string.Equals(item.Path, path, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
isNew = true;
|
||||
}
|
||||
item.Path = path;
|
||||
|
||||
if (!string.Equals(item.ChannelId, channelId, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
forceUpdate = true;
|
||||
}
|
||||
item.ChannelId = channelId;
|
||||
|
||||
if (item.ParentId != parentFolderId)
|
||||
{
|
||||
forceUpdate = true;
|
||||
}
|
||||
item.ParentId = parentFolderId;
|
||||
|
||||
item.OfficialRating = GetOfficialRating(channelInfo.ParentalRating);
|
||||
item.Overview = channelInfo.Description;
|
||||
|
@ -459,13 +465,17 @@ namespace MediaBrowser.Server.Implementations.Channels
|
|||
{
|
||||
item.Name = channelInfo.Name;
|
||||
}
|
||||
|
||||
await item.RefreshMetadata(new MetadataRefreshOptions(_fileSystem)
|
||||
|
||||
if (isNew)
|
||||
{
|
||||
ForceSave = isNew
|
||||
|
||||
}, cancellationToken);
|
||||
await _libraryManager.CreateItem(item, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
else if (forceUpdate)
|
||||
{
|
||||
await item.UpdateToRepository(ItemUpdateType.None, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
await item.RefreshMetadata(new MetadataRefreshOptions(_fileSystem), cancellationToken);
|
||||
return item;
|
||||
}
|
||||
|
||||
|
@ -1225,6 +1235,7 @@ namespace MediaBrowser.Server.Implementations.Channels
|
|||
{
|
||||
BaseItem item;
|
||||
bool isNew;
|
||||
bool forceUpdate = false;
|
||||
|
||||
if (info.Type == ChannelItemType.Folder)
|
||||
{
|
||||
|
@ -1254,7 +1265,6 @@ namespace MediaBrowser.Server.Implementations.Channels
|
|||
item.ProductionYear = info.ProductionYear;
|
||||
item.ProviderIds = info.ProviderIds;
|
||||
item.OfficialRating = info.OfficialRating;
|
||||
|
||||
item.DateCreated = info.DateCreated ?? DateTime.UtcNow;
|
||||
}
|
||||
|
||||
|
@ -1262,17 +1272,18 @@ namespace MediaBrowser.Server.Implementations.Channels
|
|||
|
||||
channelItem.ChannelId = internalChannelId.ToString("N");
|
||||
|
||||
if (item.ParentId != internalChannelId)
|
||||
{
|
||||
forceUpdate = true;
|
||||
}
|
||||
item.ParentId = internalChannelId;
|
||||
|
||||
if (!string.Equals(channelItem.ExternalId, info.Id, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
isNew = true;
|
||||
forceUpdate = true;
|
||||
}
|
||||
channelItem.ExternalId = info.Id;
|
||||
|
||||
if (isNew)
|
||||
{
|
||||
channelItem.Tags = info.Tags;
|
||||
}
|
||||
|
||||
var channelMediaItem = item as IChannelMediaItem;
|
||||
|
||||
if (channelMediaItem != null)
|
||||
|
@ -1286,7 +1297,7 @@ namespace MediaBrowser.Server.Implementations.Channels
|
|||
item.Path = mediaSource == null ? null : mediaSource.Path;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(info.ImageUrl))
|
||||
if (!string.IsNullOrWhiteSpace(info.ImageUrl) && !item.HasImage(ImageType.Primary))
|
||||
{
|
||||
item.SetImagePath(ImageType.Primary, info.ImageUrl);
|
||||
}
|
||||
|
@ -1300,6 +1311,10 @@ namespace MediaBrowser.Server.Implementations.Channels
|
|||
await _libraryManager.UpdatePeople(item, info.People ?? new List<PersonInfo>()).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
else if (forceUpdate)
|
||||
{
|
||||
await item.UpdateToRepository(ItemUpdateType.None, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user