66using Microsoft . EntityFrameworkCore ;
77using Microsoft . Extensions . Logging ;
88using Ombi . Core ;
9+ using Ombi . Core . Services ;
910using Ombi . Helpers ;
1011using Ombi . Hubs ;
1112using Ombi . Notifications . Models ;
1213using Ombi . Schedule . Jobs . Plex . Models ;
14+ using Ombi . Settings . Settings . Models ;
1315using Ombi . Store . Entities ;
1416using Ombi . Store . Entities . Requests ;
1517using Ombi . Store . Repository ;
@@ -21,14 +23,15 @@ namespace Ombi.Schedule.Jobs.Plex
2123 public class PlexAvailabilityChecker : IPlexAvailabilityChecker
2224 {
2325 public PlexAvailabilityChecker ( IPlexContentRepository repo , ITvRequestRepository tvRequest , IMovieRequestRepository movies ,
24- INotificationHelper notification , ILogger < PlexAvailabilityChecker > log , IHubContext < NotificationHub > hub )
26+ INotificationHelper notification , ILogger < PlexAvailabilityChecker > log , IHubContext < NotificationHub > hub , IFeatureService featureService )
2527 {
2628 _tvRepo = tvRequest ;
2729 _repo = repo ;
2830 _movieRepo = movies ;
2931 _notificationService = notification ;
3032 _log = log ;
3133 _notification = hub ;
34+ _featureService = featureService ;
3235 }
3336
3437 private readonly ITvRequestRepository _tvRepo ;
@@ -37,6 +40,7 @@ public PlexAvailabilityChecker(IPlexContentRepository repo, ITvRequestRepository
3740 private readonly INotificationHelper _notificationService ;
3841 private readonly ILogger _log ;
3942 private readonly IHubContext < NotificationHub > _notification ;
43+ private readonly IFeatureService _featureService ;
4044
4145 public async Task Execute ( IJobExecutionContext job )
4246 {
@@ -179,6 +183,7 @@ await _notificationService.Notify(new NotificationOptions
179183
180184 private async Task ProcessMovies ( )
181185 {
186+ var feature4kEnabled = await _featureService . FeatureEnabled ( FeatureNames . Movie4KRequests ) ;
182187 // Get all non available
183188 var movies = _movieRepo . GetAll ( ) . Include ( x => x . RequestedUser ) . Where ( x => ! x . Available || ( ! x . Available4K && x . Has4KRequest ) ) ;
184189 var itemsForAvailbility = new List < AvailabilityModel > ( ) ;
@@ -208,7 +213,7 @@ private async Task ProcessMovies()
208213
209214 var notify = false ;
210215
211- if ( has4kRequest && item . Has4K && ! movie . Available4K )
216+ if ( has4kRequest && item . Has4K && ! movie . Available4K && feature4kEnabled )
212217 {
213218 movie . Available4K = true ;
214219 movie . Approved4K = true ;
@@ -217,6 +222,14 @@ private async Task ProcessMovies()
217222 notify = true ;
218223 }
219224
225+ if ( ! feature4kEnabled && ! movie . Available )
226+ {
227+ movie . Available = true ;
228+ movie . MarkedAsAvailable = DateTime . Now ;
229+ await _movieRepo . SaveChangesAsync ( ) ;
230+ notify = true ;
231+ }
232+
220233 // If we have a non-4k versison then mark as available
221234 if ( item . Quality != null && ! movie . Available )
222235 {
0 commit comments