Exemple #1
0
        public static SimpleTag FromFile(string fileName)
        {
            SimpleTag result = new SimpleTag();
            TagBase   tag    = new TagBase();

            tag.ReadFromFile(fileName, new Achamenes.ID3.Frames.Parsers.FrameParserFactory());
            foreach (Frames.Frame frame in tag.Frames)
            {
                if (frame is Frames.PictureFrame)
                {
                    if (((Frames.PictureFrame)frame).PictureType == PictureType.CoverFront)
                    {
                        result.CoverArt = ((Frames.PictureFrame)frame).Picture;
                    }
                    else if (result.CoverArt == null)
                    {
                        result.CoverArt = ((Frames.PictureFrame)frame).Picture;
                    }
                }
                else if (frame is Frames.ArtistTextFrame)
                {
                    result.Artist = ((Frames.ArtistTextFrame)frame).Text;
                }
                else if (frame is Frames.AlbumTextFrame)
                {
                    result.Album = ((Frames.AlbumTextFrame)frame).Text;
                }
                else if (frame is Frames.CommentExtendedTextFrame)
                {
                    result.Comment = ((Frames.CommentExtendedTextFrame)frame).Text;
                }
                else if (frame is Frames.ComposerTextFrame)
                {
                    result.Composer = ((Frames.ComposerTextFrame)frame).Text;
                }
                else if (frame is Frames.CopyrightTextFrame)
                {
                    result.Copyright = ((Frames.CopyrightTextFrame)frame).Text;
                }
                else if (frame is Frames.EncodedByTextFrame)
                {
                    result.EncodedBy = ((Frames.EncodedByTextFrame)frame).Text;
                }
                else if (frame is Frames.GenreTextFrame)
                {
                    StandardGenreManager manager = new StandardGenreManager();
                    result.Genre = manager.TranslateToUserFriendly(((Frames.GenreTextFrame)frame).Text);
                }
                else if (frame is Frames.GroupingTextFrame)
                {
                    result.Grouping = ((Frames.GroupingTextFrame)frame).Text;
                }
                else if (frame is Frames.LyricsExtendedTextFrame)
                {
                    result.Lyrics = ((Frames.LyricsExtendedTextFrame)frame).Text;
                }
                else if (frame is Frames.OriginalArtistTextFrame)
                {
                    result.OriginalArtist = ((Frames.OriginalArtistTextFrame)frame).Text;
                }
                else if (frame is Frames.TitleTextFrame)
                {
                    result.Title = ((Frames.TitleTextFrame)frame).Text;
                }
                else if (frame is Frames.CustomUserUrlFrame)
                {
                    result.UserUrl = ((Frames.CustomUserUrlFrame)frame).Url;
                }
                else if (frame is Frames.OfficialArtistUrlFrame)
                {
                    result.ArtistUrl = ((Frames.OfficialArtistUrlFrame)frame).Url;
                }
                else if (frame is Frames.TrackTextFrame)
                {
                    result.TrackNumber = ((Frames.TrackTextFrame)frame).TrackNumber;
                    result.TotalTracks = ((Frames.TrackTextFrame)frame).TotalTracks;
                }
                else if (frame is Frames.PartOfSetTextFrame)
                {
                    result.PartNumber = ((Frames.PartOfSetTextFrame)frame).PartNumber;
                    result.TotalParts = ((Frames.PartOfSetTextFrame)frame).TotalParts;
                }
                else if (frame is Frames.YearTextFrame)
                {
                    string year = ((Frames.YearTextFrame)frame).Text;
                    if (year != "")
                    {
                        result.Year = year.Substring(0, 4);
                    }
                }
                else if (frame is Frames.ReleaseTimeTextFrame)
                {
                    string year = ((Frames.ReleaseTimeTextFrame)frame).Text;
                    if (year != "")
                    {
                        result.Year = year.Substring(0, 4);
                    }
                }
                else if (frame is Frames.BeatsPerMinuteTextFrame)
                {
                    result.BPM = int.Parse((((Frames.BeatsPerMinuteTextFrame)frame).Text));
                }
            }

            return(result);
        }
Exemple #2
0
        public void WriteToFile(string fileName)
        {
            TagBase tag = new TagBase();

            if (this.Artist != "")
            {
                tag.Frames.Add(new Frames.ArtistTextFrame(this.Artist));
            }
            if (this.Album != "")
            {
                tag.Frames.Add(new Frames.AlbumTextFrame(this.Album));
            }
            if (this.ArtistUrl != "")
            {
                tag.Frames.Add(new Frames.OfficialArtistUrlFrame(this.ArtistUrl));
            }
            if (this.Comment != "")
            {
                tag.Frames.Add(new Frames.CommentExtendedTextFrame(this.Comment, "", LanguageCode.eng));
            }
            if (this.Composer != "")
            {
                tag.Frames.Add(new Frames.ComposerTextFrame(this.Composer));
            }
            if (this.Copyright != "")
            {
                tag.Frames.Add(new Frames.CopyrightTextFrame(this.Copyright));
            }
            if (this.CoverArt != null)
            {
                tag.Frames.Add(new Frames.PictureFrame(this.CoverArt, "", PictureType.CoverFront));
            }
            if (this.EncodedBy != "")
            {
                tag.Frames.Add(new Frames.EncodedByTextFrame(this.EncodedBy));
            }
            if (this.Genre != "")
            {
                tag.Frames.Add(new Frames.GenreTextFrame(this.Genre));
            }
            if (this.Grouping != "")
            {
                tag.Frames.Add(new Frames.GroupingTextFrame(this.Grouping));
            }
            if (this.Lyrics != "")
            {
                tag.Frames.Add(new Frames.LyricsExtendedTextFrame(this.Lyrics, "", LanguageCode.eng));
            }
            if (this.OriginalArtist != "")
            {
                tag.Frames.Add(new Frames.OriginalArtistTextFrame(this.OriginalArtist));
            }
            if (this.Year != null)
            {
                tag.Frames.Add(new Frames.YearTextFrame(this.Year));
            }
            if (this.Title != "")
            {
                tag.Frames.Add(new Frames.TitleTextFrame(this.Title));
            }
            if (this.UserUrl != "")
            {
                tag.Frames.Add(new Frames.CustomUserTextFrame(this.UserUrl));
            }
            if (this.OriginalArtist != "")
            {
                tag.Frames.Add(new Frames.OriginalArtistTextFrame(this.OriginalArtist));
            }

            if (this.BPM > 0)
            {
                tag.Frames.Add(new Frames.BeatsPerMinuteTextFrame(this.BPM));
            }

            if (this.TrackNumber > 0 && this.TotalTracks > 0)
            {
                tag.Frames.Add(new Frames.TrackTextFrame(this.TrackNumber, this.TotalTracks));
            }
            else if (this.TrackNumber > 0)
            {
                tag.Frames.Add(new Frames.TrackTextFrame(this.TrackNumber));
            }

            if (this.PartNumber > 0 && this.TotalParts > 0)
            {
                tag.Frames.Add(new Frames.PartOfSetTextFrame(this.PartNumber, this.TotalParts));
            }
            else if (this.PartNumber > 0)
            {
                tag.Frames.Add(new Frames.PartOfSetTextFrame(this.PartNumber));
            }

            tag.WriteToFile(fileName, ID3v2MajorVersion.Version3, EncodingScheme.UnicodeWithBOM);
        }
Exemple #3
0
        public void TestReadAndWrite()
        {
            TagBase tag=new TagBase();

            //Add text frames common to all versions
            tag.Frames.Add(new AlbumTextFrame("Album"));
            tag.Frames.Add(new ArtistTextFrame("Artist"));
            tag.Frames.Add(new ComposerTextFrame("Composer"));
            tag.Frames.Add(new CopyrightTextFrame("Copyright"));
            tag.Frames.Add(new CustomUserTextFrame("CustomUser"));
            tag.Frames.Add(new DateTextFrame("Date"));
            tag.Frames.Add(new EncodedByTextFrame("EncodedBy"));
            tag.Frames.Add(new FileTypeTextFrame("FileType"));
            tag.Frames.Add(new GenreTextFrame("Genre"));
            tag.Frames.Add(new GroupingTextFrame("Grouping"));
            tag.Frames.Add(new InitialKeyTextFrame("InitialKey"));
            tag.Frames.Add(new LanguageTextFrame("Language"));
            tag.Frames.Add(new LengthTextFrame("Length"));
            tag.Frames.Add(new MediaTypeTextFrame("MediaType"));
            tag.Frames.Add(new OrchestraTextFrame("Orchestra"));
            tag.Frames.Add(new OriginalAlbumTextFrame("OriginalAlbum"));
            tag.Frames.Add(new OriginalArtistTextFrame("OriginalArtist"));
            tag.Frames.Add(new OriginalReleaseYearTextFrame("OriginalReleaseYear"));
            tag.Frames.Add(new PublisherTextFrame("Publisher"));
            tag.Frames.Add(new SoftwareSettingsTextFrame("SoftwareSettings"));
            tag.Frames.Add(new TitleTextFrame("Title"));
            tag.Frames.Add(new EncodingTimeTextFrame("EncodingTime"));
            tag.Frames.Add(new RecordingTimeTextFrame("RecordingTime"));
            tag.Frames.Add(new ReleaseTimeTextFrame("ReleaseTime"));
            tag.Frames.Add(new TaggingTimeTextFrame("TaggingTime"));
            tag.Frames.Add(new OriginalReleaseTimeTextFrame("OriginalReleaseTime"));

            // Picture frames
            System.Drawing.Image img = System.Drawing.Image.FromFile ("Resources/photo.jpg");
            tag.Frames.Add(new PictureFrame(img, "Description!", PictureType.CoverBack));
            tag.Frames.Add(new PictureFrame(img, "Yet another attached picture!", PictureType.CoverFront));

            // General encapsulated object frame
            tag.Frames.Add(new GeneralEncapsulatedObjectFrame("filename.dat", "some descriptoin!", "image/jpeg", GetRandomByteArray(1000, 1000)));

            // Music CD Identifier frame
            tag.Frames.Add(new MusicCDIdentifierFrame(GetRandomByteArray(10, 10)));

            // Play Counter Frame
            tag.Frames.Add(new PlayCounterFrame(11245));

            // Private Frame
            tag.Frames.Add(new PrivateFrame("owner", GetRandomByteArray(100,100)));

            // Unique File ID Frame
            tag.Frames.Add(new UniqueFileIdentifierFrame(GetRandomByteArray(100, 100), "owner"));

            // URL frames
            tag.Frames.Add(new CommercialUrlFrame("http://www.google.com/"));
            tag.Frames.Add(new CustomUserUrlFrame("http://www.google.com/"));
            tag.Frames.Add(new OfficialArtistUrlFrame("http://www.google.com/"));
            tag.Frames.Add(new OfficialAudioFileUrlFrame("http://www.google.com/"));
            tag.Frames.Add(new OfficialAudioSourceUrlFrame("http://www.google.com/"));

            // Part and Track frames
            tag.Frames.Add(new PartOfSetTextFrame(4));
            tag.Frames.Add(new PartOfSetTextFrame(45, 123));
            tag.Frames.Add(new TrackTextFrame(415));
            tag.Frames.Add(new TrackTextFrame(15, 1234));

            // Year frame
            tag.Frames.Add(new YearTextFrame(""));
            tag.Frames.Add(new YearTextFrame("14"));
            tag.Frames.Add(new YearTextFrame("144"));
            tag.Frames.Add(new YearTextFrame("1234"));

            //Time text frame
            tag.Frames.Add(new TimeTextFrame("134"));

            //Beats per minute frame
            tag.Frames.Add(new BeatsPerMinuteTextFrame(134));

            RunTest(tag, ID3v2MajorVersion.Version4, EncodingScheme.Ascii);
            RunTest(tag, ID3v2MajorVersion.Version4, EncodingScheme.BigEndianUnicode);
            RunTest(tag, ID3v2MajorVersion.Version4, EncodingScheme.UnicodeWithBOM);
            RunTest(tag, ID3v2MajorVersion.Version4, EncodingScheme.UTF8);

            RunTest(tag, ID3v2MajorVersion.Version2, EncodingScheme.Ascii);
            RunTest(tag, ID3v2MajorVersion.Version2, EncodingScheme.BigEndianUnicode);
            RunTest(tag, ID3v2MajorVersion.Version2, EncodingScheme.UnicodeWithBOM);
            RunTest(tag, ID3v2MajorVersion.Version2, EncodingScheme.UTF8);

            RunTest(tag, ID3v2MajorVersion.Version3, EncodingScheme.Ascii);
            RunTest(tag, ID3v2MajorVersion.Version3, EncodingScheme.BigEndianUnicode);
            RunTest(tag, ID3v2MajorVersion.Version3, EncodingScheme.UnicodeWithBOM);
            RunTest(tag, ID3v2MajorVersion.Version3, EncodingScheme.UTF8);
        }
Exemple #4
0
        private void RunTest(TagBase tag, ID3v2MajorVersion version, EncodingScheme encoding)
        {
            File.Delete(_taggedFile1);
            File.Delete(_taggedFile2);
            File.Copy(_originalFile, _taggedFile1);
            File.Copy(_originalFile, _taggedFile2);

            tag.WriteToFile(_taggedFile1, version, encoding);

            TagBase tag2=new TagBase();
            tag2.ReadFromFile(_taggedFile1);

            tag2.WriteToFile(_taggedFile2, version, encoding);
            Assert.IsTrue(CompareFiles(_taggedFile1, _taggedFile2));

            TagBase.RemoveTag(_taggedFile1);
            Assert.IsTrue(CompareFiles(_taggedFile1, _originalFile));

            TagBase.RemoveTag(_taggedFile2);
            Assert.IsTrue(CompareFiles(_taggedFile2, _originalFile));
        }
        public static void Main(string[] args)
        {
            TagBase tag=new TagBase();
            tag.Frames.Add(new LastPlayedOnFrame(DateTime.Now, 1, "Test!"));
            tag.WriteToFile("C:/Test.mp3", ID3v2MajorVersion.Version3, EncodingScheme.UnicodeWithBOM);

            TagBase tag2=new TagBase();
            tag2.ReadFromFile("C:/Test.mp3", new MyFrameParserFactory());
            System.Diagnostics.Debug.Assert(tag2.Frames.Count==1);
            System.Diagnostics.Debug.Assert(tag2.Frames[0] is LastPlayedOnFrame);
        }
Exemple #6
0
        public void WriteToFile(string fileName)
        {
            TagBase tag=new TagBase();
            if(this.Artist!="")
                tag.Frames.Add(new Frames.ArtistTextFrame(this.Artist));
            if(this.Album!="")
                tag.Frames.Add(new Frames.AlbumTextFrame(this.Album));
            if(this.ArtistUrl!="")
                tag.Frames.Add(new Frames.OfficialArtistUrlFrame(this.ArtistUrl));
            if(this.Comment!="")
                tag.Frames.Add(new Frames.CommentExtendedTextFrame(this.Comment,"", LanguageCode.eng));
            if(this.Composer!="")
                tag.Frames.Add(new Frames.ComposerTextFrame(this.Composer));
            if(this.Copyright!="")
                tag.Frames.Add(new Frames.CopyrightTextFrame(this.Copyright));
            if(this.CoverArt!=null)
                tag.Frames.Add(new Frames.PictureFrame(this.CoverArt,"",PictureType.CoverFront));
            if(this.EncodedBy!="")
                tag.Frames.Add(new Frames.EncodedByTextFrame(this.EncodedBy));
            if(this.Genre!="")
                tag.Frames.Add(new Frames.GenreTextFrame(this.Genre));
            if(this.Grouping!="")
                tag.Frames.Add(new Frames.GroupingTextFrame(this.Grouping));
            if(this.Lyrics!="")
                tag.Frames.Add(new Frames.LyricsExtendedTextFrame(this.Lyrics,"",LanguageCode.eng));
            if(this.OriginalArtist!="")
                tag.Frames.Add(new Frames.OriginalArtistTextFrame(this.OriginalArtist));
            if(this.Year!=null)
                tag.Frames.Add(new Frames.YearTextFrame(this.Year));
            if(this.Title!="")
                tag.Frames.Add(new Frames.TitleTextFrame(this.Title));
            if(this.UserUrl!="")
                tag.Frames.Add(new Frames.CustomUserTextFrame(this.UserUrl));
            if(this.OriginalArtist!="")
                tag.Frames.Add(new Frames.OriginalArtistTextFrame(this.OriginalArtist));

            if(this.BPM>0)
                tag.Frames.Add(new Frames.BeatsPerMinuteTextFrame(this.BPM));

            if(this.TrackNumber>0 && this.TotalTracks>0)
                tag.Frames.Add(new Frames.TrackTextFrame(this.TrackNumber,this.TotalTracks));
            else if(this.TrackNumber>0)
                tag.Frames.Add(new Frames.TrackTextFrame(this.TrackNumber));

            if(this.PartNumber>0 && this.TotalParts>0)
                tag.Frames.Add(new Frames.PartOfSetTextFrame(this.PartNumber, this.TotalParts));
            else if(this.PartNumber>0)
                tag.Frames.Add(new Frames.PartOfSetTextFrame(this.PartNumber));

            tag.WriteToFile(fileName, ID3v2MajorVersion.Version3, EncodingScheme.UnicodeWithBOM);
        }
Exemple #7
0
        public static SimpleTag FromFile(string fileName)
        {
            SimpleTag result=new SimpleTag();
            TagBase tag=new TagBase();
            tag.ReadFromFile(fileName, new Achamenes.ID3.Frames.Parsers.FrameParserFactory());
            foreach(Frames.Frame frame in tag.Frames)
            {
                if(frame is Frames.PictureFrame)
                {
                    if(((Frames.PictureFrame)frame).PictureType==PictureType.CoverFront)
                        result.CoverArt=((Frames.PictureFrame)frame).Picture;
                    else if(result.CoverArt==null)
                        result.CoverArt=((Frames.PictureFrame)frame).Picture;
                }
                else if(frame is Frames.ArtistTextFrame)
                    result.Artist=((Frames.ArtistTextFrame)frame).Text;
                else if(frame is Frames.AlbumTextFrame)
                    result.Album=((Frames.AlbumTextFrame)frame).Text;
                else if(frame is Frames.CommentExtendedTextFrame)
                    result.Comment=((Frames.CommentExtendedTextFrame)frame).Text;
                else if(frame is Frames.ComposerTextFrame)
                    result.Composer=((Frames.ComposerTextFrame)frame).Text;
                else if(frame is Frames.CopyrightTextFrame)
                    result.Copyright=((Frames.CopyrightTextFrame)frame).Text;
                else if(frame is Frames.EncodedByTextFrame)
                    result.EncodedBy=((Frames.EncodedByTextFrame)frame).Text;
                else if(frame is Frames.GenreTextFrame)
                {
                    StandardGenreManager manager=new StandardGenreManager();
                    result.Genre=manager.TranslateToUserFriendly(((Frames.GenreTextFrame)frame).Text);
                }
                else if(frame is Frames.GroupingTextFrame)
                    result.Grouping=((Frames.GroupingTextFrame)frame).Text;
                else if(frame is Frames.LyricsExtendedTextFrame)
                    result.Lyrics=((Frames.LyricsExtendedTextFrame)frame).Text;
                else if(frame is Frames.OriginalArtistTextFrame)
                    result.OriginalArtist=((Frames.OriginalArtistTextFrame)frame).Text;
                else if(frame is Frames.TitleTextFrame)
                    result.Title=((Frames.TitleTextFrame)frame).Text;
                else if(frame is Frames.CustomUserUrlFrame)
                    result.UserUrl=((Frames.CustomUserUrlFrame)frame).Url;
                else if(frame is Frames.OfficialArtistUrlFrame)
                    result.ArtistUrl=((Frames.OfficialArtistUrlFrame)frame).Url;
                else if(frame is Frames.TrackTextFrame)
                {
                    result.TrackNumber=((Frames.TrackTextFrame)frame).TrackNumber;
                    result.TotalTracks=((Frames.TrackTextFrame)frame).TotalTracks;
                }
                else if(frame is Frames.PartOfSetTextFrame)
                {
                    result.PartNumber=((Frames.PartOfSetTextFrame)frame).PartNumber;
                    result.TotalParts=((Frames.PartOfSetTextFrame)frame).TotalParts;
                }
                else if(frame is Frames.YearTextFrame)
                {
                    string year=((Frames.YearTextFrame)frame).Text;
                    if(year!="")
                        result.Year=year.Substring(0, 4);
                }
                else if(frame is Frames.ReleaseTimeTextFrame)
                {
                    string year=((Frames.ReleaseTimeTextFrame)frame).Text;
                    if(year!="")
                        result.Year=year.Substring(0, 4);
                }
                else if(frame is Frames.BeatsPerMinuteTextFrame)
                {
                    result.BPM=int.Parse((((Frames.BeatsPerMinuteTextFrame)frame).Text));
                }
            }

            return result;
        }