|
| 1 | +using MediaBrowser.Common.Configuration; |
| 2 | +using MediaBrowser.Controller.Library; |
| 3 | +using MediaBrowser.Controller.MediaEncoding; |
| 4 | +using MediaBrowser.Model.IO; |
| 5 | +using MediaBrowser.Model.Logging; |
| 6 | +using MediaBrowser.Model.Tasks; |
| 7 | +using System; |
| 8 | +using System.Collections.Generic; |
| 9 | +using System.Text; |
| 10 | +using System.Threading.Tasks; |
| 11 | +using System.Threading; |
| 12 | +using MediaBrowser.Model.MediaInfo; |
| 13 | +using MediaBrowser.Model.Dto; |
| 14 | +using MediaBrowser.Controller.Entities; |
| 15 | +using MediaBrowser.Model.Configuration; |
| 16 | +using MediaBrowser.Controller.Providers; |
| 17 | +using System.Collections; |
| 18 | + |
| 19 | +namespace StrmExtract |
| 20 | +{ |
| 21 | + public class ExtractTask : IScheduledTask |
| 22 | + { |
| 23 | + private readonly ILogger _logger; |
| 24 | + private readonly ILibraryManager _libraryManager; |
| 25 | + private readonly IFileSystem _fileSystem; |
| 26 | + private readonly ILibraryMonitor _libraryMonitor; |
| 27 | + private readonly IMediaProbeManager _mediaProbeManager; |
| 28 | + |
| 29 | + public ExtractTask(ILibraryManager libraryManager, |
| 30 | + ILogger logger, |
| 31 | + IFileSystem fileSystem, |
| 32 | + ILibraryMonitor libraryMonitor, |
| 33 | + IMediaProbeManager prob) |
| 34 | + { |
| 35 | + _libraryManager = libraryManager; |
| 36 | + _logger = logger; |
| 37 | + _fileSystem = fileSystem; |
| 38 | + _libraryMonitor = libraryMonitor; |
| 39 | + _mediaProbeManager = prob; |
| 40 | + } |
| 41 | + |
| 42 | + public async Task Execute(CancellationToken cancellationToken, IProgress<double> progress) |
| 43 | + { |
| 44 | + _logger.Info("StrmExtract - Task Execute"); |
| 45 | + |
| 46 | + InternalItemsQuery query = new InternalItemsQuery(); |
| 47 | + |
| 48 | + query.HasPath = true; |
| 49 | + query.HasContainer = false; |
| 50 | + query.ExcludeItemTypes = new string[] { "Folder", "CollectionFolder", "UserView", "Series", "Season", "Trailer", "Playlist" }; |
| 51 | + |
| 52 | + BaseItem[] results = _libraryManager.GetItemList(query); |
| 53 | + _logger.Info("StrmExtract - Number of items before : " + results.Length); |
| 54 | + List<BaseItem> items = new List<BaseItem>(); |
| 55 | + foreach(BaseItem item in results) |
| 56 | + { |
| 57 | + if(!string.IsNullOrEmpty(item.Path) && |
| 58 | + item.Path.EndsWith(".strm", StringComparison.InvariantCultureIgnoreCase) && |
| 59 | + item.GetMediaStreams().Count == 0) |
| 60 | + { |
| 61 | + items.Add(item); |
| 62 | + } |
| 63 | + else |
| 64 | + { |
| 65 | + _logger.Info("StrmExtract - Item dropped : " + item.Name + " - " + item.Path + " - " + item.GetType() + " - " + item.GetMediaStreams().Count); |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + _logger.Info("StrmExtract - Number of items after : " + items.Count); |
| 70 | + |
| 71 | + double total = items.Count; |
| 72 | + int current = 0; |
| 73 | + foreach(BaseItem item in items) |
| 74 | + { |
| 75 | + if (cancellationToken.IsCancellationRequested) |
| 76 | + { |
| 77 | + _logger.Info("StrmExtract - Task Cancelled"); |
| 78 | + break; |
| 79 | + } |
| 80 | + double percent_done = (current / total) * 100; |
| 81 | + progress.Report(percent_done); |
| 82 | + |
| 83 | + MetadataRefreshOptions options = new MetadataRefreshOptions(_fileSystem); |
| 84 | + options.EnableRemoteContentProbe = true; |
| 85 | + options.ReplaceAllMetadata = true; |
| 86 | + options.EnableThumbnailImageExtraction = false; |
| 87 | + options.ImageRefreshMode = MetadataRefreshMode.ValidationOnly; |
| 88 | + options.MetadataRefreshMode = MetadataRefreshMode.ValidationOnly; |
| 89 | + options.ReplaceAllImages = false; |
| 90 | + |
| 91 | + ItemUpdateType resp = await item.RefreshMetadata(options, cancellationToken); |
| 92 | + |
| 93 | + _logger.Info("StrmExtract - " + current + "/" + total + " - " + item.Path); |
| 94 | + |
| 95 | + //Thread.Sleep(5000); |
| 96 | + current++; |
| 97 | + } |
| 98 | + |
| 99 | + progress.Report(100.0); |
| 100 | + _logger.Info("StrmExtract - Task Complete"); |
| 101 | + |
| 102 | + /* |
| 103 | + LibraryOptions lib_options = new LibraryOptions(); |
| 104 | + List<MediaSourceInfo> sources = item.GetMediaSources(true, true, lib_options); |
| 105 | +
|
| 106 | + _logger.Info("StrmExtract - GetMediaSources : " + sources.Count); |
| 107 | +
|
| 108 | + MediaInfoRequest request = new MediaInfoRequest(); |
| 109 | +
|
| 110 | + MediaSourceInfo mediaSource = sources[0]; |
| 111 | + request.MediaSource = mediaSource; |
| 112 | +
|
| 113 | + _logger.Info("StrmExtract - GetMediaInfo"); |
| 114 | + MediaInfo info = await _mediaProbeManager.GetMediaInfo(request, cancellationToken); |
| 115 | +
|
| 116 | + _logger.Info("StrmExtract - Extracting Strm info " + info); |
| 117 | +
|
| 118 | + _logger.Info("StrmExtract - Extracting Strm info : url - " + info.DirectStreamUrl); |
| 119 | + _logger.Info("StrmExtract - Extracting Strm info : runtime - " + info.RunTimeTicks); |
| 120 | + */ |
| 121 | + } |
| 122 | + |
| 123 | + public string Category |
| 124 | + { |
| 125 | + get { return "Strm Extract"; } |
| 126 | + } |
| 127 | + |
| 128 | + public string Key |
| 129 | + { |
| 130 | + get { return "StrmExtractTask"; } |
| 131 | + } |
| 132 | + |
| 133 | + public string Description |
| 134 | + { |
| 135 | + get { return "Run Strm Media Info Extraction"; } |
| 136 | + } |
| 137 | + |
| 138 | + public string Name |
| 139 | + { |
| 140 | + get { return "Process Strm targets"; } |
| 141 | + } |
| 142 | + |
| 143 | + public IEnumerable<TaskTriggerInfo> GetDefaultTriggers() |
| 144 | + { |
| 145 | + return new[] |
| 146 | + { |
| 147 | + new TaskTriggerInfo |
| 148 | + { |
| 149 | + Type = TaskTriggerInfo.TriggerDaily, |
| 150 | + TimeOfDayTicks = TimeSpan.FromHours(3).Ticks, |
| 151 | + MaxRuntimeTicks = TimeSpan.FromHours(24).Ticks |
| 152 | + } |
| 153 | + }; |
| 154 | + } |
| 155 | + } |
| 156 | +} |
0 commit comments