Exemplo n.º 1
0
        private string GetFolder(MediaProcessorContext context)
        {
            switch (context.Options.SaveMedia.SaveMode)
            {
            case SaveMediaMode.CreateNew:
                if (context.Metadata.DateTaken.HasValue)
                {
                    return(string.Join("/",
                                       "New",
                                       context.Metadata.DateTaken.Value.Year.ToString(),
                                       context.Metadata.DateTaken.Value.ToString("MMMM", new CultureInfo("en-US"))));
                }
                else
                {
                    return("New/Unknown_Date");
                }

            case SaveMediaMode.KeepInSource:
                var directoryName = Path.GetDirectoryName(context.File.Id);
                var relativePath  = directoryName.Replace(context.File.BasePath, "");

                if (string.IsNullOrWhiteSpace(relativePath))
                {
                    relativePath = "/";
                }

                return(relativePath.Replace("\\", "/"));

            default:
                throw new ApplicationException($"Invalid SaveMediaMode: {context.Options.SaveMedia.SaveMode}");
            }
        }
Exemplo n.º 2
0
        public async Task ExecuteAsync(
            MediaProcessorContext context,
            CancellationToken cancellationToken)
        {
            IEnumerable <MediaFace> faces = new List <MediaFace>();

            if (context.FaceData is { })
Exemplo n.º 3
0
        public async Task ExecuteAsync(
            MediaProcessorContext context,
            CancellationToken cancellationToken)
        {
            var media = new Media
            {
                Id            = Guid.NewGuid(),
                MediaType     = context.MediaType,
                DateTaken     = context.Metadata.DateTaken,
                ImageUniqueId = context.Metadata.ImageId,
                GeoLocation   = context.Metadata.GeoLocation,
                Size          = GetSize(context),
                Folder        = GetFolder(context),
                Filename      = Path.GetFileName(context.File.Id),
                Dimension     = context.Metadata.Dimension,
                VideoInfo     = context.VideoInfo,
                OriginalHash  = ComputeHash(context),
                CameraId      = await GetCameraIdAsync(context, cancellationToken),
                Source        = new MediaSource
                {
                    Identifier = context.File.Id,
                    Type       = context.File.Source.ToString(),
                    ImportedAt = DateTime.UtcNow
                }
            };

            if (context.Thumbnails is { })
Exemplo n.º 4
0
        public async Task ExecuteAsync(
            MediaProcessorContext context,
            CancellationToken cancellationToken)
        {
            if (context.FaceData != null)
            {
                double distance = 0.4;

                foreach (FaceData face in context.FaceData)
                {
                    try
                    {
                        Guid?personId = await _faceDetectionService.PredictPersonAsync(
                            new PredictPersonRequest
                        {
                            Distance = distance,
                            Encoding = face.Encoding
                        }, cancellationToken);

                        if (personId.HasValue)
                        {
                            face.PersonId          = personId;
                            face.DistanceThreshold = distance;
                            face.RecognitionType   = FaceRecognitionType.Computer;
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }
        }
Exemplo n.º 5
0
 public async Task ExecuteAsync(
     MediaProcessorContext context,
     CancellationToken cancellationToken)
 {
     context.Thumbnails = await _thumbnailService.GenerateAllThumbnailAsync(
         context.Image,
         cancellationToken);
 }
Exemplo n.º 6
0
        public async Task ExecuteAsync(
            MediaProcessorContext context,
            CancellationToken cancellationToken)
        {
            var   stream = new MemoryStream(context.OriginalData !);
            Image image  = await Image.LoadAsync(stream);

            context.Image = _imageTransformService.AutoOrient(image);
        }
Exemplo n.º 7
0
 public async Task ExecuteAsync(
     MediaProcessorContext context,
     CancellationToken cancellationToken)
 {
     if (!context.Metadata.DateTaken.HasValue)
     {
         context.Metadata.DateTaken = _dateTakenParser.Parse(
             Path.GetFileNameWithoutExtension(context.File.Id));
     }
 }
Exemplo n.º 8
0
        public async Task ExecuteAsync(MediaProcessorContext context, CancellationToken cancellationToken)
        {
            ExtractVideoDataResult?videoData = await _videoProcessingService.ExtractVideoDataAsync(
                context.File.Id,
                cancellationToken);

            context.Image     = Image.Load(videoData.ImageData);
            context.Metadata  = videoData.Meta;
            context.VideoInfo = videoData.Info;
            context.Size      = videoData.Size;
        }
Exemplo n.º 9
0
 public async virtual Task ExecuteAsync(
     MediaProcessorContext context,
     CancellationToken cancellationToken)
 {
     foreach (string taskName in Tasks)
     {
         IMediaProcessorTask instance = _taskFactory.GetTask(taskName);
         Log.Information("Execute Task {Name}", taskName);
         await instance.ExecuteAsync(context, cancellationToken);
     }
 }
Exemplo n.º 10
0
        public async Task ExecuteAsync(
            MediaProcessorContext context,
            CancellationToken cancellationToken)
        {
            MemoryStream stream = new MemoryStream();
            await context.Image.SaveAsJpegAsync(stream, cancellationToken);

            stream.Position = 0;

            context.WebImage = _webPImageConverter.ConvertToWebP(stream).ToByteArray();
        }
Exemplo n.º 11
0
        public async Task ExecuteAsync(
            MediaProcessorContext context,
            CancellationToken cancellationToken)
        {
            MemoryStream stream = new MemoryStream();
            await context.Image.SaveAsJpegAsync(stream, cancellationToken);

            stream.Position = 0;

            IEnumerable <FaceDetectionResponse> detectedFaces = await _faceDetectionService
                                                                .DetectFacesAsync(stream, cancellationToken);

            IEnumerable <FaceData> faceData = detectedFaces.Select(f =>
                                                                   new FaceData
            {
                Box      = f.Box,
                Encoding = f.Encoding,
                Id       = Guid.NewGuid()
            }).ToList();

            IEnumerable <BoxExtractionInput> inputs = faceData.Select(f =>
                                                                      new BoxExtractionInput
            {
                Box = f.Box,
                Id  = f.Id
            });

            stream.Position = 0;

            IEnumerable <BoxExtractionResult> faceImages = await _boxExtractorService
                                                           .ExtractBoxesAsync(stream, inputs, ThumbnailSizeName.M, default);

            ILookup <Guid, BoxExtractionResult> faceLookup = faceImages.ToLookup(x => x.Id);

            foreach (FaceData face in faceData)
            {
                ThumbnailResult thumb = faceLookup[face.Id].Single().Thumbnail;

                face.Thumbnail = new MediaThumbnail
                {
                    Id         = Guid.NewGuid(),
                    Data       = thumb.Data,
                    Dimensions = thumb.Dimensions,
                    Format     = thumb.Format,
                    Size       = thumb.Size
                };
            }

            context.FaceData = faceData;
        }
Exemplo n.º 12
0
        public async Task ScanByMediaIdAsync(Guid mediaId, CancellationToken cancellationToken)
        {
            Media media = await _mediaService.GetByIdAsync(mediaId, cancellationToken);

            Stream stream = _mediaService.GetMediaStream(media);

            var context = new MediaProcessorContext
            {
                Media = media,
                Image = await Image.LoadAsync(stream)
            };

            await _flow.ExecuteAsync(context, cancellationToken);
        }
Exemplo n.º 13
0
        public Task ExecuteAsync(MediaProcessorContext context, CancellationToken cancellationToken)
        {
            if (context.Options.SaveMedia.SourceAction == SaveMediaSourceAction.Delete)
            {
                File.Delete(context.File.Id);
            }
            else if (context.Options.SaveMedia.SourceAction == SaveMediaSourceAction.Move)
            {
                //TODO: Move
            }
            else if (context.Options.SaveMedia.SourceAction == SaveMediaSourceAction.Replace)
            {
                //TODO: Overwrite source
            }

            return(Task.CompletedTask);
        }
Exemplo n.º 14
0
        public async Task ExecuteAsync(
            MediaProcessorContext context,
            CancellationToken cancellationToken)
        {
            var filename          = _mediaService.GetFilename(context.Media, MediaFileType.Original);
            var convertedFilename = _mediaService.GetFilename(context.Media, MediaFileType.Video720);

            if (File.Exists(convertedFilename))
            {
                File.Delete(convertedFilename);
            }

            await _videoProcessingService.ConvertTo720Async(
                filename,
                convertedFilename,
                cancellationToken);
        }
Exemplo n.º 15
0
        public async Task ExecuteAsync(
            MediaProcessorContext context,
            CancellationToken cancellationToken)
        {
            var filename    = _mediaService.GetFilename(context.Media, MediaFileType.Original);
            var gifFilename = _mediaService.GetFilename(context.Media, MediaFileType.VideoGif);

            if (File.Exists(gifFilename))
            {
                File.Delete(gifFilename);
            }

            await _videoProcessingService.GeneratePreviewGifAsync(
                filename,
                gifFilename,
                cancellationToken);
        }
Exemplo n.º 16
0
        public async virtual Task ExecuteAsync(
            MediaProcessorContext context,
            CancellationToken cancellationToken)
        {
            foreach (string taskName in Tasks)
            {
                IMediaProcessorTask instance = _taskFactory.GetTask(taskName);
                Log.Information("Execute Task {Name}", taskName);

                try
                {
                    await instance.ExecuteAsync(context, cancellationToken);
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "Error executing Task {Name}", taskName);
                    throw;
                }
            }
        }
Exemplo n.º 17
0
 public async Task ExecuteAsync(
     MediaProcessorContext context,
     CancellationToken cancellationToken)
 {
     context.Metadata = await _metadataExtractor.GetMetadataAsync(context.Image, default);
 }