Exemple #1
0
 public LyricsInfo(LyricsInfo info)
 {
     Description          = info.Description;
     LanguageCode         = info.LanguageCode;
     UnsynchronizedLyrics = info.UnsynchronizedLyrics;
     ContentType          = info.ContentType;
     SynchronizedLyrics   = new List <LyricsPhrase>(info.SynchronizedLyrics);
 }
Exemple #2
0
        /// <summary>
        /// Clear all values stored in TagData object
        /// </summary>
        public void Clear()
        {
            Pictures.Clear();
            AdditionalFields.Clear();
            if (Chapters != null)
            {
                Chapters.Clear();
            }

            GeneralDescription = null;
            Title                    = null;
            Artist                   = null;
            OriginalArtist           = null;
            Composer                 = null;
            Comment                  = null;
            Genre                    = null;
            Album                    = null;
            OriginalAlbum            = null;
            RecordingYear            = null;
            RecordingDayMonth        = null;
            RecordingTime            = null;
            RecordingDate            = null;
            TrackNumber              = null;
            DiscNumber               = null;
            Rating                   = null;
            Copyright                = null;
            AlbumArtist              = null;
            Publisher                = null;
            Conductor                = null;
            TrackTotal               = null;
            TrackNumberTotal         = null;
            DiscTotal                = null;
            DiscNumberTotal          = null;
            ChaptersTableDescription = null;
            Lyrics                   = null;
            PublishingDate           = null;

            TrackDigitsForLeadingZeroes = 0;
            DiscDigitsForLeadingZeroes  = 0;

            PaddingSize = -1;
            DurationMs  = 0;
        }
Exemple #3
0
        /// <summary>
        /// Merge given TagData object with current TagData object
        /// </summary>
        /// <param name="data">TagData object to merge</param>
        public void IntegrateValues(TagData data, bool integratePictures = true, bool mergeAdditionalData = true)
        {
            // String values
            IDictionary <byte, String> newData = data.ToMap();

            foreach (byte key in newData.Keys)
            {
                IntegrateValue(key, newData[key]);
            }

            // Pictures
            if (integratePictures && data.Pictures != null)
            {
                IDictionary <PictureInfo, int> picturePositions = generatePicturePositions();

                foreach (PictureInfo newPicInfo in data.Pictures)
                {
                    // New PictureInfo picture type already exists in current TagData
                    if (picturePositions.ContainsKey(newPicInfo))
                    {
                        // New PictureInfo is a demand for deletion
                        if (newPicInfo.MarkedForDeletion)
                        {
                            foreach (PictureInfo picInfo in Pictures)
                            {
                                if (picInfo.ToString().Equals(newPicInfo.ToString()))
                                {
                                    picInfo.MarkedForDeletion = true;
                                }
                            }
                        }
                        else // New PictureInfo is a X-th picture of the same type
                        {
                            newPicInfo.Position = picturePositions[newPicInfo] + 1;
                            Pictures.Add(newPicInfo);
                        }
                    }
                    else // New PictureInfo picture type does not exist in current TagData
                    {
                        Pictures.Add(newPicInfo);
                    }
                }
            }

            bool found;

            // Additional textual fields
            if (mergeAdditionalData)
            {
                foreach (MetaFieldInfo newMetaInfo in data.AdditionalFields)
                {
                    found = false;
                    foreach (MetaFieldInfo metaInfo in AdditionalFields)
                    {
                        // New MetaFieldInfo tag type+field code+streamNumber+language already exists in current TagData
                        // or new MetaFieldInfo mimics an existing field (added or edited through simplified interface)
                        if (metaInfo.EqualsWithoutZone(newMetaInfo) || metaInfo.EqualsApproximate(newMetaInfo))
                        {
                            if (newMetaInfo.MarkedForDeletion)
                            {
                                metaInfo.MarkedForDeletion = true;                                // New MetaFieldInfo is a demand for deletion
                            }
                            else
                            {
                                found          = true;
                                metaInfo.Value = newMetaInfo.Value;
                                break;
                            }
                        }
                    }

                    if (!newMetaInfo.MarkedForDeletion && !found) // New MetaFieldInfo type+streamNumber+language does not exist in current TagData
                    {
                        AdditionalFields.Add(newMetaInfo);
                    }
                    else if (newMetaInfo.MarkedForDeletion && !found) // Cannot delete a field that has not been found
                    {
                        LogDelegator.GetLogDelegate()(Log.LV_WARNING, "Field code " + newMetaInfo.NativeFieldCode + " cannot be deleted because it has not been found on current TagData.");
                    }
                }
            }
            else
            {
                AdditionalFields = new List <MetaFieldInfo>(data.AdditionalFields);
            }

            // Chapters, processed as a whole
            if (data.Chapters != null)
            {
                // Sending an existing but empty chapter list counts as a "marked for deletion"
                if (Chapters != null)
                {
                    Chapters.Clear();
                }
                else
                {
                    Chapters = new List <ChapterInfo>();
                }

                foreach (ChapterInfo chapter in data.Chapters)
                {
                    Chapters.Add(new ChapterInfo(chapter));
                }
            }

            if (data.Lyrics != null)
            {
                Lyrics = new LyricsInfo(data.Lyrics);
            }
        }
        /// <summary>
        /// Stores a 'classic' metadata value into current TagData object according to its key
        ///
        /// NB : This method cannot be used to store non-classic fields; use tagData.AdditionalFields instead
        /// </summary>
        /// <param name="key">Identifier describing the metadata to store (see TagData public consts)</param>
        /// <param name="value">Value of the metadata to store</param>
        public void IntegrateValue(byte key, string value)
        {
            switch (key)
            {
            // Textual fields
            case TAG_FIELD_GENERAL_DESCRIPTION: GeneralDescription = value; break;

            case TAG_FIELD_TITLE: Title = value; break;

            case TAG_FIELD_ARTIST: Artist = value; break;

            case TAG_FIELD_COMPOSER: Composer = value; break;

            case TAG_FIELD_COMMENT: Comment = value; break;

            case TAG_FIELD_GENRE: Genre = value; break;

            case TAG_FIELD_ALBUM: Album = value; break;

            case TAG_FIELD_ORIGINAL_ARTIST: OriginalArtist = value; break;

            case TAG_FIELD_ORIGINAL_ALBUM: OriginalAlbum = value; break;

            case TAG_FIELD_COPYRIGHT: Copyright = value; break;

            case TAG_FIELD_ALBUM_ARTIST: AlbumArtist = value; break;

            case TAG_FIELD_PUBLISHER: Publisher = value; break;

            case TAG_FIELD_CONDUCTOR: Conductor = value; break;

            // Numeric fields (a value at zero mean nothing has been valued -> field should be empty)
            case TAG_FIELD_RECORDING_DATE: RecordingDate = emptyIfZero(value); break;

            case TAG_FIELD_RECORDING_YEAR: RecordingYear = emptyIfZero(value); break;

            case TAG_FIELD_RECORDING_YEAR_OR_DATE:
                if (value != null)
                {
                    if (value.Length < 5)
                    {
                        RecordingYear = emptyIfZero(value);
                    }
                    else
                    {
                        RecordingDate = emptyIfZero(value);
                    }
                }
                break;

            case TAG_FIELD_RECORDING_DAYMONTH: RecordingDayMonth = emptyIfZero(value); break;

            case TAG_FIELD_RECORDING_TIME: RecordingTime = emptyIfZero(value); break;

            case TAG_FIELD_TRACK_NUMBER: TrackNumber = emptyIfZero(value); break;

            case TAG_FIELD_DISC_NUMBER: DiscNumber = emptyIfZero(value); break;

            case TAG_FIELD_RATING: Rating = emptyIfZero(value); break;

            case TAG_FIELD_TRACK_TOTAL: TrackTotal = emptyIfZero(value); break;

            case TAG_FIELD_TRACK_NUMBER_TOTAL: TrackNumberTotal = emptyIfZero(value); break;

            case TAG_FIELD_DISC_TOTAL: DiscTotal = emptyIfZero(value); break;

            case TAG_FIELD_DISC_NUMBER_TOTAL: DiscNumberTotal = emptyIfZero(value); break;

            case TAG_FIELD_CHAPTERS_TOC_DESCRIPTION: ChaptersTableDescription = emptyIfZero(value); break;

            case TAG_FIELD_LYRICS_UNSYNCH:
                if (null == Lyrics)
                {
                    Lyrics = new LyricsInfo();
                }
                Lyrics.UnsynchronizedLyrics = value;
                break;

            case TAG_FIELD_PUBLISHING_DATE: PublishingDate = emptyIfZero(value); break;
            }
        }
Exemple #5
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;
            }
        }