| | 1 | | using System; |
| | 2 | | using System.Globalization; |
| | 3 | | using System.IO; |
| | 4 | | using MediaBrowser.Common.Configuration; |
| | 5 | | using MediaBrowser.Controller.Configuration; |
| | 6 | | using MediaBrowser.Controller.Entities; |
| | 7 | | using MediaBrowser.Controller.IO; |
| | 8 | |
|
| | 9 | | namespace Emby.Server.Implementations.Library; |
| | 10 | |
|
| | 11 | | /// <summary> |
| | 12 | | /// IPathManager implementation. |
| | 13 | | /// </summary> |
| | 14 | | public class PathManager : IPathManager |
| | 15 | | { |
| | 16 | | private readonly IServerConfigurationManager _config; |
| | 17 | | private readonly IApplicationPaths _appPaths; |
| | 18 | |
|
| | 19 | | /// <summary> |
| | 20 | | /// Initializes a new instance of the <see cref="PathManager"/> class. |
| | 21 | | /// </summary> |
| | 22 | | /// <param name="config">The server configuration manager.</param> |
| | 23 | | /// <param name="appPaths">The application paths.</param> |
| | 24 | | public PathManager( |
| | 25 | | IServerConfigurationManager config, |
| | 26 | | IApplicationPaths appPaths) |
| | 27 | | { |
| 21 | 28 | | _config = config; |
| 21 | 29 | | _appPaths = appPaths; |
| 21 | 30 | | } |
| | 31 | |
|
| 0 | 32 | | private string SubtitleCachePath => Path.Combine(_appPaths.DataPath, "subtitles"); |
| | 33 | |
|
| 0 | 34 | | private string AttachmentCachePath => Path.Combine(_appPaths.DataPath, "attachments"); |
| | 35 | |
|
| | 36 | | /// <inheritdoc /> |
| | 37 | | public string GetAttachmentPath(string mediaSourceId, string fileName) |
| | 38 | | { |
| 0 | 39 | | return Path.Join(GetAttachmentFolderPath(mediaSourceId), fileName); |
| | 40 | | } |
| | 41 | |
|
| | 42 | | /// <inheritdoc /> |
| | 43 | | public string GetAttachmentFolderPath(string mediaSourceId) |
| | 44 | | { |
| 0 | 45 | | var id = Guid.Parse(mediaSourceId).ToString("D", CultureInfo.InvariantCulture).AsSpan(); |
| | 46 | |
|
| 0 | 47 | | return Path.Join(AttachmentCachePath, id[..2], id); |
| | 48 | | } |
| | 49 | |
|
| | 50 | | /// <inheritdoc /> |
| | 51 | | public string GetSubtitleFolderPath(string mediaSourceId) |
| | 52 | | { |
| 0 | 53 | | var id = Guid.Parse(mediaSourceId).ToString("D", CultureInfo.InvariantCulture).AsSpan(); |
| | 54 | |
|
| 0 | 55 | | return Path.Join(SubtitleCachePath, id[..2], id); |
| | 56 | | } |
| | 57 | |
|
| | 58 | | /// <inheritdoc /> |
| | 59 | | public string GetSubtitlePath(string mediaSourceId, int streamIndex, string extension) |
| | 60 | | { |
| 0 | 61 | | return Path.Join(GetSubtitleFolderPath(mediaSourceId), streamIndex.ToString(CultureInfo.InvariantCulture) + exte |
| | 62 | | } |
| | 63 | |
|
| | 64 | | /// <inheritdoc /> |
| | 65 | | public string GetTrickplayDirectory(BaseItem item, bool saveWithMedia = false) |
| | 66 | | { |
| 0 | 67 | | var id = item.Id.ToString("D", CultureInfo.InvariantCulture).AsSpan(); |
| | 68 | |
|
| 0 | 69 | | return saveWithMedia |
| 0 | 70 | | ? Path.Combine(item.ContainingFolderPath, Path.ChangeExtension(item.Path, ".trickplay")) |
| 0 | 71 | | : Path.Join(_config.ApplicationPaths.TrickplayPath, id[..2], id); |
| | 72 | | } |
| | 73 | | } |