Exemplo n.º 1
0
        protected void Update(bool readEmbeddedPictures = false)
        {
            // TODO when tag is not available, customize by naming options // tracks (...)
            fileIO = new AudioFileIO(Path, readEmbeddedPictures, Settings.ReadAllMetaFrames);

            Title = fileIO.Title;
            if (Settings.UseFileNameWhenNoTitle && (null == Title || "" == Title))
            {
                Title = System.IO.Path.GetFileNameWithoutExtension(Path);
            }
            Artist         = Utils.ProtectValue(fileIO.Artist);
            Composer       = Utils.ProtectValue(fileIO.Composer);
            Comment        = Utils.ProtectValue(fileIO.Comment);
            Genre          = Utils.ProtectValue(fileIO.Genre);
            OriginalArtist = Utils.ProtectValue(fileIO.OriginalArtist);
            OriginalAlbum  = Utils.ProtectValue(fileIO.OriginalAlbum);
            Description    = Utils.ProtectValue(fileIO.GeneralDescription);
            Copyright      = Utils.ProtectValue(fileIO.Copyright);
            Publisher      = Utils.ProtectValue(fileIO.Publisher);
            AlbumArtist    = Utils.ProtectValue(fileIO.AlbumArtist);
            Conductor      = Utils.ProtectValue(fileIO.Conductor);
            Year           = fileIO.IntYear;
            Album          = fileIO.Album;
            TrackNumber    = fileIO.Track;
            DiscNumber     = fileIO.Disc;
            Bitrate        = fileIO.IntBitRate;
            CodecFamily    = fileIO.CodecFamily;
            Duration       = fileIO.IntDuration;
            Rating         = fileIO.Rating;
            Popularity     = fileIO.Popularity;
            IsVBR          = fileIO.IsVBR;
            SampleRate     = fileIO.SampleRate;

            Chapters = fileIO.Chapters;

            AdditionalFields        = fileIO.AdditionalFields;
            initialAdditionalFields = fileIO.AdditionalFields.Keys;

            PictureTokens = new List <PictureInfo>(fileIO.PictureTokens);

            if (readEmbeddedPictures)
            {
                foreach (PictureInfo picInfo in fileIO.EmbeddedPictures)
                {
                    picInfo.ComputePicHash();
                    embeddedPictures.Add(picInfo);

                    PictureInfo initialPicInfo = new PictureInfo(picInfo, false);
                    initialEmbeddedPictures.Add(initialPicInfo);
                }
            }

            if (!readEmbeddedPictures && embeddedPictures != null)
            {
                embeddedPictures.Clear();
                initialEmbeddedPictures.Clear();
                embeddedPictures        = null;
                initialEmbeddedPictures = null;
            }
        }
Exemplo n.º 2
0
        public ChapterInfo(ChapterInfo chapter)
        {
            StartTime = chapter.StartTime; EndTime = chapter.EndTime; StartOffset = chapter.StartOffset; EndOffset = chapter.EndOffset; Title = chapter.Title; Subtitle = chapter.Subtitle; Url = chapter.Url; UniqueID = chapter.UniqueID;

            if (chapter.Picture != null)
            {
                Picture = new PictureInfo(chapter.Picture);
            }
        }
Exemplo n.º 3
0
        // ---------------- CONSTRUCTORS

        public PictureInfo(PictureInfo picInfo, bool copyPictureData = true)
        {
            this.PicType          = picInfo.PicType;
            this.NativeFormat     = picInfo.NativeFormat;
            this.Position         = picInfo.Position;
            this.TagType          = picInfo.TagType;
            this.NativePicCode    = picInfo.NativePicCode;
            this.NativePicCodeStr = picInfo.NativePicCodeStr;
            this.Description      = picInfo.Description;
            if (copyPictureData && picInfo.PictureData != null)
            {
                this.PictureData = new byte[picInfo.PictureData.Length];
                picInfo.PictureData.CopyTo(this.PictureData, 0);
            }
            this.PictureHash       = picInfo.PictureHash;
            this.MarkedForDeletion = picInfo.MarkedForDeletion;
            this.TransientFlag     = picInfo.TransientFlag;
        }
Exemplo n.º 4
0
        // ---------------- CONSTRUCTORS

        public PictureInfo(PictureInfo picInfo, Boolean copyPictureData = true)
        {
            PicType          = picInfo.PicType;
            NativeFormat     = picInfo.NativeFormat;
            Position         = picInfo.Position;
            TagType          = picInfo.TagType;
            NativePicCode    = picInfo.NativePicCode;
            NativePicCodeStr = picInfo.NativePicCodeStr;
            Description      = picInfo.Description;
            if (copyPictureData && picInfo.PictureData != null)
            {
                PictureData = new Byte[picInfo.PictureData.Length];
                picInfo.PictureData.CopyTo(PictureData, 0);
            }
            PictureHash       = picInfo.PictureHash;
            MarkedForDeletion = picInfo.MarkedForDeletion;
            Flag = picInfo.Flag;
        }
Exemplo n.º 5
0
        private TagData toTagData()
        {
            TagData result = new TagData();

            result.Title              = Title;
            result.Artist             = Artist;
            result.Composer           = Composer;
            result.Comment            = Comment;
            result.Genre              = Genre;
            result.OriginalArtist     = OriginalArtist;
            result.OriginalAlbum      = OriginalAlbum;
            result.GeneralDescription = Description;
            result.Rating             = (Popularity * 5).ToString();
            result.Copyright          = Copyright;
            result.Publisher          = Publisher;
            if (!PublishingDate.Equals(DateTime.MinValue))
            {
                result.PublishingDate = TrackUtils.FormatISOTimestamp(PublishingDate);
            }
            result.AlbumArtist = AlbumArtist;
            result.Conductor   = Conductor;
            if (!Date.Equals(DateTime.MinValue))
            {
                result.RecordingDate = TrackUtils.FormatISOTimestamp(Date);
            }
            result.RecordingYear            = Year.ToString();
            result.Album                    = Album;
            result.TrackNumber              = TrackNumber.ToString();
            result.TrackTotal               = TrackTotal.ToString();
            result.DiscNumber               = DiscNumber.ToString();
            result.DiscTotal                = DiscTotal.ToString();
            result.ChaptersTableDescription = ChaptersTableDescription.ToString();

            result.Chapters = new List <ChapterInfo>();
            foreach (ChapterInfo chapter in Chapters)
            {
                result.Chapters.Add(new ChapterInfo(chapter));
            }

            if (Lyrics != null)
            {
                result.Lyrics = new LyricsInfo(Lyrics);
            }

            foreach (string s in AdditionalFields.Keys)
            {
                result.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ANY, s, AdditionalFields[s]));
            }

            // Detect and tag deleted Additional fields (=those which were in initialAdditionalFields and do not appear in AdditionalFields anymore)
            foreach (string s in initialAdditionalFields)
            {
                if (!AdditionalFields.ContainsKey(s))
                {
                    MetaFieldInfo metaFieldToDelete = new MetaFieldInfo(MetaDataIOFactory.TAG_ANY, s, "");
                    metaFieldToDelete.MarkedForDeletion = true;
                    result.AdditionalFields.Add(metaFieldToDelete);
                }
            }

            result.Pictures = new List <PictureInfo>();
            if (currentEmbeddedPictures != null)
            {
                foreach (PictureInfo targetPic in currentEmbeddedPictures)
                {
                    targetPic.TransientFlag = 0;
                }
            }

            if (initialEmbeddedPictures != null && currentEmbeddedPictures != null)
            {
                foreach (PictureInfo picInfo in initialEmbeddedPictures)
                {
                    // Detect and tag deleted pictures (=those which were in initialEmbeddedPictures and do not appear in embeddedPictures anymore)
                    if (!currentEmbeddedPictures.Contains(picInfo))
                    {
                        PictureInfo picToDelete = new PictureInfo(picInfo);
                        picToDelete.MarkedForDeletion = true;
                        result.Pictures.Add(picToDelete);
                    }
                    else // Only add new additions (pictures identical to initial list will be kept, and do not have to make it to the list, or else a duplicate will be created)
                    {
                        foreach (PictureInfo targetPic in currentEmbeddedPictures)
                        {
                            if (targetPic.Equals(picInfo))
                            {
                                // Compare picture contents
                                targetPic.ComputePicHash();

                                if (targetPic.PictureHash != picInfo.PictureHash)
                                {
                                    // A new picture content has been defined for an existing location
                                    result.Pictures.Add(targetPic);

                                    PictureInfo picToDelete = new PictureInfo(picInfo);
                                    picToDelete.MarkedForDeletion = true;
                                    result.Pictures.Add(picToDelete);
                                }

                                targetPic.TransientFlag = 1;
                            }
                        }
                    }
                }

                if (currentEmbeddedPictures != null)
                {
                    foreach (PictureInfo targetPic in currentEmbeddedPictures)
                    {
                        if (0 == targetPic.TransientFlag) // Entirely new pictures without equivalent in initialEmbeddedPictures
                        {
                            result.Pictures.Add(targetPic);
                        }
                    }
                }
            }

            return(result);
        }
Exemplo n.º 6
0
        protected void Update(bool onlyReadEmbeddedPictures = false)
        {
            if (string.IsNullOrEmpty(Path))
            {
                return;
            }

            // TODO when tag is not available, customize by naming options // tracks (...)
            if (null == stream)
            {
                fileIO = new AudioFileIO(Path, onlyReadEmbeddedPictures, Settings.ReadAllMetaFrames, writeProgress);
            }
            else
            {
                fileIO = new AudioFileIO(stream, mimeType, onlyReadEmbeddedPictures, Settings.ReadAllMetaFrames, writeProgress);
            }

            if (onlyReadEmbeddedPictures)
            {
                foreach (PictureInfo picInfo in fileIO.EmbeddedPictures)
                {
                    picInfo.ComputePicHash();
                    currentEmbeddedPictures.Add(picInfo);

                    PictureInfo initialPicInfo = new PictureInfo(picInfo, false);
                    initialEmbeddedPictures.Add(initialPicInfo);
                }
                // Don't overwrite all the other fields with their initial value
                // otherwise any value set by the user before calling EmbeddedPictures would be lost
                return;
            }

            if (currentEmbeddedPictures != null)
            {
                currentEmbeddedPictures.Clear();
                initialEmbeddedPictures.Clear();
                currentEmbeddedPictures = null;
                initialEmbeddedPictures = null;
            }

            MetadataFormats = fileIO.MetadataFormats;

            Title = fileIO.Title;
            if (Settings.UseFileNameWhenNoTitle && (null == Title || "" == Title) && Path != InMemoryPath)
            {
                Title = System.IO.Path.GetFileNameWithoutExtension(Path);
            }
            Artist                   = Utils.ProtectValue(fileIO.Artist);
            Composer                 = Utils.ProtectValue(fileIO.Composer);
            Comment                  = Utils.ProtectValue(fileIO.Comment);
            Genre                    = Utils.ProtectValue(fileIO.Genre);
            OriginalArtist           = Utils.ProtectValue(fileIO.OriginalArtist);
            OriginalAlbum            = Utils.ProtectValue(fileIO.OriginalAlbum);
            Description              = Utils.ProtectValue(fileIO.GeneralDescription);
            Copyright                = Utils.ProtectValue(fileIO.Copyright);
            Publisher                = Utils.ProtectValue(fileIO.Publisher);
            PublishingDate           = fileIO.PublishingDate;
            AlbumArtist              = Utils.ProtectValue(fileIO.AlbumArtist);
            Conductor                = Utils.ProtectValue(fileIO.Conductor);
            Date                     = fileIO.Date;
            Year                     = fileIO.IntYear;
            Album                    = fileIO.Album;
            TrackNumber              = fileIO.Track;
            TrackTotal               = fileIO.TrackTotal;
            DiscNumber               = fileIO.Disc;
            DiscTotal                = fileIO.DiscTotal;
            ChaptersTableDescription = Utils.ProtectValue(fileIO.ChaptersTableDescription);

            Bitrate     = fileIO.IntBitRate;
            CodecFamily = fileIO.CodecFamily;
            AudioFormat = fileIO.AudioFormat;

            DurationMs          = fileIO.Duration;
            Popularity          = fileIO.Popularity;
            IsVBR               = fileIO.IsVBR;
            SampleRate          = fileIO.SampleRate;
            ChannelsArrangement = fileIO.ChannelsArrangement;

            Chapters = fileIO.Chapters;
            Lyrics   = fileIO.Lyrics;

            AdditionalFields        = fileIO.AdditionalFields;
            initialAdditionalFields = fileIO.AdditionalFields.Keys;

            PictureTokens = new List <PictureInfo>(fileIO.PictureTokens);
        }
Exemplo n.º 7
0
        protected void Update(bool readEmbeddedPictures = false)
        {
            if ((null == Path) || (0 == Path.Length))
            {
                return;
            }

            // TODO when tag is not available, customize by naming options // tracks (...)
            if (null == stream)
            {
                fileIO = new AudioFileIO(Path, readEmbeddedPictures, Settings.ReadAllMetaFrames);
            }
            else
            {
                fileIO = new AudioFileIO(stream, mimeType, readEmbeddedPictures, Settings.ReadAllMetaFrames);
            }

            Title = fileIO.Title;
            if (Settings.UseFileNameWhenNoTitle && (null == Title || "" == Title))
            {
                Title = System.IO.Path.GetFileNameWithoutExtension(Path);
            }
            Artist                   = Utils.ProtectValue(fileIO.Artist);
            Composer                 = Utils.ProtectValue(fileIO.Composer);
            Comment                  = Utils.ProtectValue(fileIO.Comment);
            Genre                    = Utils.ProtectValue(fileIO.Genre);
            OriginalArtist           = Utils.ProtectValue(fileIO.OriginalArtist);
            OriginalAlbum            = Utils.ProtectValue(fileIO.OriginalAlbum);
            Description              = Utils.ProtectValue(fileIO.GeneralDescription);
            Copyright                = Utils.ProtectValue(fileIO.Copyright);
            Publisher                = Utils.ProtectValue(fileIO.Publisher);
            AlbumArtist              = Utils.ProtectValue(fileIO.AlbumArtist);
            Conductor                = Utils.ProtectValue(fileIO.Conductor);
            Date                     = fileIO.Date;
            Year                     = fileIO.IntYear;
            Album                    = fileIO.Album;
            TrackNumber              = fileIO.Track;
            TrackTotal               = fileIO.TrackTotal;
            DiscNumber               = fileIO.Disc;
            DiscTotal                = fileIO.DiscTotal;
            ChaptersTableDescription = Utils.ProtectValue(fileIO.ChaptersTableDescription);

            Bitrate     = fileIO.IntBitRate;
            CodecFamily = fileIO.CodecFamily;
            DurationMs  = fileIO.Duration;
#pragma warning disable CS0618 // Obsolete
            Rating = fileIO.Rating;
#pragma warning restore CS0618 // Obsolete
            Popularity          = fileIO.Popularity;
            IsVBR               = fileIO.IsVBR;
            SampleRate          = fileIO.SampleRate;
            ChannelsArrangement = fileIO.ChannelsArrangement;

            Chapters = fileIO.Chapters;
            Lyrics   = fileIO.Lyrics;

            AdditionalFields        = fileIO.AdditionalFields;
            initialAdditionalFields = fileIO.AdditionalFields.Keys;

            PictureTokens = new List <PictureInfo>(fileIO.PictureTokens);

            if (readEmbeddedPictures)
            {
                foreach (PictureInfo picInfo in fileIO.EmbeddedPictures)
                {
                    picInfo.ComputePicHash();
                    currentEmbeddedPictures.Add(picInfo);

                    PictureInfo initialPicInfo = new PictureInfo(picInfo, false);
                    initialEmbeddedPictures.Add(initialPicInfo);
                }
            }

            if (!readEmbeddedPictures && currentEmbeddedPictures != null)
            {
                currentEmbeddedPictures.Clear();
                initialEmbeddedPictures.Clear();
                currentEmbeddedPictures = null;
                initialEmbeddedPictures = null;
            }
        }