< Summary - Jellyfin

Information
Class: Emby.Server.Implementations.Library.PathManager
Assembly: Emby.Server.Implementations
File(s): /srv/git/jellyfin/Emby.Server.Implementations/Library/PathManager.cs
Line coverage
11%
Covered lines: 3
Uncovered lines: 23
Coverable lines: 26
Total lines: 101
Line coverage: 11.5%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

File(s)

/srv/git/jellyfin/Emby.Server.Implementations/Library/PathManager.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Globalization;
 4using System.IO;
 5using MediaBrowser.Common.Configuration;
 6using MediaBrowser.Controller.Configuration;
 7using MediaBrowser.Controller.Entities;
 8using MediaBrowser.Controller.IO;
 9
 10namespace Emby.Server.Implementations.Library;
 11
 12/// <summary>
 13/// IPathManager implementation.
 14/// </summary>
 15public class PathManager : IPathManager
 16{
 17    private readonly IServerConfigurationManager _config;
 18    private readonly IApplicationPaths _appPaths;
 19
 20    /// <summary>
 21    /// Initializes a new instance of the <see cref="PathManager"/> class.
 22    /// </summary>
 23    /// <param name="config">The server configuration manager.</param>
 24    /// <param name="appPaths">The application paths.</param>
 25    public PathManager(
 26        IServerConfigurationManager config,
 27        IApplicationPaths appPaths)
 28    {
 2129        _config = config;
 2130        _appPaths = appPaths;
 2131    }
 32
 033    private string SubtitleCachePath => Path.Combine(_appPaths.DataPath, "subtitles");
 34
 035    private string AttachmentCachePath => Path.Combine(_appPaths.DataPath, "attachments");
 36
 37    /// <inheritdoc />
 38    public string GetAttachmentPath(string mediaSourceId, string fileName)
 39    {
 040        return Path.Combine(GetAttachmentFolderPath(mediaSourceId), fileName);
 41    }
 42
 43    /// <inheritdoc />
 44    public string GetAttachmentFolderPath(string mediaSourceId)
 45    {
 046        var id = Guid.Parse(mediaSourceId).ToString("D", CultureInfo.InvariantCulture).AsSpan();
 47
 048        return Path.Join(AttachmentCachePath, id[..2], id);
 49    }
 50
 51    /// <inheritdoc />
 52    public string GetSubtitleFolderPath(string mediaSourceId)
 53    {
 054        var id = Guid.Parse(mediaSourceId).ToString("D", CultureInfo.InvariantCulture).AsSpan();
 55
 056        return Path.Join(SubtitleCachePath, id[..2], id);
 57    }
 58
 59    /// <inheritdoc />
 60    public string GetSubtitlePath(string mediaSourceId, int streamIndex, string extension)
 61    {
 062        return Path.Combine(GetSubtitleFolderPath(mediaSourceId), streamIndex.ToString(CultureInfo.InvariantCulture) + e
 63    }
 64
 65    /// <inheritdoc />
 66    public string GetTrickplayDirectory(BaseItem item, bool saveWithMedia = false)
 67    {
 068        var id = item.Id.ToString("D", CultureInfo.InvariantCulture).AsSpan();
 69
 070        return saveWithMedia
 071            ? Path.Combine(item.ContainingFolderPath, Path.ChangeExtension(Path.GetFileName(item.Path), ".trickplay"))
 072            : Path.Join(_config.ApplicationPaths.TrickplayPath, id[..2], id);
 73    }
 74
 75    /// <inheritdoc/>
 76    public string GetChapterImageFolderPath(BaseItem item)
 77    {
 078        return Path.Combine(item.GetInternalMetadataPath(), "chapters");
 79    }
 80
 81    /// <inheritdoc/>
 82    public string GetChapterImagePath(BaseItem item, long chapterPositionTicks)
 83    {
 084        var filename = item.DateModified.Ticks.ToString(CultureInfo.InvariantCulture) + "_" + chapterPositionTicks.ToStr
 85
 086        return Path.Combine(GetChapterImageFolderPath(item), filename);
 87    }
 88
 89    /// <inheritdoc/>
 90    public IReadOnlyList<string> GetExtractedDataPaths(BaseItem item)
 91    {
 092        var mediaSourceId = item.Id.ToString("N", CultureInfo.InvariantCulture);
 093        return [
 094            GetAttachmentFolderPath(mediaSourceId),
 095            GetSubtitleFolderPath(mediaSourceId),
 096            GetTrickplayDirectory(item, false),
 097            GetTrickplayDirectory(item, true),
 098            GetChapterImageFolderPath(item)
 099        ];
 100    }
 101}