Exemplo n.º 1
0
        public static bool SaveXmpSidecar(this TagLib.Image.File file, TagLib.File.IFileAbstraction resource)
        {
            var xmp_tag = file.GetTag(TagLib.TagTypes.XMP, false) as XmpTag;

            if (xmp_tag == null)
            {
                // TODO: Delete File
                return(true);
            }

            var xmp = xmp_tag.Render();

            try {
                using (var stream = resource.WriteStream) {
                    stream.SetLength(0);
                    using (var writer = new StreamWriter(stream)) {
                        writer.Write(xmp);
                    }
                    resource.CloseStream(stream);
                }
            } catch (Exception e) {
                Log.DebugFormat($"Sidecar cannot be saved: {resource.Name}");
                Log.DebugException(e);
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        ///    Parses the XMP file identified by resource and replaces the XMP
        ///    tag of file by the parsed data.
        /// </summary>
        public static bool ParseXmpSidecar(this TagLib.Image.File file, TagLib.File.IFileAbstraction resource)
        {
            string xmp;

            try {
                using (var stream = resource.ReadStream) {
                    using (var reader = new StreamReader(stream)) {
                        xmp = reader.ReadToEnd();
                    }
                }
            } catch (Exception e) {
                Log.DebugFormat($"Sidecar cannot be read for file {file.Name}");
                Log.DebugException(e);
                return(false);
            }

            XmpTag tag = null;

            try {
                tag = new XmpTag(xmp, file);
            } catch (Exception e) {
                Log.DebugFormat($"Metadata of Sidecar cannot be parsed for file {file.Name}");
                Log.DebugException(e);
                return(false);
            }

            var xmp_tag = file.GetTag(TagLib.TagTypes.XMP, true) as XmpTag;

            xmp_tag.ReplaceFrom(tag);
            return(true);
        }
Exemplo n.º 3
0
        public static void ReadTags(TagLib.File.IFileAbstraction fileAbstraction)
        {
            using (var tagFile = TagLib.File.Create(fileAbstraction, TagLib.ReadStyle.Average))
            {
                //read the raw tags
                var tags = tagFile.GetTag(TagLib.TagTypes.Id3v2, true);

                // do stuff with the tags
            }
        }
Exemplo n.º 4
0
 private static TagLib.File UserDefinedResolver(TagLib.File.IFileAbstraction abstraction, string mimetype, TagLib.ReadStyle style)
 {
     foreach (KeyValuePair <string, CUEToolsFormat> fmt in _config.formats)
     {
         if (fmt.Value.tagger != CUEToolsTagger.TagLibSharp && mimetype == "taglib/" + fmt.Key)
         {
             return(new File(abstraction, style, fmt.Value.tagger));
         }
     }
     return(null);
 }
        public override void Rebuild(bool deepLoad)
        {
            _tag = null;

            if (IsServerURI == false)
            {
                try
                {
                    TagLib.File.IFileAbstraction abs = null;

                    if (IsURI)
                    {
                        abs = new UriFileAbstraction(base.Path);
                    }
                    else
                    {
                        abs = new TagLib.File.LocalFileAbstraction(base.Path);
                    }

                    af = new TagLib.Mpeg.AudioFile(abs, ReadStyle.Average);

                    if (deepLoad)
                    {
                        // This will actually toggle reading the audio header
                        TimeSpan duration = af.Properties.Duration;
                        _deepLoad = true;
                    }

                    _tag  = af.Tag;
                    _prop = af.Properties;
                }
                catch (Exception ex)
                {
                    string s = null;
                }

                _tagModified = false;
            }
        }
Exemplo n.º 6
0
 /// <summary>
 ///    Constructs and initializes a new instance of <see
 ///    cref="Attachment" /> by reading in the contents of a
 ///    specified file abstraction.
 /// </summary>
 /// <param name="abstraction">
 ///    A <see cref="TagLib.File.IFileAbstraction"/> object containing
 ///    abstraction of the file to read.
 /// </param>
 /// <param name="offset">
 ///    The position in bytes where the picture is located in the
 ///    <see cref="T:File.IFileAbstraction"/>.
 /// </param>
 /// <param name="size">
 ///    The size in bytes of the picture in the
 ///    <see cref="T:File.IFileAbstraction"/> (default: read all).
 /// </param>
 /// <exception cref="ArgumentNullException">
 ///    <paramref name="abstraction" /> is <see langword="null"
 ///    />.
 /// </exception>
 public Attachment(TagLib.File.IFileAbstraction abstraction, long offset = 0, long size = -1)
     : base(abstraction, offset, size)
 {
 }
Exemplo n.º 7
0
 public static NameValueCollection Analyze(TagLib.File.IFileAbstraction file)
 {
     return(Analyze(TagLib.File.Create(file)));
 }
Exemplo n.º 8
0
 private TagLib.File MidiResolver(TagLib.File.IFileAbstraction abstraction, string mimetype, ReadStyle style)
 {
     return(null);
 }