mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-07-15 10:43:30 +01:00
Recognize file changes and remove data on change (#13839)
Some checks are pending
CodeQL / Analyze (csharp) (push) Waiting to run
OpenAPI / OpenAPI - HEAD (push) Waiting to run
OpenAPI / OpenAPI - BASE (push) Waiting to run
OpenAPI / OpenAPI - Difference (push) Blocked by required conditions
OpenAPI / OpenAPI - Publish Unstable Spec (push) Blocked by required conditions
OpenAPI / OpenAPI - Publish Stable Spec (push) Blocked by required conditions
Tests / run-tests (macos-latest) (push) Waiting to run
Tests / run-tests (ubuntu-latest) (push) Waiting to run
Tests / run-tests (windows-latest) (push) Waiting to run
Project Automation / Project board (push) Waiting to run
Merge Conflict Labeler / Labeling (push) Waiting to run
Some checks are pending
CodeQL / Analyze (csharp) (push) Waiting to run
OpenAPI / OpenAPI - HEAD (push) Waiting to run
OpenAPI / OpenAPI - BASE (push) Waiting to run
OpenAPI / OpenAPI - Difference (push) Blocked by required conditions
OpenAPI / OpenAPI - Publish Unstable Spec (push) Blocked by required conditions
OpenAPI / OpenAPI - Publish Stable Spec (push) Blocked by required conditions
Tests / run-tests (macos-latest) (push) Waiting to run
Tests / run-tests (ubuntu-latest) (push) Waiting to run
Tests / run-tests (windows-latest) (push) Waiting to run
Project Automation / Project board (push) Waiting to run
Merge Conflict Labeler / Labeling (push) Waiting to run
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
@@ -12,7 +13,9 @@ using Jellyfin.Extensions;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Audio;
|
||||
using MediaBrowser.Controller.IO;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.MediaSegments;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Configuration;
|
||||
using MediaBrowser.Model.Entities;
|
||||
@@ -26,13 +29,24 @@ namespace MediaBrowser.Providers.Manager
|
||||
where TItemType : BaseItem, IHasLookupInfo<TIdType>, new()
|
||||
where TIdType : ItemLookupInfo, new()
|
||||
{
|
||||
protected MetadataService(IServerConfigurationManager serverConfigurationManager, ILogger<MetadataService<TItemType, TIdType>> logger, IProviderManager providerManager, IFileSystem fileSystem, ILibraryManager libraryManager)
|
||||
protected MetadataService(
|
||||
IServerConfigurationManager serverConfigurationManager,
|
||||
ILogger<MetadataService<TItemType, TIdType>> logger,
|
||||
IProviderManager providerManager,
|
||||
IFileSystem fileSystem,
|
||||
ILibraryManager libraryManager,
|
||||
IPathManager pathManager,
|
||||
IKeyframeManager keyframeManager,
|
||||
IMediaSegmentManager mediaSegmentManager)
|
||||
{
|
||||
ServerConfigurationManager = serverConfigurationManager;
|
||||
Logger = logger;
|
||||
ProviderManager = providerManager;
|
||||
FileSystem = fileSystem;
|
||||
LibraryManager = libraryManager;
|
||||
PathManager = pathManager;
|
||||
KeyframeManager = keyframeManager;
|
||||
MediaSegmentManager = mediaSegmentManager;
|
||||
ImageProvider = new ItemImageProvider(Logger, ProviderManager, FileSystem);
|
||||
}
|
||||
|
||||
@@ -48,6 +62,12 @@ namespace MediaBrowser.Providers.Manager
|
||||
|
||||
protected ILibraryManager LibraryManager { get; }
|
||||
|
||||
protected IPathManager PathManager { get; }
|
||||
|
||||
protected IKeyframeManager KeyframeManager { get; }
|
||||
|
||||
protected IMediaSegmentManager MediaSegmentManager { get; }
|
||||
|
||||
protected virtual bool EnableUpdatingPremiereDateFromChildren => false;
|
||||
|
||||
protected virtual bool EnableUpdatingGenresFromChildren => false;
|
||||
@@ -303,6 +323,55 @@ namespace MediaBrowser.Providers.Manager
|
||||
updateType |= ItemUpdateType.MetadataImport;
|
||||
}
|
||||
|
||||
// Cleanup extracted files if source file was modified
|
||||
var itemPath = item.Path;
|
||||
if (!string.IsNullOrEmpty(itemPath))
|
||||
{
|
||||
var info = FileSystem.GetFileSystemInfo(itemPath);
|
||||
var modificationDate = info.LastWriteTimeUtc;
|
||||
var itemLastModifiedFileSystem = item.DateModified;
|
||||
if (info.Exists && itemLastModifiedFileSystem != modificationDate)
|
||||
{
|
||||
Logger.LogDebug("File modification time changed from {Then} to {Now}: {Path}", itemLastModifiedFileSystem, modificationDate, itemPath);
|
||||
|
||||
item.DateModified = modificationDate;
|
||||
if (ServerConfigurationManager.GetMetadataConfiguration().UseFileCreationTimeForDateAdded)
|
||||
{
|
||||
item.DateCreated = info.CreationTimeUtc;
|
||||
}
|
||||
|
||||
var size = info.Length;
|
||||
if (item is Video video)
|
||||
{
|
||||
var videoType = video.VideoType;
|
||||
var sizeChanged = size != (video.Size ?? 0);
|
||||
if (videoType == VideoType.BluRay || video.VideoType == VideoType.Dvd || sizeChanged)
|
||||
{
|
||||
if (sizeChanged)
|
||||
{
|
||||
item.Size = size;
|
||||
Logger.LogDebug("File size changed from {Then} to {Now}: {Path}", video.Size, size, itemPath);
|
||||
}
|
||||
|
||||
var validPaths = PathManager.GetExtractedDataPaths(video).Where(Directory.Exists).ToList();
|
||||
if (validPaths.Count > 0)
|
||||
{
|
||||
Logger.LogInformation("File changed, pruning extracted data: {Path}", itemPath);
|
||||
foreach (var path in validPaths)
|
||||
{
|
||||
Directory.Delete(path, true);
|
||||
}
|
||||
}
|
||||
|
||||
KeyframeManager.DeleteKeyframeDataAsync(video.Id, CancellationToken.None).GetAwaiter().GetResult();
|
||||
MediaSegmentManager.DeleteSegmentsAsync(item.Id).GetAwaiter().GetResult();
|
||||
}
|
||||
}
|
||||
|
||||
updateType |= ItemUpdateType.MetadataImport;
|
||||
}
|
||||
}
|
||||
|
||||
return updateType;
|
||||
}
|
||||
|
||||
@@ -1132,6 +1201,11 @@ namespace MediaBrowser.Providers.Manager
|
||||
target.DateCreated = source.DateCreated;
|
||||
}
|
||||
|
||||
if (replaceData || source.DateModified != default)
|
||||
{
|
||||
target.DateModified = source.DateModified;
|
||||
}
|
||||
|
||||
if (replaceData || string.IsNullOrEmpty(target.PreferredMetadataCountryCode))
|
||||
{
|
||||
target.PreferredMetadataCountryCode = source.PreferredMetadataCountryCode;
|
||||
|
||||
Reference in New Issue
Block a user