| | 1 | | using System.IO; |
| | 2 | | using System.Linq; |
| | 3 | | using System.Threading; |
| | 4 | | using System.Threading.Tasks; |
| | 5 | | using MediaBrowser.Controller.Entities; |
| | 6 | | using MediaBrowser.Controller.IO; |
| | 7 | | using MediaBrowser.Controller.MediaSegments; |
| | 8 | | using MediaBrowser.Controller.Trickplay; |
| | 9 | |
|
| | 10 | | namespace Emby.Server.Implementations.Library; |
| | 11 | |
|
| | 12 | | /// <summary> |
| | 13 | | /// IExternalDataManager implementation. |
| | 14 | | /// </summary> |
| | 15 | | public class ExternalDataManager : IExternalDataManager |
| | 16 | | { |
| | 17 | | private readonly IKeyframeManager _keyframeManager; |
| | 18 | | private readonly IMediaSegmentManager _mediaSegmentManager; |
| | 19 | | private readonly IPathManager _pathManager; |
| | 20 | | private readonly ITrickplayManager _trickplayManager; |
| | 21 | |
|
| | 22 | | /// <summary> |
| | 23 | | /// Initializes a new instance of the <see cref="ExternalDataManager"/> class. |
| | 24 | | /// </summary> |
| | 25 | | /// <param name="keyframeManager">The keyframe manager.</param> |
| | 26 | | /// <param name="mediaSegmentManager">The media segment manager.</param> |
| | 27 | | /// <param name="pathManager">The path manager.</param> |
| | 28 | | /// <param name="trickplayManager">The trickplay manager.</param> |
| | 29 | | public ExternalDataManager( |
| | 30 | | IKeyframeManager keyframeManager, |
| | 31 | | IMediaSegmentManager mediaSegmentManager, |
| | 32 | | IPathManager pathManager, |
| | 33 | | ITrickplayManager trickplayManager) |
| | 34 | | { |
| 21 | 35 | | _keyframeManager = keyframeManager; |
| 21 | 36 | | _mediaSegmentManager = mediaSegmentManager; |
| 21 | 37 | | _pathManager = pathManager; |
| 21 | 38 | | _trickplayManager = trickplayManager; |
| 21 | 39 | | } |
| | 40 | |
|
| | 41 | | /// <inheritdoc/> |
| | 42 | | public async Task DeleteExternalItemDataAsync(BaseItem item, CancellationToken cancellationToken) |
| | 43 | | { |
| | 44 | | var validPaths = _pathManager.GetExtractedDataPaths(item).Where(Directory.Exists).ToList(); |
| | 45 | | var itemId = item.Id; |
| | 46 | | if (validPaths.Count > 0) |
| | 47 | | { |
| | 48 | | foreach (var path in validPaths) |
| | 49 | | { |
| | 50 | | Directory.Delete(path, true); |
| | 51 | | } |
| | 52 | | } |
| | 53 | |
|
| | 54 | | await _keyframeManager.DeleteKeyframeDataAsync(itemId, cancellationToken).ConfigureAwait(false); |
| | 55 | | await _mediaSegmentManager.DeleteSegmentsAsync(itemId, cancellationToken).ConfigureAwait(false); |
| | 56 | | await _trickplayManager.DeleteTrickplayDataAsync(itemId, cancellationToken).ConfigureAwait(false); |
| | 57 | | } |
| | 58 | | } |