diff options
| author | Tim Eisele <Shadowghost@users.noreply.github.com> | 2024-09-07 19:23:48 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-07 11:23:48 -0600 |
| commit | c56dbc1c4410e1b0ec31ca901809b6f627bbb6ed (patch) | |
| tree | 56df7024be555125eae955da94dd5dda248b8f59 /Jellyfin.Server/Migrations/Routines/MoveTrickplayFiles.cs | |
| parent | 675a8a9ec91da47e37ace6161ba5a5a0e20a7839 (diff) | |
Enhance Trickplay (#11883)
Diffstat (limited to 'Jellyfin.Server/Migrations/Routines/MoveTrickplayFiles.cs')
| -rw-r--r-- | Jellyfin.Server/Migrations/Routines/MoveTrickplayFiles.cs | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/Jellyfin.Server/Migrations/Routines/MoveTrickplayFiles.cs b/Jellyfin.Server/Migrations/Routines/MoveTrickplayFiles.cs new file mode 100644 index 000000000..e8abee95a --- /dev/null +++ b/Jellyfin.Server/Migrations/Routines/MoveTrickplayFiles.cs @@ -0,0 +1,73 @@ +using System; +using System.Globalization; +using System.IO; +using DiscUtils; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Trickplay; + +namespace Jellyfin.Server.Migrations.Routines; + +/// <summary> +/// Migration to move trickplay files to the new directory. +/// </summary> +public class MoveTrickplayFiles : IMigrationRoutine +{ + private readonly ITrickplayManager _trickplayManager; + private readonly IFileSystem _fileSystem; + private readonly ILibraryManager _libraryManager; + + /// <summary> + /// Initializes a new instance of the <see cref="MoveTrickplayFiles"/> class. + /// </summary> + /// <param name="trickplayManager">Instance of the <see cref="ITrickplayManager"/> interface.</param> + /// <param name="fileSystem">Instance of the <see cref="IFileSystem"/> interface.</param> + /// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param> + public MoveTrickplayFiles(ITrickplayManager trickplayManager, IFileSystem fileSystem, ILibraryManager libraryManager) + { + _trickplayManager = trickplayManager; + _fileSystem = fileSystem; + _libraryManager = libraryManager; + } + + /// <inheritdoc /> + public Guid Id => new("4EF123D5-8EFF-4B0B-869D-3AED07A60E1B"); + + /// <inheritdoc /> + public string Name => "MoveTrickplayFiles"; + + /// <inheritdoc /> + public bool PerformOnNewInstall => true; + + /// <inheritdoc /> + public void Perform() + { + var trickplayItems = _trickplayManager.GetTrickplayItemsAsync().GetAwaiter().GetResult(); + foreach (var itemId in trickplayItems) + { + var resolutions = _trickplayManager.GetTrickplayResolutions(itemId).GetAwaiter().GetResult(); + var item = _libraryManager.GetItemById(itemId); + if (item is null) + { + continue; + } + + foreach (var resolution in resolutions) + { + var oldPath = GetOldTrickplayDirectory(item, resolution.Key); + var newPath = _trickplayManager.GetTrickplayDirectory(item, resolution.Value.TileWidth, resolution.Value.TileHeight, resolution.Value.Width, false); + if (_fileSystem.DirectoryExists(oldPath)) + { + _fileSystem.MoveDirectory(oldPath, newPath); + } + } + } + } + + private string GetOldTrickplayDirectory(BaseItem item, int? width = null) + { + var path = Path.Combine(item.GetInternalMetadataPath(), "trickplay"); + + return width.HasValue ? Path.Combine(path, width.Value.ToString(CultureInfo.InvariantCulture)) : path; + } +} |
