|
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 |
| -} |
| 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 | +using System.Linq; |
| 19 | + |
| 20 | +namespace StrmExtract |
| 21 | +{ |
| 22 | + public class ExtractTask : IScheduledTask |
| 23 | + { |
| 24 | + private readonly ILogger _logger; |
| 25 | + private readonly ILibraryManager _libraryManager; |
| 26 | + private readonly IFileSystem _fileSystem; |
| 27 | + private readonly ILibraryMonitor _libraryMonitor; |
| 28 | + private readonly IMediaProbeManager _mediaProbeManager; |
| 29 | + |
| 30 | + public ExtractTask(ILibraryManager libraryManager, |
| 31 | + ILogger logger, |
| 32 | + IFileSystem fileSystem, |
| 33 | + ILibraryMonitor libraryMonitor, |
| 34 | + IMediaProbeManager prob) |
| 35 | + { |
| 36 | + _libraryManager = libraryManager; |
| 37 | + _logger = logger; |
| 38 | + _fileSystem = fileSystem; |
| 39 | + _libraryMonitor = libraryMonitor; |
| 40 | + _mediaProbeManager = prob; |
| 41 | + } |
| 42 | + |
| 43 | + public async Task Execute(CancellationToken cancellationToken, IProgress<double> progress) |
| 44 | + { |
| 45 | + _logger.Info("MediaExtract - Task Execute"); |
| 46 | + |
| 47 | + InternalItemsQuery query = new InternalItemsQuery(); |
| 48 | + |
| 49 | + query.HasPath = true; |
| 50 | + query.HasContainer = false; |
| 51 | + query.ExcludeItemTypes = new string[] { "Folder", "CollectionFolder", "UserView", "Series", "Season", "Trailer", "Playlist" }; |
| 52 | + |
| 53 | + BaseItem[] results = _libraryManager.GetItemList(query); |
| 54 | + _logger.Info("MediaExtract - Scan items : " + results.Length); |
| 55 | + List<BaseItem> items = new List<BaseItem>(); |
| 56 | + foreach(BaseItem item in results) |
| 57 | + { |
| 58 | + if(!string.IsNullOrEmpty(item.Path) && |
| 59 | + (item.Path.Contains("softlink") || item.Path.Contains("strm")) && |
| 60 | + item.GetMediaStreams().Count == 0) |
| 61 | + { |
| 62 | + items.Add(item); |
| 63 | + _logger.Info("MediaExtract - Item added : " + " - " + item.Path); |
| 64 | + } |
| 65 | + else |
| 66 | + { |
| 67 | + _logger.Info("MediaExtract - Item dropped : " + " - " + item.Path + " - MediaStreams: " + item.GetMediaStreams().Count); |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + _logger.Info("MediaExtract - Nums of targets : " + items.Count); |
| 72 | + |
| 73 | + double total = items.Count; |
| 74 | + int current = 0; |
| 75 | + foreach(BaseItem item in items) |
| 76 | + { |
| 77 | + if (cancellationToken.IsCancellationRequested) |
| 78 | + { |
| 79 | + _logger.Info("MediaExtract - Task Cancelled"); |
| 80 | + break; |
| 81 | + } |
| 82 | + double percent_done = (current / total) * 100; |
| 83 | + progress.Report(percent_done); |
| 84 | + |
| 85 | + MetadataRefreshOptions options = new MetadataRefreshOptions(_fileSystem); |
| 86 | + options.EnableRemoteContentProbe = true; |
| 87 | + options.ReplaceAllMetadata = true; |
| 88 | + options.EnableThumbnailImageExtraction = false; |
| 89 | + options.ImageRefreshMode = MetadataRefreshMode.ValidationOnly; |
| 90 | + options.MetadataRefreshMode = MetadataRefreshMode.ValidationOnly; |
| 91 | + options.ReplaceAllImages = false; |
| 92 | + |
| 93 | + ItemUpdateType resp = await item.RefreshMetadata(options, cancellationToken); |
| 94 | + |
| 95 | + _logger.Info("MediaExtract - " + current + "/" + total + " - " + item.Path); |
| 96 | + |
| 97 | + //Thread.Sleep(5000); |
| 98 | + current++; |
| 99 | + } |
| 100 | + |
| 101 | + progress.Report(100.0); |
| 102 | + _logger.Info("MediaExtract - Task Complete"); |
| 103 | + } |
| 104 | + |
| 105 | + public string Category |
| 106 | + { |
| 107 | + get { return "Media Extract"; } |
| 108 | + } |
| 109 | + |
| 110 | + public string Key |
| 111 | + { |
| 112 | + get { return "MediaExtract Task"; } |
| 113 | + } |
| 114 | + |
| 115 | + public string Description |
| 116 | + { |
| 117 | + get { return "Run Media Info Extraction"; } |
| 118 | + } |
| 119 | + |
| 120 | + public string Name |
| 121 | + { |
| 122 | + get { return "Process Media targets"; } |
| 123 | + } |
| 124 | + |
| 125 | + public IEnumerable<TaskTriggerInfo> GetDefaultTriggers() |
| 126 | + { |
| 127 | + return new[] |
| 128 | + { |
| 129 | + new TaskTriggerInfo |
| 130 | + { |
| 131 | + Type = TaskTriggerInfo.TriggerDaily, |
| 132 | + TimeOfDayTicks = TimeSpan.FromHours(3).Ticks, |
| 133 | + MaxRuntimeTicks = TimeSpan.FromHours(24).Ticks |
| 134 | + } |
| 135 | + }; |
| 136 | + } |
| 137 | + } |
| 138 | +} |
0 commit comments