| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using System.Globalization; |
| | 4 | | using System.IO; |
| | 5 | | using MediaBrowser.Common.Configuration; |
| | 6 | | using MediaBrowser.Controller.Configuration; |
| | 7 | | using MediaBrowser.Controller.Entities; |
| | 8 | | using MediaBrowser.Controller.IO; |
| | 9 | |
|
| | 10 | | namespace Emby.Server.Implementations.Library; |
| | 11 | |
|
| | 12 | | /// <summary> |
| | 13 | | /// IPathManager implementation. |
| | 14 | | /// </summary> |
| | 15 | | public 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 | | { |
| 21 | 29 | | _config = config; |
| 21 | 30 | | _appPaths = appPaths; |
| 21 | 31 | | } |
| | 32 | |
|
| 0 | 33 | | private string SubtitleCachePath => Path.Combine(_appPaths.DataPath, "subtitles"); |
| | 34 | |
|
| 0 | 35 | | private string AttachmentCachePath => Path.Combine(_appPaths.DataPath, "attachments"); |
| | 36 | |
|
| | 37 | | /// <inheritdoc /> |
| | 38 | | public string GetAttachmentPath(string mediaSourceId, string fileName) |
| | 39 | | { |
| 0 | 40 | | return Path.Combine(GetAttachmentFolderPath(mediaSourceId), fileName); |
| | 41 | | } |
| | 42 | |
|
| | 43 | | /// <inheritdoc /> |
| | 44 | | public string GetAttachmentFolderPath(string mediaSourceId) |
| | 45 | | { |
| 0 | 46 | | var id = Guid.Parse(mediaSourceId).ToString("D", CultureInfo.InvariantCulture).AsSpan(); |
| | 47 | |
|
| 0 | 48 | | return Path.Join(AttachmentCachePath, id[..2], id); |
| | 49 | | } |
| | 50 | |
|
| | 51 | | /// <inheritdoc /> |
| | 52 | | public string GetSubtitleFolderPath(string mediaSourceId) |
| | 53 | | { |
| 0 | 54 | | var id = Guid.Parse(mediaSourceId).ToString("D", CultureInfo.InvariantCulture).AsSpan(); |
| | 55 | |
|
| 0 | 56 | | return Path.Join(SubtitleCachePath, id[..2], id); |
| | 57 | | } |
| | 58 | |
|
| | 59 | | /// <inheritdoc /> |
| | 60 | | public string GetSubtitlePath(string mediaSourceId, int streamIndex, string extension) |
| | 61 | | { |
| 0 | 62 | | return Path.Combine(GetSubtitleFolderPath(mediaSourceId), streamIndex.ToString(CultureInfo.InvariantCulture) + e |
| | 63 | | } |
| | 64 | |
|
| | 65 | | /// <inheritdoc /> |
| | 66 | | public string GetTrickplayDirectory(BaseItem item, bool saveWithMedia = false) |
| | 67 | | { |
| 0 | 68 | | var id = item.Id.ToString("D", CultureInfo.InvariantCulture).AsSpan(); |
| | 69 | |
|
| 0 | 70 | | return saveWithMedia |
| 0 | 71 | | ? Path.Combine(item.ContainingFolderPath, Path.ChangeExtension(Path.GetFileName(item.Path), ".trickplay")) |
| 0 | 72 | | : Path.Join(_config.ApplicationPaths.TrickplayPath, id[..2], id); |
| | 73 | | } |
| | 74 | |
|
| | 75 | | /// <inheritdoc/> |
| | 76 | | public string GetChapterImageFolderPath(BaseItem item) |
| | 77 | | { |
| 0 | 78 | | return Path.Combine(item.GetInternalMetadataPath(), "chapters"); |
| | 79 | | } |
| | 80 | |
|
| | 81 | | /// <inheritdoc/> |
| | 82 | | public string GetChapterImagePath(BaseItem item, long chapterPositionTicks) |
| | 83 | | { |
| 0 | 84 | | var filename = item.DateModified.Ticks.ToString(CultureInfo.InvariantCulture) + "_" + chapterPositionTicks.ToStr |
| | 85 | |
|
| 0 | 86 | | return Path.Combine(GetChapterImageFolderPath(item), filename); |
| | 87 | | } |
| | 88 | |
|
| | 89 | | /// <inheritdoc/> |
| | 90 | | public IReadOnlyList<string> GetExtractedDataPaths(BaseItem item) |
| | 91 | | { |
| 0 | 92 | | var mediaSourceId = item.Id.ToString("N", CultureInfo.InvariantCulture); |
| 0 | 93 | | return [ |
| 0 | 94 | | GetAttachmentFolderPath(mediaSourceId), |
| 0 | 95 | | GetSubtitleFolderPath(mediaSourceId), |
| 0 | 96 | | GetTrickplayDirectory(item, false), |
| 0 | 97 | | GetTrickplayDirectory(item, true), |
| 0 | 98 | | GetChapterImageFolderPath(item) |
| 0 | 99 | | ]; |
| | 100 | | } |
| | 101 | | } |