ReadFromFile() public method

public ReadFromFile ( string fileName ) : ID3v2MajorVersion
fileName string
return ID3v2MajorVersion
Example #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);
        }
Example #2
0
        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);
        }
Example #3
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));
        }
Example #4
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;
        }