pull/13760/merge
Tim Eisele 3 weeks ago committed by GitHub
commit 89e5901cec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1,14 +1,14 @@
#pragma warning disable CS1591
using System;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Database.Implementations;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.IO;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Trickplay;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
@ -19,15 +19,18 @@ public class CleanDatabaseScheduledTask : ILibraryPostScanTask
private readonly ILibraryManager _libraryManager;
private readonly ILogger<CleanDatabaseScheduledTask> _logger;
private readonly IDbContextFactory<JellyfinDbContext> _dbProvider;
private readonly IPathManager _pathManager;
public CleanDatabaseScheduledTask(
ILibraryManager libraryManager,
ILogger<CleanDatabaseScheduledTask> logger,
IDbContextFactory<JellyfinDbContext> dbProvider)
IDbContextFactory<JellyfinDbContext> dbProvider,
IPathManager pathManager)
{
_libraryManager = libraryManager;
_logger = logger;
_dbProvider = dbProvider;
_pathManager = pathManager;
}
public async Task Run(IProgress<double> progress, CancellationToken cancellationToken)
@ -56,6 +59,40 @@ public class CleanDatabaseScheduledTask : ILibraryPostScanTask
{
_logger.LogInformation("Cleaning item {Item} type: {Type} path: {Path}", item.Name, item.GetType().Name, item.Path ?? string.Empty);
foreach (var mediaSource in item.GetMediaSources(false))
{
// Delete extracted subtitles
try
{
// Use SRT as a dummy parameter since it is required, we only need the parent directory.
var subtitleFolder = Path.GetDirectoryName(_pathManager.GetSubtitlePath(mediaSource.Id, 1, ".srt"));
if (Directory.Exists(subtitleFolder))
{
Directory.Delete(subtitleFolder, true);
}
}
catch (Exception e)
{
_logger.LogWarning("Failed to remove subtitle cache folder for {Item}: {Exception}", item.Id, e.Message);
}
// Delete extracted attachments
try
{
// Use steam id 1 as a dummy parameter since it is required, we only need the parent directory.
var attachmentFolder = Path.GetDirectoryName(_pathManager.GetAttachmentPath(mediaSource.Id, 1));
if (Directory.Exists(attachmentFolder))
{
Directory.Delete(attachmentFolder, true);
}
}
catch (Exception e)
{
_logger.LogWarning("Failed to remove attachment cache folder for {Item}: {Exception}", item.Id, e.Message);
}
}
// Delete item
_libraryManager.DeleteItem(item, new DeleteOptions
{
DeleteFileLocation = false

@ -492,7 +492,26 @@ namespace Emby.Server.Implementations.Library
if (item is Video video)
{
// Trickplay
list.Add(_pathManager.GetTrickplayDirectory(video));
// Subtitles and attachments
foreach (var mediaSource in item.GetMediaSources(false))
{
// Use SRT as a dummy parameter since it is required, we only need the parent directory.
var subtitleFolder = Path.GetDirectoryName(_pathManager.GetSubtitlePath(mediaSource.Id, 1, ".srt"));
if (subtitleFolder is not null)
{
list.Add(subtitleFolder);
}
// Use steam id 1 as a dummy parameter since it is required, we only need the parent directory.
var attachmentFolder = Path.GetDirectoryName(_pathManager.GetAttachmentPath(mediaSource.Id, 1));
if (attachmentFolder is not null)
{
list.Add(attachmentFolder);
}
}
}
return list;

@ -1,5 +1,7 @@
using System;
using System.Globalization;
using System.IO;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.IO;
@ -12,22 +14,44 @@ namespace Emby.Server.Implementations.Library;
public class PathManager : IPathManager
{
private readonly IServerConfigurationManager _config;
private readonly IApplicationPaths _appPaths;
/// <summary>
/// Initializes a new instance of the <see cref="PathManager"/> class.
/// </summary>
/// <param name="config">The server configuration manager.</param>
/// <param name="appPaths">The application paths.</param>
public PathManager(
IServerConfigurationManager config)
IServerConfigurationManager config,
IApplicationPaths appPaths)
{
_config = config;
_appPaths = appPaths;
}
private string SubtitleCachePath => Path.Combine(_appPaths.DataPath, "subtitles");
private string AttachmentCachePath => Path.Combine(_appPaths.DataPath, "attachments");
/// <inheritdoc />
public string GetAttachmentPath(string mediaSourceId, int attachmentIndex)
{
var id = Guid.Parse(mediaSourceId);
return Path.Join(AttachmentCachePath, id.ToString("D", CultureInfo.InvariantCulture), attachmentIndex.ToString(CultureInfo.InvariantCulture));
}
/// <inheritdoc />
public string GetSubtitlePath(string mediaSourceId, int streamIndex, string extension)
{
var id = Guid.Parse(mediaSourceId);
return Path.Join(SubtitleCachePath, id.ToString("D", CultureInfo.InvariantCulture), streamIndex.ToString(CultureInfo.InvariantCulture) + extension);
}
/// <inheritdoc />
public string GetTrickplayDirectory(BaseItem item, bool saveWithMedia = false)
{
var basePath = _config.ApplicationPaths.TrickplayPath;
var idString = item.Id.ToString("N", CultureInfo.InvariantCulture);
var idString = item.Id.ToString("D", CultureInfo.InvariantCulture);
return saveWithMedia
? Path.Combine(item.ContainingFolderPath, Path.ChangeExtension(item.Path, ".trickplay"))

@ -54,6 +54,7 @@ namespace Jellyfin.Server.Migrations
typeof(Routines.FixAudioData),
typeof(Routines.RemoveDuplicatePlaylistChildren),
typeof(Routines.MigrateLibraryDb),
typeof(Routines.MoveExtractedFiles),
typeof(Routines.MigrateRatingLevels),
typeof(Routines.MoveTrickplayFiles),
};

@ -80,6 +80,7 @@ internal class MigrateLibraryDb : IDatabaseMigrationRoutine
using (var operation = GetPreparedDbContext("Cleanup database"))
{
operation.JellyfinDbContext.AttachmentStreamInfos.ExecuteDelete();
operation.JellyfinDbContext.BaseItems.ExecuteDelete();
operation.JellyfinDbContext.ItemValues.ExecuteDelete();
operation.JellyfinDbContext.UserData.ExecuteDelete();
@ -251,6 +252,29 @@ internal class MigrateLibraryDb : IDatabaseMigrationRoutine
}
}
using (var operation = GetPreparedDbContext("moving AttachmentStreamInfos"))
{
const string mediaAttachmentQuery =
"""
SELECT ItemId, AttachmentIndex, Codec, CodecTag, Comment, filename, MIMEType
FROM mediaattachments
WHERE EXISTS(SELECT 1 FROM TypedBaseItems WHERE TypedBaseItems.guid = mediaattachments.ItemId)
""";
using (new TrackedMigrationStep("loading AttachmentStreamInfos", _logger))
{
foreach (SqliteDataReader dto in connection.Query(mediaAttachmentQuery))
{
operation.JellyfinDbContext.AttachmentStreamInfos.Add(GetMediaAttachment(dto));
}
}
using (new TrackedMigrationStep($"saving {operation.JellyfinDbContext.AttachmentStreamInfos.Local.Count} AttachmentStreamInfos entries", _logger))
{
operation.JellyfinDbContext.SaveChanges();
}
}
using (var operation = GetPreparedDbContext("moving People"))
{
const string personsQuery =
@ -709,6 +733,48 @@ internal class MigrateLibraryDb : IDatabaseMigrationRoutine
return item;
}
/// <summary>
/// Gets the attachment.
/// </summary>
/// <param name="reader">The reader.</param>
/// <returns>MediaAttachment.</returns>
private AttachmentStreamInfo GetMediaAttachment(SqliteDataReader reader)
{
var item = new AttachmentStreamInfo
{
Index = reader.GetInt32(1),
Item = null!,
ItemId = reader.GetGuid(0),
};
if (reader.TryGetString(2, out var codec))
{
item.Codec = codec;
}
if (reader.TryGetString(3, out var codecTag))
{
item.CodecTag = codecTag;
}
if (reader.TryGetString(4, out var comment))
{
item.Comment = comment;
}
if (reader.TryGetString(5, out var fileName))
{
item.Filename = fileName;
}
if (reader.TryGetString(6, out var mimeType))
{
item.MimeType = mimeType;
}
return item;
}
private (BaseItemEntity BaseItem, string[] LegacyUserDataKey) GetItem(SqliteDataReader reader)
{
var entity = new BaseItemEntity()

@ -0,0 +1,268 @@
#pragma warning disable CA5351 // Do Not Use Broken Cryptographic Algorithms
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using Jellyfin.Data.Enums;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.IO;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.MediaInfo;
using Microsoft.Extensions.Logging;
namespace Jellyfin.Server.Migrations.Routines;
/// <summary>
/// Migration to move extracted files to the new directories.
/// </summary>
public class MoveExtractedFiles : IDatabaseMigrationRoutine
{
private readonly IApplicationPaths _appPaths;
private readonly ILibraryManager _libraryManager;
private readonly ILogger<MoveExtractedFiles> _logger;
private readonly IMediaSourceManager _mediaSourceManager;
private readonly IPathManager _pathManager;
/// <summary>
/// Initializes a new instance of the <see cref="MoveExtractedFiles"/> class.
/// </summary>
/// <param name="appPaths">Instance of the <see cref="IApplicationPaths"/> interface.</param>
/// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>
/// <param name="logger">The logger.</param>
/// <param name="mediaSourceManager">Instance of the <see cref="IMediaSourceManager"/> interface.</param>
/// <param name="pathManager">Instance of the <see cref="IPathManager"/> interface.</param>
public MoveExtractedFiles(
IApplicationPaths appPaths,
ILibraryManager libraryManager,
ILogger<MoveExtractedFiles> logger,
IMediaSourceManager mediaSourceManager,
IPathManager pathManager)
{
_appPaths = appPaths;
_libraryManager = libraryManager;
_logger = logger;
_mediaSourceManager = mediaSourceManager;
_pathManager = pathManager;
}
private string SubtitleCachePath => Path.Combine(_appPaths.DataPath, "subtitles");
private string AttachmentCachePath => Path.Combine(_appPaths.DataPath, "attachments");
/// <inheritdoc />
public Guid Id => new("9063b0Ef-CFF1-4EDC-9A13-74093681A89B");
/// <inheritdoc />
public string Name => "MoveExtractedFiles";
/// <inheritdoc />
public bool PerformOnNewInstall => false;
/// <inheritdoc />
public void Perform()
{
const int Limit = 500;
int itemCount = 0, offset = 0;
var sw = Stopwatch.StartNew();
var itemsQuery = new InternalItemsQuery
{
MediaTypes = [MediaType.Video],
SourceTypes = [SourceType.Library],
IsVirtualItem = false,
IsFolder = false,
Limit = Limit,
StartIndex = offset,
EnableTotalRecordCount = true,
};
var records = _libraryManager.GetItemsResult(itemsQuery).TotalRecordCount;
_logger.LogInformation("Checking {Count} items for movable extracted files.", records);
// Make sure directories exist
Directory.CreateDirectory(SubtitleCachePath);
Directory.CreateDirectory(AttachmentCachePath);
itemsQuery.EnableTotalRecordCount = false;
do
{
itemsQuery.StartIndex = offset;
var result = _libraryManager.GetItemsResult(itemsQuery);
var items = result.Items;
foreach (var item in items)
{
if (MoveSubtitleAndAttachmentFiles(item))
{
itemCount++;
}
}
offset += Limit;
if (offset % 5_000 == 0)
{
_logger.LogInformation("Checked extracted files for {Count} items in {Time}.", offset, sw.Elapsed);
}
} while (offset < records);
_logger.LogInformation("Checked {Checked} items - Moved files for {Items} items in {Time}.", records, itemCount, sw.Elapsed);
// Get all subdirectories with 1 character names (those are the legacy directories)
var subdirectories = Directory.GetDirectories(SubtitleCachePath, "*", SearchOption.AllDirectories).Where(s => s.Length == SubtitleCachePath.Length + 2).ToList();
subdirectories.AddRange(Directory.GetDirectories(AttachmentCachePath, "*", SearchOption.AllDirectories).Where(s => s.Length == AttachmentCachePath.Length + 2));
// Remove all legacy subdirectories
foreach (var subdir in subdirectories)
{
Directory.Delete(subdir, true);
}
_logger.LogInformation("Cleaned up left over subtitles and attachments.");
}
private bool MoveSubtitleAndAttachmentFiles(BaseItem item)
{
var mediaStreams = item.GetMediaStreams().Where(s => s.Type == MediaStreamType.Subtitle && !s.IsExternal);
var modified = false;
foreach (var mediaStream in mediaStreams)
{
if (mediaStream.Codec is null)
{
continue;
}
var mediaStreamIndex = mediaStream.Index;
var extension = GetSubtitleExtension(mediaStream.Codec);
var oldSubtitleCachePath = GetOldSubtitleCachePath(item.Path, mediaStream.Index, extension);
if (string.IsNullOrEmpty(oldSubtitleCachePath) || !File.Exists(oldSubtitleCachePath))
{
continue;
}
var newSubtitleCachePath = _pathManager.GetSubtitlePath(item.Id.ToString("N", CultureInfo.InvariantCulture), mediaStreamIndex, extension);
if (File.Exists(newSubtitleCachePath))
{
File.Delete(oldSubtitleCachePath);
}
else
{
var newDirectory = Path.GetDirectoryName(newSubtitleCachePath);
if (newDirectory is not null)
{
Directory.CreateDirectory(newDirectory);
File.Move(oldSubtitleCachePath, newSubtitleCachePath, false);
_logger.LogDebug("Moved subtitle {Index} for {Item} from {Source} to {Destination}", mediaStreamIndex, item.Id, oldSubtitleCachePath, newSubtitleCachePath);
modified = true;
}
}
}
foreach (var attachment in _mediaSourceManager.GetMediaAttachments(item.Id))
{
var attachmentIndex = attachment.Index;
var oldAttachmentCachePath = GetOldAttachmentCachePath(item.Path, attachmentIndex);
if (string.IsNullOrEmpty(oldAttachmentCachePath) || !File.Exists(oldAttachmentCachePath))
{
continue;
}
var newAttachmentCachePath = _pathManager.GetAttachmentPath(item.Id.ToString("N", CultureInfo.InvariantCulture), attachmentIndex);
var newDirectory = Path.GetDirectoryName(newAttachmentCachePath);
if (File.Exists(newAttachmentCachePath))
{
File.Delete(oldAttachmentCachePath);
}
else
{
if (newDirectory is not null)
{
Directory.CreateDirectory(newDirectory);
File.Move(oldAttachmentCachePath, newAttachmentCachePath, false);
_logger.LogDebug("Moved attachment {Index} for {Item} from {Source} to {Destination}", attachmentIndex, item.Id, oldAttachmentCachePath, newAttachmentCachePath);
modified = true;
}
}
}
return modified;
}
private string? GetOldAttachmentCachePath(string? mediaPath, int attachmentStreamIndex)
{
if (mediaPath is null)
{
return null;
}
string filename;
var protocol = _mediaSourceManager.GetPathProtocol(mediaPath);
if (protocol == MediaProtocol.File)
{
DateTime? date;
try
{
date = File.GetLastWriteTimeUtc(mediaPath);
}
catch (IOException e)
{
_logger.LogDebug("Skipping attachment at index {Index} for {Path}: {Exception}", attachmentStreamIndex, mediaPath, e.Message);
return null;
}
filename = (mediaPath + attachmentStreamIndex.ToString(CultureInfo.InvariantCulture) + "_" + date.Value.Ticks.ToString(CultureInfo.InvariantCulture)).GetMD5().ToString("D", CultureInfo.InvariantCulture);
}
else
{
filename = (mediaPath + attachmentStreamIndex.ToString(CultureInfo.InvariantCulture)).GetMD5().ToString("D", CultureInfo.InvariantCulture);
}
return Path.Join(_appPaths.DataPath, "attachments", filename[..1], filename);
}
private string? GetOldSubtitleCachePath(string path, int streamIndex, string outputSubtitleExtension)
{
DateTime? date;
try
{
date = File.GetLastWriteTimeUtc(path);
}
catch (IOException e)
{
_logger.LogDebug("Skipping subtitle at index {Index} for {Path}: {Exception}", streamIndex, path, e.Message);
return null;
}
var ticksParam = string.Empty;
ReadOnlySpan<char> filename = new Guid(MD5.HashData(Encoding.Unicode.GetBytes(path + "_" + streamIndex.ToString(CultureInfo.InvariantCulture) + "_" + date.Value.Ticks.ToString(CultureInfo.InvariantCulture) + ticksParam))) + outputSubtitleExtension;
return Path.Join(SubtitleCachePath, filename[..1], filename);
}
private static string GetSubtitleExtension(string codec)
{
if (codec.ToLower(CultureInfo.InvariantCulture).Equals("ass", StringComparison.OrdinalIgnoreCase)
|| codec.ToLower(CultureInfo.InvariantCulture).Equals("ssa", StringComparison.OrdinalIgnoreCase))
{
return "." + codec;
}
else if (codec.Contains("pgs", StringComparison.OrdinalIgnoreCase))
{
return ".sup";
}
else
{
return ".srt";
}
}
}

@ -14,4 +14,21 @@ public interface IPathManager
/// <param name="saveWithMedia">Whether or not the tile should be saved next to the media file.</param>
/// <returns>The absolute path.</returns>
public string GetTrickplayDirectory(BaseItem item, bool saveWithMedia = false);
/// <summary>
/// Gets the path to the subtitle file.
/// </summary>
/// <param name="mediaSourceId">The media source id.</param>
/// <param name="streamIndex">The stream index.</param>
/// <param name="extension">The subtitle file extension.</param>
/// <returns>The absolute path.</returns>
public string GetSubtitlePath(string mediaSourceId, int streamIndex, string extension);
/// <summary>
/// Gets the path to the attachment file.
/// </summary>
/// <param name="mediaSourceId">The media source id.</param>
/// <param name="attachmentIndex">The stream index.</param>
/// <returns>The absolute path.</returns>
public string GetAttachmentPath(string mediaSourceId, int attachmentIndex);
}

@ -10,16 +10,15 @@ using System.Threading;
using System.Threading.Tasks;
using AsyncKeyedLock;
using MediaBrowser.Common;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.IO;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.MediaEncoding.Encoder;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.MediaInfo;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.MediaEncoding.Attachments
@ -27,10 +26,10 @@ namespace MediaBrowser.MediaEncoding.Attachments
public sealed class AttachmentExtractor : IAttachmentExtractor, IDisposable
{
private readonly ILogger<AttachmentExtractor> _logger;
private readonly IApplicationPaths _appPaths;
private readonly IFileSystem _fileSystem;
private readonly IMediaEncoder _mediaEncoder;
private readonly IMediaSourceManager _mediaSourceManager;
private readonly IPathManager _pathManager;
private readonly AsyncKeyedLocker<string> _semaphoreLocks = new(o =>
{
@ -40,16 +39,16 @@ namespace MediaBrowser.MediaEncoding.Attachments
public AttachmentExtractor(
ILogger<AttachmentExtractor> logger,
IApplicationPaths appPaths,
IFileSystem fileSystem,
IMediaEncoder mediaEncoder,
IMediaSourceManager mediaSourceManager)
IMediaSourceManager mediaSourceManager,
IPathManager pathManager)
{
_logger = logger;
_appPaths = appPaths;
_fileSystem = fileSystem;
_mediaEncoder = mediaEncoder;
_mediaSourceManager = mediaSourceManager;
_pathManager = pathManager;
}
/// <inheritdoc />
@ -248,7 +247,7 @@ namespace MediaBrowser.MediaEncoding.Attachments
{
await CacheAllAttachments(mediaPath, inputFile, mediaSource, cancellationToken).ConfigureAwait(false);
var outputPath = GetAttachmentCachePath(mediaPath, mediaSource, mediaAttachment.Index);
var outputPath = GetAttachmentCachePath(mediaSource, mediaAttachment.Index);
await ExtractAttachment(inputFile, mediaSource, mediaAttachment.Index, outputPath, cancellationToken)
.ConfigureAwait(false);
@ -268,7 +267,7 @@ namespace MediaBrowser.MediaEncoding.Attachments
{
foreach (var attachment in mediaSource.MediaAttachments)
{
var outputPath = GetAttachmentCachePath(mediaPath, mediaSource, attachment.Index);
var outputPath = GetAttachmentCachePath(mediaSource, attachment.Index);
var releaser = await _semaphoreLocks.LockAsync(outputPath, cancellationToken).ConfigureAwait(false);
@ -309,7 +308,7 @@ namespace MediaBrowser.MediaEncoding.Attachments
foreach (var attachmentId in extractableAttachmentIds)
{
var outputPath = GetAttachmentCachePath(mediaPath, mediaSource, attachmentId);
var outputPath = GetAttachmentCachePath(mediaSource, attachmentId);
Directory.CreateDirectory(Path.GetDirectoryName(outputPath) ?? throw new FileNotFoundException($"Calculated path ({outputPath}) is not valid."));
@ -510,21 +509,9 @@ namespace MediaBrowser.MediaEncoding.Attachments
_logger.LogInformation("ffmpeg attachment extraction completed for {InputPath} to {OutputPath}", inputPath, outputPath);
}
private string GetAttachmentCachePath(string mediaPath, MediaSourceInfo mediaSource, int attachmentStreamIndex)
private string GetAttachmentCachePath(MediaSourceInfo mediaSource, int attachmentStreamIndex)
{
string filename;
if (mediaSource.Protocol == MediaProtocol.File)
{
var date = _fileSystem.GetLastWriteTimeUtc(mediaPath);
filename = (mediaPath + attachmentStreamIndex.ToString(CultureInfo.InvariantCulture) + "_" + date.Ticks.ToString(CultureInfo.InvariantCulture)).GetMD5().ToString("D", CultureInfo.InvariantCulture);
}
else
{
filename = (mediaPath + attachmentStreamIndex.ToString(CultureInfo.InvariantCulture)).GetMD5().ToString("D", CultureInfo.InvariantCulture);
}
var prefix = filename.AsSpan(0, 1);
return Path.Join(_appPaths.DataPath, "attachments", prefix, filename);
return _pathManager.GetAttachmentPath(mediaSource.Id, attachmentStreamIndex);
}
/// <inheritdoc />

@ -13,10 +13,10 @@ using System.Threading;
using System.Threading.Tasks;
using AsyncKeyedLock;
using MediaBrowser.Common;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.IO;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Model.Dto;
@ -31,12 +31,12 @@ namespace MediaBrowser.MediaEncoding.Subtitles
public sealed class SubtitleEncoder : ISubtitleEncoder, IDisposable
{
private readonly ILogger<SubtitleEncoder> _logger;
private readonly IApplicationPaths _appPaths;
private readonly IFileSystem _fileSystem;
private readonly IMediaEncoder _mediaEncoder;
private readonly IHttpClientFactory _httpClientFactory;
private readonly IMediaSourceManager _mediaSourceManager;
private readonly ISubtitleParser _subtitleParser;
private readonly IPathManager _pathManager;
/// <summary>
/// The _semaphoreLocks.
@ -49,24 +49,22 @@ namespace MediaBrowser.MediaEncoding.Subtitles
public SubtitleEncoder(
ILogger<SubtitleEncoder> logger,
IApplicationPaths appPaths,
IFileSystem fileSystem,
IMediaEncoder mediaEncoder,
IHttpClientFactory httpClientFactory,
IMediaSourceManager mediaSourceManager,
ISubtitleParser subtitleParser)
ISubtitleParser subtitleParser,
IPathManager pathManager)
{
_logger = logger;
_appPaths = appPaths;
_fileSystem = fileSystem;
_mediaEncoder = mediaEncoder;
_httpClientFactory = httpClientFactory;
_mediaSourceManager = mediaSourceManager;
_subtitleParser = subtitleParser;
_pathManager = pathManager;
}
private string SubtitleCachePath => Path.Combine(_appPaths.DataPath, "subtitles");
private MemoryStream ConvertSubtitles(
Stream stream,
string inputFormat,
@ -830,26 +828,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
private string GetSubtitleCachePath(MediaSourceInfo mediaSource, int subtitleStreamIndex, string outputSubtitleExtension)
{
if (mediaSource.Protocol == MediaProtocol.File)
{
var ticksParam = string.Empty;
var date = _fileSystem.GetLastWriteTimeUtc(mediaSource.Path);
ReadOnlySpan<char> filename = (mediaSource.Path + "_" + subtitleStreamIndex.ToString(CultureInfo.InvariantCulture) + "_" + date.Ticks.ToString(CultureInfo.InvariantCulture) + ticksParam).GetMD5() + outputSubtitleExtension;
var prefix = filename.Slice(0, 1);
return Path.Join(SubtitleCachePath, prefix, filename);
}
else
{
ReadOnlySpan<char> filename = (mediaSource.Path + "_" + subtitleStreamIndex.ToString(CultureInfo.InvariantCulture)).GetMD5() + outputSubtitleExtension;
var prefix = filename.Slice(0, 1);
return Path.Join(SubtitleCachePath, prefix, filename);
}
return _pathManager.GetSubtitlePath(mediaSource.Id, subtitleStreamIndex, outputSubtitleExtension);
}
/// <inheritdoc />

@ -1,51 +1,49 @@
#nullable disable
namespace MediaBrowser.Model.Entities
namespace MediaBrowser.Model.Entities;
/// <summary>
/// Class MediaAttachment.
/// </summary>
public class MediaAttachment
{
/// <summary>
/// Class MediaAttachment.
/// Gets or sets the codec.
/// </summary>
public class MediaAttachment
{
/// <summary>
/// Gets or sets the codec.
/// </summary>
/// <value>The codec.</value>
public string Codec { get; set; }
/// <value>The codec.</value>
public string? Codec { get; set; }
/// <summary>
/// Gets or sets the codec tag.
/// </summary>
/// <value>The codec tag.</value>
public string CodecTag { get; set; }
/// <summary>
/// Gets or sets the codec tag.
/// </summary>
/// <value>The codec tag.</value>
public string? CodecTag { get; set; }
/// <summary>
/// Gets or sets the comment.
/// </summary>
/// <value>The comment.</value>
public string Comment { get; set; }
/// <summary>
/// Gets or sets the comment.
/// </summary>
/// <value>The comment.</value>
public string? Comment { get; set; }
/// <summary>
/// Gets or sets the index.
/// </summary>
/// <value>The index.</value>
public int Index { get; set; }
/// <summary>
/// Gets or sets the index.
/// </summary>
/// <value>The index.</value>
public int Index { get; set; }
/// <summary>
/// Gets or sets the filename.
/// </summary>
/// <value>The filename.</value>
public string FileName { get; set; }
/// <summary>
/// Gets or sets the filename.
/// </summary>
/// <value>The filename.</value>
public string? FileName { get; set; }
/// <summary>
/// Gets or sets the MIME type.
/// </summary>
/// <value>The MIME type.</value>
public string MimeType { get; set; }
/// <summary>
/// Gets or sets the MIME type.
/// </summary>
/// <value>The MIME type.</value>
public string? MimeType { get; set; }
/// <summary>
/// Gets or sets the delivery URL.
/// </summary>
/// <value>The delivery URL.</value>
public string DeliveryUrl { get; set; }
}
/// <summary>
/// Gets or sets the delivery URL.
/// </summary>
/// <value>The delivery URL.</value>
public string? DeliveryUrl { get; set; }
}

@ -25,7 +25,7 @@ public class AttachmentStreamInfo
/// <summary>
/// Gets or Sets the codec of the attachment.
/// </summary>
public required string Codec { get; set; }
public string? Codec { get; set; }
/// <summary>
/// Gets or Sets the codec tag of the attachment.

@ -0,0 +1,36 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Jellyfin.Server.Implementations.Migrations
{
/// <inheritdoc />
public partial class FixAttachmentMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Codec",
table: "AttachmentStreamInfos",
type: "TEXT",
nullable: true,
oldClrType: typeof(string),
oldType: "TEXT");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Codec",
table: "AttachmentStreamInfos",
type: "TEXT",
nullable: false,
defaultValue: string.Empty,
oldClrType: typeof(string),
oldType: "TEXT",
oldNullable: true);
}
}
}

@ -120,7 +120,6 @@ namespace Jellyfin.Server.Implementations.Migrations
.HasColumnType("INTEGER");
b.Property<string>("Codec")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("CodecTag")

Loading…
Cancel
Save