public async Task RunAsync(CancellationToken cancellationToken) { IMediaProcessorFlow flow = _flowFactory.CreateFlow("ScanFaces"); List <Store.Media> medias = await _storeContext.Medias.AsQueryable() .Where(x => x.FaceCount == 0 && x.MediaType == MediaType.Image && x.State == MediaState.Active) .OrderByDescending(x => x.DateTaken) .Take(100) .ToListAsync(cancellationToken); foreach (Media media in medias) { try { Console.WriteLine($"Scanning faces: {media.Id}"); var context = new MediaProcessorContext { Media = media, Image = await GetImageAsync(media) }; await flow.ExecuteAsync(context, cancellationToken); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } } }
public async Task DiscoverAsync( FileSystemDiscoveryOptions options, CancellationToken cancellationToken) { var todo = new List <MediaDiscoveryIdentifier>(); foreach (IMediaSourceDiscovery source in _discoveryFactory.GetSources()) { IEnumerable <MediaDiscoveryIdentifier> identifiers = await source .DiscoverMediaAsync(options, cancellationToken); todo.AddRange(identifiers); } IMediaProcessorFlow flow = _flowFactory.CreateFlow("ImportImage"); foreach (MediaDiscoveryIdentifier file in todo) { IMediaSourceDiscovery src = _discoveryFactory.GetSource(file.Source); byte[] data = await src.GetMediaDataAsync(file.Id, default); var context = new MediaProcessorContext { OriginalData = data, File = file }; try { Console.WriteLine($"Importing: {file.Id}"); await flow.ExecuteAsync(context, default); } catch (Exception ex) { Console.WriteLine(ex.Message); } //TODO: Move to Imported or delete } }
public async Task ScanExistingAsync( FileSystemDiscoveryOptions options, CancellationToken cancellationToken) { var todo = new List <MediaDiscoveryIdentifier>(); foreach (IMediaSourceDiscovery source in _discoveryFactory.GetSources()) { IEnumerable <MediaDiscoveryIdentifier> identifiers = await source .DiscoverMediaAsync(options, cancellationToken); todo.AddRange(identifiers); } IMediaProcessorFlow imageFlow = _flowFactory.CreateFlow("ImportImageNoFace"); IMediaProcessorFlow videoFlow = _flowFactory.CreateFlow("ImportVideo"); var processionOptions = new MediaProcessingOptions { SaveMedia = new SaveMediaFileOptions { SaveMode = SaveMediaMode.KeepInSource, SourceAction = SaveMediaSourceAction.Keep } }; foreach (MediaDiscoveryIdentifier file in todo) { IMediaSourceDiscovery src = _discoveryFactory.GetSource(file.Source); var extension = Path.GetExtension(file.Id); if (extension == ".mp4") { var context = new MediaProcessorContext { File = file, Options = processionOptions, MediaType = MediaType.Video }; try { Console.WriteLine($"Importing vide: {file.Id}"); await videoFlow.ExecuteAsync(context, default); } catch (Exception ex) { Console.WriteLine(ex.Message); } } else { byte[] data = await src.GetMediaDataAsync(file.Id, default); var context = new MediaProcessorContext { OriginalData = data, File = file, Options = processionOptions, MediaType = MediaType.Image }; try { Console.WriteLine($"Importing: {file.Id}"); await imageFlow.ExecuteAsync(context, default); } catch (Exception ex) { Console.WriteLine(ex.Message); } } } }