Ejemplo n.º 1
0
        public virtual void writeMetadata(BaseMetadata media, CancellableOperationProgressBase progress = null)
        {
            Progress = progress;       

            XMPLib.MetaData.ErrorCallbackDelegate errorCallbackDelegate = new XMPLib.MetaData.ErrorCallbackDelegate(errorCallback);
            // bug in xmplib, crashes on write when video is mpg and a progresscallback is active
            XMPLib.MetaData.ProgressCallbackDelegate progressCallbackDelegate = media.MimeType.Equals("video/mpeg") ? null : new XMPLib.MetaData.ProgressCallbackDelegate(progressCallback);

            XMPLib.MetaData xmpMetaDataWriter = new XMPLib.MetaData(errorCallbackDelegate, progressCallbackDelegate);

            try
            {
               if (media.SupportsXMPMetadata)
               {
                   xmpMetaDataWriter.open(media.Location, Consts.OpenOptions.XMPFiles_OpenForUpdate);

                   write(xmpMetaDataWriter, media);
               }
               else
               {
                  throw new Exception("Format does not support XMP metadata");
               }

            }
            finally
            {
                xmpMetaDataWriter.Dispose();
                xmpMetaDataWriter = null;
            }
        }
Ejemplo n.º 2
0
        public virtual void readMetadata(MediaProbe mediaProbe, Stream data, MetadataFactory.ReadOptions options, BaseMetadata media, CancellationToken token, int timeoutSeconds)
        {

            XMPLib.MetaData.ErrorCallbackDelegate errorCallbackDelegate = new XMPLib.MetaData.ErrorCallbackDelegate(errorCallback);

            //XMPLib.MetaData xmpMetaDataReader = new XMPLib.MetaData(errorCallbackDelegate, null);
            XMPLib.MetaData xmpMetaDataReader = new XMPLib.MetaData(null, null);

            try
            {
                
                FileInfo info = new FileInfo(media.Location);
                info.Refresh();
                media.LastModifiedDate = info.LastWriteTime < sqlMinDate ? sqlMinDate : info.LastWriteTime;
                media.FileDate = info.CreationTime < sqlMinDate ? sqlMinDate : info.CreationTime;
                media.MimeType = MediaFormatConvert.fileNameToMimeType(media.Name); 

                if (media.SupportsXMPMetadata == false) return;

                xmpMetaDataReader.open(media.Location, Consts.OpenOptions.XMPFiles_OpenForRead);
                                    
                readXMPMetadata(xmpMetaDataReader, media);
                
            }
            catch (Exception e)
            {
                Logger.Log.Error("Cannot read XMP metadata for: " + media.Location, e);
                media.MetadataReadError = e;

            } finally {
          
                xmpMetaDataReader.Dispose();
                xmpMetaDataReader = null;
            }
        }
        public override void readMetadata(MediaProbe mediaProbe, Stream data, MetadataFactory.ReadOptions options, BaseMetadata media,
            CancellationToken token, int timeoutSeconds)
        {
            AudioMetadata audio = media as AudioMetadata;
                                       
            audio.DurationSeconds = mediaProbe.DurationSeconds;
            audio.SizeBytes = mediaProbe.SizeBytes;

            audio.AudioContainer = mediaProbe.Container;                     
            audio.AudioCodec = mediaProbe.AudioCodecName;
            audio.SamplesPerSecond = mediaProbe.SamplesPerSecond;
            audio.BitsPerSample = (short)(mediaProbe.BytesPerSample * 8);
            audio.NrChannels = (short)mediaProbe.NrChannels;

            audio.BitRate = mediaProbe.AudioBitRate == 0 ? (long?)null : mediaProbe.AudioBitRate;             
       
            List<string> fsMetaData = mediaProbe.MetaData;
               
            try
            {                
                if (options.HasFlag(MetadataFactory.ReadOptions.GENERATE_THUMBNAIL))
                {
                    generateThumbnail(mediaProbe, audio, token, timeoutSeconds, 1);
                }                                        
            }
            catch (Exception e)
            {
                Logger.Log.Error("Cannot read audio thumbnail: " + audio.Location, e);
                media.MetadataReadError = e;
            }

            if(audio.AudioCodec.ToLower().Equals("mp3") || audio.AudioCodec.ToLower().StartsWith("pcm"))
            {
                audio.SupportsXMPMetadata = true;                
            }
            else
            {
                audio.SupportsXMPMetadata = false;
            }

            base.readMetadata(mediaProbe, data, options, media, token, timeoutSeconds);
 
            parseFFMpegMetaData(fsMetaData, audio);
                      
        }
        public override void readMetadata(MediaProbe mediaProbe, Stream data, MetadataFactory.ReadOptions options, BaseMetadata media,
            CancellationToken token, int timeoutSeconds)
        {
            ImageMetadata image = media as ImageMetadata;
            image.SizeBytes = data.Length;

            if (FileUtils.isUrl(image.Location))
            {
                image.SupportsXMPMetadata = false;
            }
            else
            {
                image.SupportsXMPMetadata = true;
                base.readMetadata(mediaProbe, data, options, media, token, timeoutSeconds);
            }

            image.ImageContainer = mediaProbe.Container;
            image.Width = mediaProbe.Width;
            image.Height = mediaProbe.Height;
            image.PixelFormat = mediaProbe.PixelFormat;
            image.BitsPerPixel = (short)mediaProbe.BitsPerPixel;
           
            List<String> fsMetaData = mediaProbe.MetaData;
               
            try
            {                   
                if (options.HasFlag(MetadataFactory.ReadOptions.GENERATE_THUMBNAIL))
                {
                    generateThumbnail(mediaProbe, image, token, timeoutSeconds, 1);
                }
                    
            }
            catch (Exception e)
            {
                Logger.Log.Error("Cannot create image thumbnail: " + image.Location, e);
                media.MetadataReadError = e;
            }
            
                        
        }
Ejemplo n.º 5
0
            public static MediaFileItem create(string location, BaseMetadata metadata = null)
            {                               
                rwLock.EnterWriteLock();
                try
                {  
                    WeakReference<MediaFileItem> reference = null;
                    MediaFileItem item = null;

                    bool success = dictionary.TryGetValue(location, out reference);

                    if (success == true)
                    {
                        bool exists = reference.TryGetTarget(out item);

                        if (exists == false) {
                      
                            // item has been garbage collected, recreate
                            item = new MediaFileItem(location);
                            if (metadata != null)
                            {
                                item.Metadata = metadata;                              
                                item.checkVariables(metadata);
                                item.ItemState = MediaItemState.LOADED;
                            }
                            
                            reference = new WeakReference<MediaFileItem>(item);
                            dictionary.Remove(location);
                            dictionary.Add(location, reference);
                            
                        }
                    }
                    else
                    {
                        // item did not exist yet
                        item = new MediaFileItem(location);
                        if (metadata != null)
                        {
                            item.Metadata = metadata;                           
                            item.checkVariables(metadata);
                            item.ItemState = MediaItemState.LOADED;
                        }

                        reference = new WeakReference<MediaFileItem>(item);
                        dictionary.Add(location, reference);
                  
                    }

                    return (item);
                }
                finally
                {
                    rwLock.ExitWriteLock();                   
                }
            }
Ejemplo n.º 6
0
        // function should only be called inside a write lock
        bool checkVariables(BaseMetadata metadata)
        {
            if (metadata == null) return(false);

            if (metadata.Tags.Count > 0)
            {
                HasTags = true;
            }
            else
            {
                HasTags = false;
            }

            if (metadata.Longitude != null && metadata.Latitude != null)
            {
                HasGeoTag = true;
            }
            else
            {
                HasGeoTag = false;
            }

            return (true);

        }
Ejemplo n.º 7
0
        private void getExifProperties(ObservableCollection<Tuple<string, string>> p, BaseMetadata media)
        {
            p.Add(new Tuple<string, string>("Size", MediaViewer.Model.Utils.MiscUtils.formatSizeBytes(media.SizeBytes)));

            if (media.FileDate != null)
            {
                p.Add(new Tuple<string, string>("File Date", media.FileDate.ToString()));
            }

            if (media.LastModifiedDate != null)
            {
                p.Add(new Tuple<string, string>("File Modified", media.LastModifiedDate.ToString()));
            }

            int nrProps = p.Count;
           
            if (media.Software != null)
            {
                p.Add(new Tuple<string,string>("Software", media.Software));
            }
            if(media.MetadataDate != null) {

                p.Add(new Tuple<string, string>("Metadata Date", media.MetadataDate.ToString()));
            }
            if (media.MetadataModifiedDate != null)
            {
                p.Add(new Tuple<string, string>("Metadata Modified", media.MetadataModifiedDate.ToString()));
            }
                      
            if (media is ImageMetadata)
            {
                foreach (Tuple<string, string> item in FormatMetaData.formatProperties(media as ImageMetadata))
                {
                    p.Add(item);
                }
            }
            else if (media is AudioMetadata)
            {
                AudioMetadata audio = media as AudioMetadata;

                if (audio.Genre != null)
                {
                    p.Add(new Tuple<string, string>("Genre", audio.Genre));
                }

                if (audio.Album != null)
                {
                    p.Add(new Tuple<string, string>("Album", audio.Album));
                }

                if (audio.TrackNr != null)
                {
                    String value = audio.TrackNr.ToString();

                    if (audio.TotalTracks != null)
                    {
                        value += " / " + audio.TotalTracks;
                    }

                    p.Add(new Tuple<string, string>("Track", value));
                }

                if (audio.DiscNr != null)
                {
                    String value = audio.DiscNr.ToString();

                    if (audio.TotalDiscs != null)
                    {
                        value += " / " + audio.TotalDiscs;
                    }

                    p.Add(new Tuple<string, string>("Disc", value));
                }
                                
            }

            
            if (media.Latitude != null)
            {
                p.Add(new Tuple<string, string>("GPS Latitude", media.Latitude.Value.ToString("0.00000")));
            }

            if (media.Longitude != null)
            {
                p.Add(new Tuple<string, string>("GPS Longitude", media.Longitude.Value.ToString("0.00000")));
            }
            
            if (p.Count > nrProps)
            {
                p.Insert(nrProps, new Tuple<string, string>("", "EXIF"));
            }
            
        }
        protected override void readXMPMetadata(XMPLib.MetaData xmpMetaDataReader, BaseMetadata media)
        {

            base.readXMPMetadata(xmpMetaDataReader, media);

            ImageMetadata image = media as ImageMetadata;

            Nullable<int> intVal = new Nullable<int>();
            String temp = "";
            bool exists = false;

            exists = xmpMetaDataReader.getStructField(Consts.XMP_NS_EXIF, "Flash", Consts.XMP_NS_EXIF, "exif:Fired", ref temp);
            if (exists)
            {
                try
                {
                    image.FlashFired = Boolean.Parse(temp);
                }
                catch (Exception)
                {
                    image.FlashFired = null;
                }
            }
            else
            {
                image.FlashFired = null;
            }

            xmpMetaDataReader.getProperty_Int(Consts.XMP_NS_EXIF, "LightSource", ref intVal);
            if (intVal == null)
            {
                image.LightSource = null;
            }
            else
            {
                image.LightSource = (short)intVal;
            }

            xmpMetaDataReader.getProperty_Int(Consts.XMP_NS_EXIF, "MeteringMode", ref intVal);
            if (intVal == null)
            {
                image.MeteringMode = null;
            }
            else
            {
                image.MeteringMode = (short)intVal;
            }

            xmpMetaDataReader.getProperty_Int(Consts.XMP_NS_EXIF, "Saturation", ref intVal);
            if (intVal == null)
            {
                image.Saturation = null;
            }
            else
            {
                image.Saturation = (short)intVal;
            }


            xmpMetaDataReader.getProperty_Int(Consts.XMP_NS_EXIF, "SceneCaptureType", ref intVal);
            if (intVal == null)
            {
                image.SceneCaptureType = null;
            }
            else
            {
                image.SceneCaptureType = (short)intVal;
            }

            xmpMetaDataReader.getProperty_Int(Consts.XMP_NS_EXIF, "SensingMethod", ref intVal);
            if (intVal == null)
            {
                image.SensingMethod = null;
            }
            else
            {
                image.SensingMethod = (short)intVal;
            }

            xmpMetaDataReader.getProperty_Int(Consts.XMP_NS_EXIF, "Sharpness", ref intVal);
            if (intVal == null)
            {
                image.Sharpness = null;
            }
            else
            {
                image.Sharpness = (short)intVal;
            }

            xmpMetaDataReader.getProperty_Int(Consts.XMP_NS_TIFF, "Orientation", ref intVal);
            if (intVal == null)
            {
                image.Orientation = null;
            }
            else
            {
                image.Orientation = (short)intVal;
            }

            string subjectDistance = "";

            xmpMetaDataReader.getProperty(Consts.XMP_NS_EXIF, "SubjectDistance", ref subjectDistance);
            image.SubjectDistance = parseRational(subjectDistance);

            string shutterSpeedValue = "";

            xmpMetaDataReader.getProperty(Consts.XMP_NS_EXIF, "ShutterSpeedValue", ref shutterSpeedValue);
            image.ShutterSpeedValue = parseRational(shutterSpeedValue);

            xmpMetaDataReader.getProperty_Int(Consts.XMP_NS_EXIF, "SubjectDistanceRange", ref intVal);
            if (intVal == null)
            {
                image.SubjectDistanceRange = null;
            }
            else
            {
                image.SubjectDistanceRange = (short)intVal;
            }

            string isoSpeedRating = "";

            int nrSpeedRatings = xmpMetaDataReader.countArrayItems(Consts.XMP_NS_EXIF, "ISOSpeedRatings");
            if (nrSpeedRatings > 0)
            {
                xmpMetaDataReader.getArrayItem(Consts.XMP_NS_EXIF, "ISOSpeedRatings", 1, ref isoSpeedRating);
                int value = 0;
                if (int.TryParse(isoSpeedRating, out value))
                {
                    image.ISOSpeedRating = value;
                }
            }
            else
            {
                image.ISOSpeedRating = null;
            }

            xmpMetaDataReader.getProperty_Int(Consts.XMP_NS_EXIF, "WhiteBalance", ref intVal);
            if (intVal == null)
            {
                image.WhiteBalance = null;
            }
            else
            {
                image.WhiteBalance = (short)intVal;
            }

            String cameraMake = "";

            xmpMetaDataReader.getProperty(Consts.XMP_NS_TIFF, "Make", ref cameraMake);
            image.CameraMake = cameraMake;

            String cameraModel = "";

            xmpMetaDataReader.getProperty(Consts.XMP_NS_TIFF, "Model", ref cameraModel);
            image.CameraModel = cameraModel;

            String lens = "";

            xmpMetaDataReader.getProperty(Consts.XMP_NS_EXIF_Aux, "Lens", ref lens);
            image.Lens = lens;

            String serialNumber = "";

            xmpMetaDataReader.getProperty(Consts.XMP_NS_EXIF_Aux, "SerialNumber", ref serialNumber);
            image.SerialNumber = serialNumber;

            string exposureTime = "";

            xmpMetaDataReader.getProperty(Consts.XMP_NS_EXIF, "ExposureTime", ref exposureTime);
            image.ExposureTime = parseRational(exposureTime);

            string fnumber = "";

            xmpMetaDataReader.getProperty(Consts.XMP_NS_EXIF, "FNumber", ref fnumber);
            image.FNumber = parseRational(fnumber);

            string exposureBiasValue = "";

            xmpMetaDataReader.getProperty(Consts.XMP_NS_EXIF, "ExposureBiasValue", ref exposureBiasValue);
            image.ExposureBiasValue = parseRational(exposureBiasValue);

            xmpMetaDataReader.getProperty_Int(Consts.XMP_NS_EXIF, "ExposureProgram", ref intVal);
            if (intVal == null)
            {
                image.ExposureProgram = null;
            }
            else
            {
                image.ExposureProgram = (short)intVal;
            }

            string focalLength = "";

            xmpMetaDataReader.getProperty(Consts.XMP_NS_EXIF, "FocalLength", ref focalLength);
            image.FocalLength = parseRational(focalLength);

            xmpMetaDataReader.getProperty_Int(Consts.XMP_NS_EXIF, "Contrast", ref intVal);
            if (intVal == null)
            {
                image.Contrast = null;
            }
            else
            {
                image.Contrast = (short)intVal;
            }
        }
Ejemplo n.º 9
0
        protected virtual void write(XMPLib.MetaData xmpMetaDataWriter, BaseMetadata media) {
        
            if (media.Title != null)
            {
                xmpMetaDataWriter.setLocalizedText(Consts.XMP_NS_DC, "title", "en", "en-US", media.Title);
            }

            if (media.Rating != null)
            {
                xmpMetaDataWriter.setProperty_Float(Consts.XMP_NS_XMP, "Rating", media.Rating.Value);
                //xmpMetaDataWriter.setProperty(Consts.XMP_NS_XMP, "Rating", media.Rating.ToString(), Consts.PropOptions.XMP_DeleteExisting);
            }

            if (media.Description != null)
            {
                xmpMetaDataWriter.setLocalizedText(Consts.XMP_NS_DC, "description", "en", "en-US", media.Description);
            }

            if (media.Software != null)
            {

                xmpMetaDataWriter.setProperty(Consts.XMP_NS_XMP, "CreatorTool", media.Software,
                    Consts.PropOptions.XMP_DeleteExisting);
            }

            if (media.Author != null)
            {

                if (xmpMetaDataWriter.doesArrayItemExist(Consts.XMP_NS_DC, "creator", 1))
                {
                    xmpMetaDataWriter.setArrayItem(Consts.XMP_NS_DC, "creator", 1, media.Author, 0);
                }
                else
                {
                    xmpMetaDataWriter.appendArrayItem(Consts.XMP_NS_DC, "creator",
                        Consts.PropOptions.XMP_PropArrayIsOrdered, media.Author, 0);
                }

            }

            /*if (media.Thumbnail != null)
            {
                string imageData = MediaViewer.Infrastructure.Utils.ImageUtils.imageToJpegBase64String(media.Thumbnail.Image);

                xmpMetaDataWriter.setStructField(Consts.XMP_NS_XMP, "xmpGImg", Consts.XMP_NS_XMP_Image, "format", "JPEG", (uint)Consts.PropOptions.XMP_NoOptions);
                xmpMetaDataWriter.setStructField(Consts.XMP_NS_XMP, "xmpGImg", Consts.XMP_NS_XMP_Image, "width", media.Thumbnail.Image.Width.ToString(), (uint)Consts.PropOptions.XMP_NoOptions);
                xmpMetaDataWriter.setStructField(Consts.XMP_NS_XMP, "xmpGImg", Consts.XMP_NS_XMP_Image, "height", media.Thumbnail.Image.Height.ToString(), (uint)Consts.PropOptions.XMP_NoOptions);
                xmpMetaDataWriter.setStructField(Consts.XMP_NS_XMP, "xmpGImg", Consts.XMP_NS_XMP_Image, "image", imageData, (uint)Consts.PropOptions.XMP_NoOptions);
            }*/

            if (media.Copyright != null)
            {
                xmpMetaDataWriter.setLocalizedText(Consts.XMP_NS_DC, "rights", "en", "en-US", media.Copyright);          
            }

            if (media.CreationDate != null)
            {
                xmpMetaDataWriter.setProperty_Date(Consts.XMP_NS_XMP, "CreateDate", media.CreationDate.Value);
            }

            if (media.MetadataDate == null)
            {

                xmpMetaDataWriter.setProperty_Date(Consts.XMP_NS_XMP, "MetadataDate", DateTime.Now);
            }
            else
            {
                xmpMetaDataWriter.setProperty_Date(Consts.XMP_NS_XMP, "ModifyDate", DateTime.Now);
            }

           
            int nrTags = xmpMetaDataWriter.countArrayItems(Consts.XMP_NS_DC, "subject");

            for (int i = nrTags; i > 0; i--)
            {
                xmpMetaDataWriter.deleteArrayItem(Consts.XMP_NS_DC, "subject", i);
            }

            foreach (Tag tag in media.Tags)
            {
                xmpMetaDataWriter.appendArrayItem(Consts.XMP_NS_DC, "subject",
                    Consts.PropOptions.XMP_PropArrayIsUnordered, tag.Name, 0);
            }

            GeoTagCoordinatePair geoTag = new GeoTagCoordinatePair(media.Latitude, media.Longitude);

            if (!geoTag.IsEmpty)
            {
                xmpMetaDataWriter.setProperty(Consts.XMP_NS_EXIF, "GPSLatitude", geoTag.LatCoord, 0);
                xmpMetaDataWriter.setProperty(Consts.XMP_NS_EXIF, "GPSLongitude", geoTag.LonCoord, 0);
            }
            else
            {
                xmpMetaDataWriter.deleteProperty(Consts.XMP_NS_EXIF, "GPSLatitude");
                xmpMetaDataWriter.deleteProperty(Consts.XMP_NS_EXIF, "GPSLongitude");
            }
           
            if (xmpMetaDataWriter.canPutXMP())
            {
                xmpMetaDataWriter.putXMP();
            }
            else
            {              
                throw new Exception("Format does not support XMP metadata");
            }

          
        }
Ejemplo n.º 10
0
        public override void readMetadata(MediaProbe mediaProbe, Stream data, MetadataFactory.ReadOptions options, BaseMetadata media,
            CancellationToken token, int timeoutSeconds)
        {
            VideoMetadata video = media as VideoMetadata;

            video.DurationSeconds = mediaProbe.DurationSeconds;
            video.SizeBytes = mediaProbe.SizeBytes;

            video.Width = mediaProbe.Width;
            video.Height = mediaProbe.Height;

            video.VideoContainer = mediaProbe.Container;
            video.VideoCodec = mediaProbe.VideoCodecName;

            video.PixelFormat = mediaProbe.PixelFormat;
            video.BitsPerPixel = (short)mediaProbe.BitsPerPixel;

            video.FramesPerSecond = mediaProbe.FrameRate;

            video.VideoBitRate = mediaProbe.VideoBitRate == 0 ? (long?)null : mediaProbe.VideoBitRate;
            video.AudioBitRate = mediaProbe.AudioBitRate == 0 ? (long?)null : mediaProbe.AudioBitRate;
           
            if (!String.IsNullOrEmpty(mediaProbe.AudioCodecName))
            {
                video.AudioCodec = mediaProbe.AudioCodecName;
                video.SamplesPerSecond = mediaProbe.SamplesPerSecond;
                video.BitsPerSample = (short)(mediaProbe.BytesPerSample * 8);
                video.NrChannels = (short)mediaProbe.NrChannels;
            }
            else
            {
                video.AudioCodec = null;
                video.SamplesPerSecond = null;
                video.BitsPerSample = null;
                video.NrChannels = null;
            }

            List<String> fsMetaData = mediaProbe.MetaData;

            try
            {
                if (options.HasFlag(MetadataFactory.ReadOptions.GENERATE_THUMBNAIL))
                {
                    generateThumbnail(mediaProbe, video, token, timeoutSeconds, 1);
                }
               
            }
            catch (Exception e)
            {
                Logger.Log.Error("Cannot create video thumbnail: " + video.Location, e);
                media.MetadataReadError = e;
            }

            if (fsMetaData != null)
            {
                video.SupportsXMPMetadata = supportsXMPMetadata(video, fsMetaData);
            }
            else
            {
                video.SupportsXMPMetadata = false;
            }

            base.readMetadata(mediaProbe, data, options, media, token, timeoutSeconds);

            parseFFMpegMetaData(fsMetaData, video);


        }
Ejemplo n.º 11
0
        public static void write(BaseMetadata metadata, CancellableOperationProgressBase progress = null)
        {
            if (metadata is ImageMetadata)
            {
                ImageFileMetadataWriter imageMetadataWriter = new ImageFileMetadataWriter();
                imageMetadataWriter.writeMetadata(metadata, progress);

            }
            else if (metadata is VideoMetadata)
            {
                VideoFileMetadataWriter videoMetadataWriter = new VideoFileMetadataWriter();
                videoMetadataWriter.writeMetadata(metadata, progress);

            }
            else if (metadata is AudioMetadata)
            {
                AudioFileMetadataWriter audioMetadataWriter = new AudioFileMetadataWriter();
                audioMetadataWriter.writeMetadata(metadata, progress);
            }
            else 
            {
                MetadataFileWriter metadataFileWriter = new MetadataFileWriter();
                metadataFileWriter.writeMetadata(metadata, progress);
            } 

        }
Ejemplo n.º 12
0
        protected virtual void readXMPMetadata(XMPLib.MetaData xmpMetaDataReader, BaseMetadata media)
        {
                     
            string title = "";

            xmpMetaDataReader.getLocalizedText(Consts.XMP_NS_DC, "title", "en", "en-US", ref title);

            media.Title = title;

            string description = "";

            xmpMetaDataReader.getLocalizedText(Consts.XMP_NS_DC, "description", "en", "en-US", ref description);
           
            media.Description = description;

            string author = "";

            xmpMetaDataReader.getArrayItem(Consts.XMP_NS_DC, "creator", 1, ref author);

            media.Author = author;

            string copyright = "";

            xmpMetaDataReader.getLocalizedText(Consts.XMP_NS_DC, "rights", "en", "en-US", ref copyright);
                     
            media.Copyright = copyright;

            string software = "";

            xmpMetaDataReader.getProperty(Consts.XMP_NS_XMP, "CreatorTool", ref software);
                       
            media.Software = software;
         
            Nullable<double> rating = new Nullable<double>();

            xmpMetaDataReader.getProperty_Float(Consts.XMP_NS_XMP, "Rating", ref rating);

            media.Rating = rating;

            Nullable<DateTime> date = new Nullable<DateTime>();

            xmpMetaDataReader.getProperty_Date(Consts.XMP_NS_XMP, "MetadataDate", ref date);
            if (date != null && date < sqlMinDate)
            {               
                media.MetadataDate = null;               
            }
            else
            {
                media.MetadataDate = date;
            }

            xmpMetaDataReader.getProperty_Date(Consts.XMP_NS_XMP, "CreateDate", ref date);
            if (date != null && date < sqlMinDate)
            {
                media.CreationDate = null;
            }
            else
            {
                media.CreationDate = date;
            }
          
            xmpMetaDataReader.getProperty_Date(Consts.XMP_NS_XMP, "ModifyDate", ref date);
            if (date != null && date < sqlMinDate)
            {
                media.MetadataModifiedDate = null;
            }
            else
            {
                media.MetadataModifiedDate = date;
            }

            string longitude = null;
            string latitude = null;

            xmpMetaDataReader.getProperty(Consts.XMP_NS_EXIF, "GPSLatitude", ref latitude);
            xmpMetaDataReader.getProperty(Consts.XMP_NS_EXIF, "GPSLongitude", ref longitude);
           
            GeoTagCoordinatePair geoPair = new GeoTagCoordinatePair(latitude, longitude);
            media.Latitude = geoPair.LatDecimal;
            media.Longitude = geoPair.LonDecimal;
            
            media.Tags.Clear();
            
            int nrTags = xmpMetaDataReader.countArrayItems(Consts.XMP_NS_DC, "subject");

            for (int i = 1; i <= nrTags; i++)
            {

                string tagName = "";
                xmpMetaDataReader.getArrayItem(Consts.XMP_NS_DC, "subject", i, ref tagName);

                if (tagName != null)
                {

                    Tag newTag = new Tag();
                    newTag.Name = tagName.Trim();

                    media.Tags.Add(newTag);

                }
            }

            /*string imageData = "";

            bool exists = xmpMetaDataReader.getStructField(Consts.XMP_NS_XMP, "xmpGImg", Consts.XMP_NS_XMP_Image, "image", ref imageData);
            if (exists)
            {
                BitmapSource thumbnail = MediaViewer.Infrastructure.Utils.ImageUtils.jpegBase64StringToImage(imageData);
              
            }*/
            

        }
Ejemplo n.º 13
0
        private string parseReplaceFilename(string replaceFilename, BaseMetadata media)
        {
            Regex counterRegEx = new Regex("#counter([0-9]+)");

            replaceFilename = counterRegEx.Replace(replaceFilename, m =>
            {
                if (!counter.HasValue)
                {
                    int initialCount = int.Parse(m.Groups[1].Value);
                    counter = initialCount;
                }
                else
                {
                    counter++;
                }

                return (counter.ToString());
            });

            Regex parentDirRegEx = new Regex(parentDirMarker);

            replaceFilename = parentDirRegEx.Replace(replaceFilename, m =>
            {
                String directoryName = Path.GetDirectoryName(media.Location);
                string parentDir = "";

                int index = directoryName.LastIndexOf('\\');
                if (index != -1 && index < directoryName.Length)
                {
                    parentDir = directoryName.Substring(index + 1);
                }

                return (parentDir);
            });

            Regex widthRegEx = new Regex(widthMarker);

            replaceFilename = widthRegEx.Replace(replaceFilename, m =>
            {
                String width = media is VideoMetadata ? (media as VideoMetadata).Width.ToString() : "";
                width = media is ImageMetadata ? (media as ImageMetadata).Width.ToString() : "";

                return width;
            });

            Regex heightRegEx = new Regex(heightMarker);

            replaceFilename = heightRegEx.Replace(replaceFilename, m =>
            {
                String height = media is VideoMetadata ? (media as VideoMetadata).Height.ToString() : "";
                height = media is ImageMetadata ? (media as ImageMetadata).Height.ToString() : "";

                return height;
            });

            Regex bitrateRegEx = new Regex(bitrateMarker);

            replaceFilename = bitrateRegEx.Replace(replaceFilename, m =>
            {
                String bitrateKB = "";

                if (media is VideoMetadata)                
                {
                    VideoMetadata video = media as VideoMetadata;

                    long totalBitrate = 0;

                    if (video.VideoBitRate.HasValue)
                    {
                        totalBitrate += video.VideoBitRate.Value;
                    }

                    if (video.AudioBitRate.HasValue)
                    {
                        totalBitrate += video.AudioBitRate.Value;
                    }

                    if (totalBitrate > 0)
                    {
                        bitrateKB = (totalBitrate / (8 * 1024)).ToString();
                    }
                }
                else if (media is AudioMetadata)
                {
                    AudioMetadata audio = media as AudioMetadata;
                  
                    if (audio.BitRate.HasValue)
                    {
                        bitrateKB = (audio.BitRate.Value / (8 * 1024)).ToString();
                    }
                }

                return bitrateKB;
            });

            Regex dateRegex = new Regex(dateMarker);

            replaceFilename = bitrateRegEx.Replace(replaceFilename, m =>
            {
                String creationDate = "";

                if (media.CreationDate.HasValue)
                {

                    creationDate = media.CreationDate.Value.ToString("dd/M/yyyy");
                }

                return creationDate;
            });

            return replaceFilename;
           
        }
Ejemplo n.º 14
0
        string parseNewFilename(string newFilename, string replaceFilename, bool isRegexEnabled, string oldFilename, 
            BaseMetadata media)
        {
            string outputFilename = null;

            if (isRegexEnabled == false)
            {
                if (String.IsNullOrEmpty(newFilename) || String.IsNullOrWhiteSpace(newFilename))
                {
                    outputFilename = oldFilename;
                }
                else
                {
                    outputFilename = newFilename;
                }

            }
            else
            {
                Regex regex = new Regex(newFilename, RegexOptions.Singleline);
               
                replaceFilename = parseReplaceFilename(replaceFilename, media);

                if (replaceFilename.Equals("#upper"))
                {
                    outputFilename = regex.Replace(oldFilename, m => m.Value.ToUpperInvariant());
                }
                else if (replaceFilename.Equals("#lower"))
                {
                    outputFilename = regex.Replace(oldFilename, m => m.Value.ToLowerInvariant());
                }
                else
                {
                    outputFilename = regex.Replace(oldFilename, replaceFilename);
                }
            }

            outputFilename = FileUtils.removeIllegalCharsFromFileName(outputFilename, "-");

            return (outputFilename);
        }
Ejemplo n.º 15
0
        public static void write(BaseMetadata metadata, WriteOptions options, CancellableOperationProgressBase progress = null)
        {
           
            if (options.HasFlag(WriteOptions.AUTO) || options.HasFlag(WriteOptions.WRITE_TO_DISK))
            {
                MetadataFileFactory.write(metadata, progress);                
            }

            if (metadata.IsImported && (options.HasFlag(WriteOptions.AUTO) || options.HasFlag(WriteOptions.WRITE_TO_DATABASE)))
            {
                using (MetadataDbCommands metadataCommands = new MetadataDbCommands())
                {
                    metadata = metadataCommands.update(metadata);
                }
            }

            metadata.IsModified = false;
            
        }