示例#1
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 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;
            }
        }
        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;
            }
        }
        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;
            }
        }