Package org.farng.mp3.id3

Examples of org.farng.mp3.id3.FrameBodyTPE4


    }

    public void setSongLyric(String songLyrics) {
        AbstractID3v2Frame field = getFrame("SYLT");
        if (field == null) {
            field = new ID3v2_3Frame(new FrameBodyUSLT((byte) 0, "ENG", "", songLyrics.trim()));
            setFrame(field);
        } else {
            ((FrameBodyUSLT) field.getBody()).setLyric(songLyrics.trim());
        }
    }
View Full Code Here


            Logger.getLogger(JMP3Propriedades.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    private void precisaCriarV2() {
        //  if (mp3File.hasID3v1Tag()) {
        ID3v2_4 id = new ID3v2_4();
        id.setSongTitle(jTextField_Titulo.getText());
        id.setAlbumTitle(jTextField_Album.getText());
        id.setLeadArtist(jTextField_Interp.getText());
         id.setSongGenre((String)(jComboBoxGenero.getSelectedItem()));
        id.setYearReleased(jTextField_ano.getText());
        id.setSongComment(jTextField_Comentario.getText());
        mp3File.setID3v2Tag(id);
        alterarMusica();
        try {
            mp3File.save(TagConstant.MP3_FILE_SAVE_APPEND);
            // }
View Full Code Here

     */
    public void testJohnMartinWCOP() throws Exception {
        setUp();
        File testFile = this.testMusicArray[0].getMp3file();
        MP3File mp3file = this.testMusicArray[0];
        ID3v2_4 tag = null;
        ID3v2_4Frame wcopFrame = null;
        FrameBodyWCOP wcopFrameBody = null;
        tag = new ID3v2_4(mp3file.getID3v2Tag());
        System.err.println("The tag is: " + tag);
        wcopFrame = new ID3v2_4Frame(tag.getFrame("WCOP"));
        wcopFrameBody = new FrameBodyWCOP("http://creativecommons.org");
        wcopFrameBody.setUrlLink("http://creativecommons.org");
        wcopFrame.setBody(wcopFrameBody);
        System.err.println("The wcop frame is: " + wcopFrame.toString());
        tag.setFrame(wcopFrame);
        mp3file.setID3v2Tag(tag);
        System.err.println("The WCOP frame contains: " + ((FrameBodyWCOP) wcopFrame.getBody()).getUrlLink());
        mp3file.save(testFile.toString(), TagConstant.MP3_FILE_SAVE_OVERWRITE);
        mp3file.save();
        mp3file = new MP3File(testFile);
        tag = new ID3v2_4(mp3file.getID3v2Tag());
        System.err.println("The tag is: " + tag);

        // run again
        wcopFrame = new ID3v2_4Frame(tag.getFrame("WCOP"));
        wcopFrameBody = new FrameBodyWCOP("http://creativecommons.org");
        wcopFrameBody.setUrlLink("http://creativecommons.org");
        wcopFrame.setBody(wcopFrameBody);
        System.err.println("The wcop frame is: " + wcopFrame.toString());
        tag.setFrame(wcopFrame);
        mp3file.setID3v2Tag(tag);
        System.err.println("The WCOP frame contains: " + ((FrameBodyWCOP) wcopFrame.getBody()).getUrlLink());
        mp3file.save(testFile.toString(), TagConstant.MP3_FILE_SAVE_OVERWRITE);
        mp3file.save();
        mp3file = new MP3File(testFile);
        tag = new ID3v2_4(mp3file.getID3v2Tag());
        System.err.println("The tag is: " + tag);
        tearDown();
    }
View Full Code Here

            assertEquals(this.testMusicArray[i].getMp3file().getName(),
                         this.testMusicMP3StartByteNew[i],
                         this.testMusicArray[i].getMp3StartByte());
        }
        MP3File mp3file = new MP3File(new File(this.testMusicDirectory, this.testMusic[1]));
        ID3v2_4 tag = new ID3v2_4();
        ID3v2_4Frame frame = new ID3v2_4Frame();
        FrameBodyTPE1 body = new FrameBodyTPE1((byte) 0, "text");

        //        // save and re-read this to set file/tag alter preservation tags to
        // correct
        //        // values;
        //        mp3file.save();
        //        mp3file = new MP3File(new File(testMusicDirectory, "Theme - Fat
        // Albert.mp3"));
        RandomAccessFile randomAccessFile;
        frame.setBody(body);
        tag.setFrame(frame);
        assertTrue(mp3file.adjustID3v2Padding(1, true, true));
        assertEquals(1, mp3file.getMp3StartByte());
        assertTrue(mp3file.adjustID3v2Padding(2, true, true));
        assertEquals(2, mp3file.getMp3StartByte());
        assertTrue(mp3file.adjustID3v2Padding(this.paddingSize, true, true));
        assertEquals(this.paddingSize, mp3file.getMp3StartByte());

        // save tag
        mp3file.setID3v2Tag(tag);
        mp3file.save();
        assertEquals(this.paddingSize, mp3file.getMp3StartByte());
        assertFalse(mp3file.adjustID3v2Padding(0, false, true));
        assertEquals(this.paddingSize, mp3file.getMp3StartByte());

        // compare new tag
        randomAccessFile = new RandomAccessFile(mp3file.getMp3file(), "r");
        ID3v2_4 tagNew = new ID3v2_4(randomAccessFile);
        assertTrue(tagNew.equals(tag));
        assertFalse(mp3file.adjustID3v2Padding(1, false, true));
        assertEquals(this.paddingSize, mp3file.getMp3StartByte());

        // compare new tag
        randomAccessFile = new RandomAccessFile(mp3file.getMp3file(), "r");
        tagNew = new ID3v2_4(randomAccessFile);
        assertTrue(tagNew.equals(tag));
        assertTrue(mp3file.adjustID3v2Padding(1, true, true));
        assertEquals(32, mp3file.getMp3StartByte());

        // compare new tag
        randomAccessFile = new RandomAccessFile(mp3file.getMp3file(), "r");
        tagNew = new ID3v2_4(randomAccessFile);
        assertTrue(tagNew.equals(tag));
        assertTrue(mp3file.adjustID3v2Padding(this.paddingSize, true, false));
        assertEquals(this.paddingSize, mp3file.getMp3StartByte());

//        // compare new tag
//        randomAccessFile = new RandomAccessFile(mp3file.getMp3file(), "r");
View Full Code Here

        List frameList;
        final String testString = "Test String";
        mp3file = new MP3File();
        frame = new ID3v2_4Frame(new FrameBodyTIT2((byte) 0, testString));
        id3v1 = new ID3v1_1();
        id3v2 = new ID3v2_4();
        lyrics3 = new Lyrics3v2();
        filename = FilenameTagBuilder.createEmptyFilenameTag();
        id3v1.setTitle(testString);
        id3v2.setFrame(frame);
        try {
            ((Lyrics3v2) lyrics3).setField(new Lyrics3v2Field(frame));
        } catch (TagException ex) {
            fail("This should not happen. " + ex.getMessage());
        }
        filename.setFrame(frame);

        // different nulls
        mp3file = new MP3File();
        mp3file.setID3v1Tag(null);
        mp3file.setID3v2Tag(null);
        mp3file.setLyrics3Tag(null);
        mp3file.setFilenameTag(null);
        frameList = mp3file.getFrameAcrossTags("TIT2");
        assertEquals(0, frameList.size());
        mp3file = new MP3File();
        mp3file.setID3v1Tag(id3v1);
        mp3file.setID3v2Tag(null);
        mp3file.setLyrics3Tag(null);
        mp3file.setFilenameTag(null);
        frameList = mp3file.getFrameAcrossTags("TIT2");
        assertEquals(1, frameList.size());
        for (int i = 0; i < frameList.size(); i++) {
            assertEquals(frame, frameList.get(i));
        }
        mp3file = new MP3File();
        mp3file.setID3v1Tag(null);
        mp3file.setID3v2Tag(id3v2);
        mp3file.setLyrics3Tag(null);
        mp3file.setFilenameTag(null);
        frameList = mp3file.getFrameAcrossTags("TIT2");
        assertEquals(1, frameList.size());
        for (int i = 0; i < frameList.size(); i++) {
            assertEquals(frame, frameList.get(i));
        }
        mp3file = new MP3File();
        mp3file.setID3v1Tag(null);
        mp3file.setID3v2Tag(null);
        mp3file.setLyrics3Tag(lyrics3);
        mp3file.setFilenameTag(null);
        frameList = mp3file.getFrameAcrossTags("TIT2");
        assertEquals(1, frameList.size());
        for (int i = 0; i < frameList.size(); i++) {
            assertEquals(frame, frameList.get(i));
        }
        mp3file = new MP3File();
        mp3file.setID3v1Tag(null);
        mp3file.setID3v2Tag(null);
        mp3file.setLyrics3Tag(null);
        mp3file.setFilenameTag(filename);
        frameList = mp3file.getFrameAcrossTags("TIT2");
        assertEquals(1, frameList.size());
        for (int i = 0; i < frameList.size(); i++) {
            assertEquals(frame, frameList.get(i));
        }
        mp3file = new MP3File();
        mp3file.setID3v1Tag(id3v1);
        mp3file.setID3v2Tag(id3v2);
        mp3file.setLyrics3Tag(null);
        mp3file.setFilenameTag(null);
        frameList = mp3file.getFrameAcrossTags("TIT2");
        assertEquals(2, frameList.size());
        for (int i = 0; i < frameList.size(); i++) {
            assertEquals(frame, frameList.get(i));
        }
        mp3file = new MP3File();
        mp3file.setID3v1Tag(id3v1);
        mp3file.setID3v2Tag(null);
        mp3file.setLyrics3Tag(lyrics3);
        mp3file.setFilenameTag(null);
        frameList = mp3file.getFrameAcrossTags("TIT2");
        assertEquals(2, frameList.size());
        for (int i = 0; i < frameList.size(); i++) {
            assertEquals(frame, frameList.get(i));
        }
        mp3file = new MP3File();
        mp3file.setID3v1Tag(id3v1);
        mp3file.setID3v2Tag(null);
        mp3file.setLyrics3Tag(null);
        mp3file.setFilenameTag(filename);
        frameList = mp3file.getFrameAcrossTags("TIT2");
        assertEquals(2, frameList.size());
        for (int i = 0; i < frameList.size(); i++) {
            assertEquals(frame, frameList.get(i));
        }
        mp3file = new MP3File();
        mp3file.setID3v1Tag(null);
        mp3file.setID3v2Tag(id3v2);
        mp3file.setLyrics3Tag(lyrics3);
        mp3file.setFilenameTag(null);
        frameList = mp3file.getFrameAcrossTags("TIT2");
        assertEquals(2, frameList.size());
        for (int i = 0; i < frameList.size(); i++) {
            assertEquals(frame, frameList.get(i));
        }
        mp3file = new MP3File();
        mp3file.setID3v1Tag(null);
        mp3file.setID3v2Tag(id3v2);
        mp3file.setLyrics3Tag(null);
        mp3file.setFilenameTag(filename);
        frameList = mp3file.getFrameAcrossTags("TIT2");
        assertEquals(2, frameList.size());
        for (int i = 0; i < frameList.size(); i++) {
            assertEquals(frame, frameList.get(i));
        }
        mp3file = new MP3File();
        mp3file.setID3v1Tag(null);
        mp3file.setID3v2Tag(null);
        mp3file.setLyrics3Tag(lyrics3);
        mp3file.setFilenameTag(filename);
        frameList = mp3file.getFrameAcrossTags("TIT2");
        assertEquals(2, frameList.size());
        for (int i = 0; i < frameList.size(); i++) {
            assertEquals(frame, frameList.get(i));
        }
        mp3file = new MP3File();
        mp3file.setID3v1Tag(id3v1);
        mp3file.setID3v2Tag(id3v2);
        mp3file.setLyrics3Tag(lyrics3);
        mp3file.setFilenameTag(null);
        frameList = mp3file.getFrameAcrossTags("TIT2");
        assertEquals(3, frameList.size());
        for (int i = 0; i < frameList.size(); i++) {
            assertEquals(frame, frameList.get(i));
        }
        mp3file = new MP3File();
        mp3file.setID3v1Tag(id3v1);
        mp3file.setID3v2Tag(id3v2);
        mp3file.setLyrics3Tag(null);
        mp3file.setFilenameTag(filename);
        frameList = mp3file.getFrameAcrossTags("TIT2");
        assertEquals(3, frameList.size());
        for (int i = 0; i < frameList.size(); i++) {
            assertEquals(frame, frameList.get(i));
        }
        mp3file = new MP3File();
        mp3file.setID3v1Tag(id3v1);
        mp3file.setID3v2Tag(null);
        mp3file.setLyrics3Tag(lyrics3);
        mp3file.setFilenameTag(filename);
        frameList = mp3file.getFrameAcrossTags("TIT2");
        assertEquals(3, frameList.size());
        for (int i = 0; i < frameList.size(); i++) {
            assertEquals(frame, frameList.get(i));
        }
        mp3file = new MP3File();
        mp3file.setID3v1Tag(null);
        mp3file.setID3v2Tag(id3v2);
        mp3file.setLyrics3Tag(lyrics3);
        mp3file.setFilenameTag(filename);
        frameList = mp3file.getFrameAcrossTags("TIT2");
        assertEquals(3, frameList.size());
        for (int i = 0; i < frameList.size(); i++) {
            assertEquals(frame, frameList.get(i));
        }

        // TEST each frame
        // TIT1
        mp3file = new MP3File();
        mp3file.setID3v1Tag(id3v1);
        mp3file.setID3v2Tag(id3v2);
        mp3file.setLyrics3Tag(lyrics3);
        mp3file.setFilenameTag(filename);
        frameList = mp3file.getFrameAcrossTags("TIT2");
        assertEquals(4, frameList.size());
        for (int i = 0; i < frameList.size(); i++) {
            assertEquals(frame, frameList.get(i));
        }

        // TPE1
        mp3file = new MP3File();
        id3v1 = new ID3v1_1();
        id3v2 = new ID3v2_4();
        lyrics3 = new Lyrics3v2();
        filename = FilenameTagBuilder.createEmptyFilenameTag();
        frame = new ID3v2_4Frame(new FrameBodyTPE1((byte) 0, testString));
        id3v1.setArtist(testString);
        id3v2.setFrame(frame);
        try {
            ((Lyrics3v2) lyrics3).setField(new Lyrics3v2Field(frame));
        } catch (TagException ex) {
            fail("This should not happen. " + ex.getMessage());
        }
        filename.setFrame(frame);
        mp3file.setID3v1Tag(id3v1);
        mp3file.setID3v2Tag(id3v2);
        mp3file.setLyrics3Tag(lyrics3);
        mp3file.setFilenameTag(filename);
        frameList = mp3file.getFrameAcrossTags("TPE1");
        assertEquals(4, frameList.size());
        for (int i = 0; i < frameList.size(); i++) {
            assertEquals(frame, frameList.get(i));
        }

        // TALB
        mp3file = new MP3File();
        id3v1 = new ID3v1_1();
        id3v2 = new ID3v2_4();
        lyrics3 = new Lyrics3v2();
        filename = FilenameTagBuilder.createEmptyFilenameTag();
        frame = new ID3v2_4Frame(new FrameBodyTALB((byte) 0, testString));
        id3v1.setAlbum(testString);
        id3v2.setFrame(frame);
        try {
            ((Lyrics3v2) lyrics3).setField(new Lyrics3v2Field(frame));
        } catch (TagException ex) {
            fail("This should not happen. " + ex.getMessage());
        }
        filename.setFrame(frame);
        mp3file.setID3v1Tag(id3v1);
        mp3file.setID3v2Tag(id3v2);
        mp3file.setLyrics3Tag(lyrics3);
        mp3file.setFilenameTag(filename);
        frameList = mp3file.getFrameAcrossTags("TALB");
        assertEquals(4, frameList.size());
        for (int i = 0; i < frameList.size(); i++) {
            assertEquals(frame, frameList.get(i));
        }

        // TDRC
        mp3file = new MP3File();
        id3v1 = new ID3v1_1();
        id3v2 = new ID3v2_4();
        lyrics3 = new Lyrics3v2();
        filename = FilenameTagBuilder.createEmptyFilenameTag();
        frame = new ID3v2_4Frame(new FrameBodyTDRC((byte) 0, "1992"));
        id3v1.setYear("1992");
        id3v2.setFrame(frame);
        try {
            ((Lyrics3v2) lyrics3).setField(new Lyrics3v2Field(frame));
            fail("Somehow created a TDRC (year) Lyrics3v2 Field");
        } catch (TagException ex) {
            // correct behavior
        }
        filename.setFrame(frame);
        mp3file.setID3v1Tag(id3v1);
        mp3file.setID3v2Tag(id3v2);
        mp3file.setLyrics3Tag(lyrics3);
        mp3file.setFilenameTag(filename);
        frameList = mp3file.getFrameAcrossTags("TDRC");
        assertEquals(3, frameList.size());
        for (int i = 0; i < frameList.size(); i++) {
            assertEquals(frame, frameList.get(i));
        }

        // COMM
        mp3file = new MP3File();
        id3v1 = new ID3v1_1();
        id3v2 = new ID3v2_4();
        lyrics3 = new Lyrics3v2();
        filename = FilenameTagBuilder.createEmptyFilenameTag();
        frame = new ID3v2_4Frame(new FrameBodyCOMM((byte) 0, "ENG", "", testString));
        id3v1.setComment(testString);
        id3v2.setFrame(frame);
        try {
            ((Lyrics3v2) lyrics3).setField(new Lyrics3v2Field(frame));
        } catch (TagException ex) {
            fail("This should not happen. " + ex.getMessage());
        }
        filename.setFrame(frame);
        mp3file.setID3v1Tag(id3v1);
        mp3file.setID3v2Tag(id3v2);
        mp3file.setLyrics3Tag(lyrics3);
        mp3file.setFilenameTag(filename);
        frameList = mp3file.getFrameAcrossTags("COMM");
        assertEquals(4, frameList.size());
        for (int i = 0; i < frameList.size(); i++) {
            assertEquals(frame, frameList.get(i));
        }

        // TCON
        mp3file = new MP3File();
        id3v1 = new ID3v1_1();
        id3v2 = new ID3v2_4();
        lyrics3 = new Lyrics3v2();
        filename = FilenameTagBuilder.createEmptyFilenameTag();
        frame = new ID3v2_4Frame(new FrameBodyTCON((byte) 0, "(42) Soul"));
        id3v1.setGenre((byte) 42);
        id3v2.setFrame(frame);
        try {
            ((Lyrics3v2) lyrics3).setField(new Lyrics3v2Field(frame));
            fail("Somehow created a TCON (genre) Lyrics3v2 Field");
        } catch (TagException ex) {
            // correct behavior
        }
        filename.setFrame(frame);
        mp3file.setID3v1Tag(id3v1);
        mp3file.setID3v2Tag(id3v2);
        mp3file.setLyrics3Tag(lyrics3);
        mp3file.setFilenameTag(filename);
        frameList = mp3file.getFrameAcrossTags("TCON");
        assertEquals(3, frameList.size());
        for (int i = 0; i < frameList.size(); i++) {
            assertEquals(frame, frameList.get(i));
        }

        // TRCK
        mp3file = new MP3File();
        id3v1 = new ID3v1_1();
        id3v2 = new ID3v2_4();
        lyrics3 = new Lyrics3v2();
        filename = FilenameTagBuilder.createEmptyFilenameTag();
        frame = new ID3v2_4Frame(new FrameBodyTRCK((byte) 0, "42"));
        ((ID3v1_1) id3v1).setTrack((byte) 42);
        id3v2.setFrame(frame);
        try {
            ((Lyrics3v2) lyrics3).setField(new Lyrics3v2Field(frame));
            fail("Somehow created a TRCK (track) Lyrics3v2 Field");
        } catch (TagException ex) {
            // correct behavior
        }
        filename.setFrame(frame);
        mp3file.setID3v1Tag(id3v1);
        mp3file.setID3v2Tag(id3v2);
        mp3file.setLyrics3Tag(lyrics3);
        mp3file.setFilenameTag(filename);
        frameList = mp3file.getFrameAcrossTags("TRCK");
        assertEquals(3, frameList.size());
        for (int i = 0; i < frameList.size(); i++) {
            assertEquals(frame, frameList.get(i));
        }

        // SYLT
        mp3file = new MP3File();
        id3v1 = new ID3v1_1();
        id3v2 = new ID3v2_4();
        lyrics3 = new Lyrics3v2();
        filename = FilenameTagBuilder.createEmptyFilenameTag();
        frame = new ID3v2_4Frame(new FrameBodySYLT((byte) 0, "ENG", (byte) 0, (byte) 0, "description"));
        ((FrameBodySYLT) frame.getBody()).addLyric(0, testString);
        id3v2.setFrame(frame);
        try {
            ((Lyrics3v2) lyrics3).setField(new Lyrics3v2Field(frame));
        } catch (TagException ex) {
            fail("This should not happen. " + ex.getMessage());
        }
        filename.setFrame(frame);
        mp3file.setID3v1Tag(id3v1);
        mp3file.setID3v2Tag(id3v2);
        mp3file.setLyrics3Tag(lyrics3);
        mp3file.setFilenameTag(filename);
        frameList = mp3file.getFrameAcrossTags("SYLT");
        assertEquals(3, frameList.size());
        for (int i = 0; i < frameList.size(); i++) {
            assertEquals(frame, frameList.get(i));
        }

        // USLT
        mp3file = new MP3File();
        id3v1 = new ID3v1_1();
        id3v2 = new ID3v2_4();
        lyrics3 = new Lyrics3v2();
        filename = FilenameTagBuilder.createEmptyFilenameTag();
        frame = new ID3v2_4Frame(new FrameBodyUSLT((byte) 0, "ENG", "", testString));
        id3v2.setFrame(frame);
        try {
            ((Lyrics3v2) lyrics3).setField(new Lyrics3v2Field(frame));
        } catch (TagException ex) {
            fail("This should not happen. " + ex.getMessage());
        }
        filename.setFrame(frame);
        mp3file.setID3v1Tag(id3v1);
        mp3file.setID3v2Tag(id3v2);
        mp3file.setLyrics3Tag(lyrics3);
        mp3file.setFilenameTag(filename);
        frameList = mp3file.getFrameAcrossTags("USLT");
        assertEquals(3, frameList.size());
        for (int i = 0; i < frameList.size(); i++) {
            assertEquals(frame, frameList.get(i));
        }

        // TCOM
        mp3file = new MP3File();
        id3v1 = new ID3v1_1();
        id3v2 = new ID3v2_4();
        lyrics3 = new Lyrics3v2();
        filename = FilenameTagBuilder.createEmptyFilenameTag();
        frame = new ID3v2_4Frame(new FrameBodyTCOM((byte) 0, testString));
        id3v2.setFrame(frame);
        try {
View Full Code Here

    /**
     * @throws Exception
     */
    public void testGetUnsynchronizedFragments() throws Exception {
        MP3File mp3 = new MP3File();
        ID3v2_4 id3v2 = new ID3v2_4();
        ID3v1 id3v1 = new ID3v1();
        Lyrics3v2 lyrics3 = new Lyrics3v2();
        String albumTitle = "<album title>";
        mp3.setID3v2Tag(id3v2);
        mp3.setID3v1Tag(id3v1);
        mp3.setLyrics3Tag(lyrics3);
        mp3.setMp3file(new File(albumTitle));
        FilenameTag filename = FilenameTagBuilder.createFilenameTagFromMP3File(mp3);
        mp3.setFilenameTag(filename);
        AbstractID3v2Frame frame;
        AbstractID3v2FrameBody body;

        // test nulls;
        assertEquals(0, mp3.getUnsynchronizedFragments().size());

        // test equals
        body = new FrameBodyTALB((byte) 0, albumTitle);
        frame = new ID3v2_4Frame(body);
        id3v2.setFrame(frame);
        assertEquals(0, mp3.getUnsynchronizedFragments().size());
        lyrics3.setField(new Lyrics3v2Field(frame));
        assertEquals(0, mp3.getUnsynchronizedFragments().size());
        id3v1.setAlbum(albumTitle);
        assertEquals(0, mp3.getUnsynchronizedFragments().size());
        filename.setFrame(frame);
        assertEquals(0, mp3.getUnsynchronizedFragments().size());

        // test differences
        body = new FrameBodyTIT2((byte) 0, "<song title>");
        frame = new ID3v2_4Frame();
        frame.setBody(body);
        filename.setFrame(frame);
        assertEquals(0, mp3.getUnsynchronizedFragments().size());
        id3v1.setTitle("different");
        assertEquals(1, mp3.getUnsynchronizedFragments().size());
        id3v1.setTitle("<song title>");
        assertEquals(0, mp3.getUnsynchronizedFragments().size());
        lyrics3.setField(new Lyrics3v2Field(new FieldBodyETT("different")));
        assertEquals(1, mp3.getUnsynchronizedFragments().size());
        lyrics3.setField(new Lyrics3v2Field(new FieldBodyETT("<song title>")));
        assertEquals(0, mp3.getUnsynchronizedFragments().size());
        body = new FrameBodyTIT2((byte) 0, "different");
        frame = new ID3v2_4Frame(body);
        id3v2.setFrame(frame);
        assertEquals(1, mp3.getUnsynchronizedFragments().size());

        // test two differences
        id3v1.setArtist("<song artist>");
        assertEquals(1, mp3.getUnsynchronizedFragments().size());
        body = new FrameBodyTPE1((byte) 0, "different");
        frame = new ID3v2_4Frame();
        frame.setBody(body);
        filename.setFrame(frame);
        assertEquals(2, mp3.getUnsynchronizedFragments().size());
        body = new FrameBodyTPE1((byte) 0, "<song artist>");
        frame = new ID3v2_4Frame();
        frame.setBody(body);
        filename.setFrame(frame);
        assertEquals(1, mp3.getUnsynchronizedFragments().size());
        lyrics3.setField(new Lyrics3v2Field(new FieldBodyEAR("different")));
        assertEquals(2, mp3.getUnsynchronizedFragments().size());
        lyrics3.setField(new Lyrics3v2Field(new FieldBodyEAR("<song artist>")));
        assertEquals(1, mp3.getUnsynchronizedFragments().size());
        body = new FrameBodyTPE1((byte) 0, "different");
        frame = new ID3v2_4Frame(body);
        id3v2.setFrame(frame);
        assertEquals(2, mp3.getUnsynchronizedFragments().size());
        body = new FrameBodyTPE1((byte) 0, "<song artist>");
        frame = new ID3v2_4Frame(body);
        id3v2.setFrame(frame);
        assertEquals(1, mp3.getUnsynchronizedFragments().size());
        mp3.getMp3file().delete();
    }
View Full Code Here

    public void testSave() throws Exception {
        String albumTitle = "Theme";
        String newAlbumTitle = "New alb title";
        TagOptionSingleton.getInstance().setDefaultSaveMode(TagConstant.MP3_FILE_SAVE_OVERWRITE);
        MP3File mp3file = this.testMusicArray[1];
        ID3v2_4 id3v2 = new ID3v2_4();
        ID3v2_4 filenameId3 = new ID3v2_4();
        ID3v1_1 id3v1 = new ID3v1_1();
        Lyrics3v2 lyrics3 = new Lyrics3v2();
        File renamedFile = new File(this.testMusicDirectory, newAlbumTitle + " - Fat Albert.mp3");
        assertNull(mp3file.getID3v1Tag());
        assertNull(mp3file.getID3v2Tag());
        assertNull(mp3file.getLyrics3Tag());
        assertEquals(0, (mp3file.getFilenameTag().getId3tag()).getFrameCount());

        // setup id3v1
        id3v1.setAlbum(albumTitle);

        // setup id3v2
        AbstractID3v2Frame frame;
        AbstractID3v2FrameBody frameBody;
        frameBody = new FrameBodyTALB((byte) 0, albumTitle);
        frame = new ID3v2_4Frame(frameBody);
        id3v2.setFrame(frame);

        // setup lyrics3v2
        Lyrics3v2Field field;
        AbstractLyrics3v2FieldBody fieldBody;
        fieldBody = new FieldBodyEAL(albumTitle);
        field = new Lyrics3v2Field(fieldBody);
        lyrics3.setField(field);

        // setup filename tag
        frameBody = new FrameBodyTALB((byte) 0, albumTitle);
        frame = new ID3v2_4Frame(frameBody);
        filenameId3.setFrame(frame);
        TagOptionSingleton.getInstance().setFilenameTagSave(true);

        // nulls
        mp3file.save();
        mp3file = new MP3File(mp3file.getMp3file());
        assertNull(mp3file.getID3v1Tag());
        assertNull(mp3file.getID3v2Tag());
        assertNull(mp3file.getLyrics3Tag());
        assertEquals(0, (mp3file.getFilenameTag().getId3tag()).getFrameCount());

        // save one at a time
        // id3v1
        mp3file.setID3v1Tag(id3v1);
        mp3file.setID3v2Tag(null);
        mp3file.setLyrics3Tag(null);
        mp3file.setFilenameTag(null);
        mp3file.save();
        mp3file = new MP3File(mp3file.getMp3file());
        assertTrue(mp3file.getID3v1Tag().equals(id3v1));
        assertNull(mp3file.getID3v2Tag());
        assertNull(mp3file.getLyrics3Tag());
        assertEquals(1, (mp3file.getFilenameTag().getId3tag()).getFrameCount());
        tearDown();
        setUp();
        mp3file = this.testMusicArray[1];
        ((FrameBodyTALB) filenameId3.getFrame("TALB").getBody()).setText(albumTitle);

        // id3v2
        mp3file.setID3v1Tag(null);
        mp3file.setID3v2Tag(id3v2);
        mp3file.setLyrics3Tag(null);
        mp3file.setFilenameTag(null);
        mp3file.save();
        mp3file = new MP3File(mp3file.getMp3file());
        assertNull(mp3file.getID3v1Tag());
        assertTrue(mp3file.getID3v2Tag().equals(id3v2));
        assertNull(mp3file.getLyrics3Tag());
        assertEquals(1, (mp3file.getFilenameTag().getId3tag()).getFrameCount());
        tearDown();
        setUp();
        mp3file = this.testMusicArray[1];
        ((FrameBodyTALB) filenameId3.getFrame("TALB").getBody()).setText(albumTitle);

        // lyrics3
        mp3file.setID3v1Tag(null);
        mp3file.setID3v2Tag(null);
        mp3file.setLyrics3Tag(lyrics3);
        mp3file.setFilenameTag(null);
        mp3file.save();
        mp3file = new MP3File(mp3file.getMp3file());
        assertNull(mp3file.getID3v1Tag());
        assertNull(mp3file.getID3v2Tag());
        assertTrue(mp3file.getLyrics3Tag().equals(lyrics3));
        assertEquals(1, (mp3file.getFilenameTag().getId3tag()).getFrameCount());
        tearDown();
        setUp();
        mp3file = this.testMusicArray[1];
        ((FrameBodyTALB) filenameId3.getFrame("TALB").getBody()).setText(albumTitle);

        // filename tag
        mp3file.setID3v1Tag(null);
        mp3file.setID3v2Tag(null);
        mp3file.setLyrics3Tag(null);
        mp3file.getFilenameTag().setId3tag(filenameId3);
        ((FrameBodyTALB) filenameId3.getFrame("TALB").getBody()).setText(newAlbumTitle);
        mp3file.getFilenameTag().setId3tag(filenameId3);
        try {
            mp3file.save();
        } catch (TagException ex) {
            if ((ex.getMessage().startsWith("Unable to delete original file:") == false) &&
                (ex.getMessage().startsWith("Unable to rename file:") == false)) {
                throw ex;
            }

            // handle this exception for now.
            // @todo fix this
        }
        assertTrue(renamedFile.exists());
        mp3file = new MP3File(renamedFile);
        assertNull(mp3file.getID3v1Tag());
        assertNull(mp3file.getID3v2Tag());
        assertNull(mp3file.getLyrics3Tag());
        assertEquals(0, (mp3file.getFilenameTag().getId3tag()).getFrameCount());

        // save two at a time
        tearDown();
        setUp();
        mp3file = this.testMusicArray[1];
        ((FrameBodyTALB) filenameId3.getFrame("TALB").getBody()).setText(albumTitle);

        // id3v1 & id3v2
        mp3file.setID3v1Tag(id3v1);
        mp3file.setID3v2Tag(id3v2);
        mp3file.setLyrics3Tag(null);
        mp3file.setFilenameTag(null);
        mp3file.save();
        mp3file = new MP3File(mp3file.getMp3file());
        assertTrue(mp3file.getID3v1Tag().equals(id3v1));
        assertTrue(mp3file.getID3v2Tag().equals(id3v2));
        assertNull(mp3file.getLyrics3Tag());
        assertEquals(1, (mp3file.getFilenameTag().getId3tag()).getFrameCount());
        tearDown();
        setUp();
        mp3file = this.testMusicArray[1];
        ((FrameBodyTALB) filenameId3.getFrame("TALB").getBody()).setText(albumTitle);

        // id3v1 & lyrics3
        mp3file.setID3v1Tag(id3v1);
        mp3file.setID3v2Tag(null);
        mp3file.setLyrics3Tag(lyrics3);
        mp3file.setFilenameTag(null);
        mp3file.save();
        mp3file = new MP3File(mp3file.getMp3file());
        assertTrue(mp3file.getID3v1Tag().equals(id3v1));
        assertNull(mp3file.getID3v2Tag());
        assertTrue(mp3file.getLyrics3Tag().equals(lyrics3));
        assertEquals(1, (mp3file.getFilenameTag().getId3tag()).getFrameCount());
        tearDown();
        setUp();
        mp3file = this.testMusicArray[1];
        ((FrameBodyTALB) filenameId3.getFrame("TALB").getBody()).setText(albumTitle);

        // id3v1 & filename
        mp3file.setID3v1Tag(id3v1);
        mp3file.setID3v2Tag(null);
        mp3file.setLyrics3Tag(null);
        mp3file.getFilenameTag().setId3tag(filenameId3);
        ((FrameBodyTALB) filenameId3.getFrame("TALB").getBody()).setText(newAlbumTitle);
        mp3file.getFilenameTag().setId3tag(filenameId3);
        try {
            mp3file.save();
        } catch (TagException ex) {
            if ((ex.getMessage().startsWith("Unable to delete original file:") == false) &&
                (ex.getMessage().startsWith("Unable to rename file:") == false)) {
                throw ex;
            }

            // handle this exception for now.
            // @todo fix this
        }
        assertTrue(renamedFile.exists());
        mp3file = new MP3File(renamedFile);
        assertTrue(mp3file.getID3v1Tag().equals(id3v1));
        assertNull(mp3file.getID3v2Tag());
        assertNull(mp3file.getLyrics3Tag());
        assertEquals(0, (mp3file.getFilenameTag().getId3tag()).getFrameCount());
        tearDown();
        setUp();
        mp3file = this.testMusicArray[1];
        ((FrameBodyTALB) filenameId3.getFrame("TALB").getBody()).setText(albumTitle);

        // id3v2 & lyrics3
        mp3file.setID3v1Tag(null);
        mp3file.setID3v2Tag(id3v2);
        mp3file.setLyrics3Tag(lyrics3);
        mp3file.setFilenameTag(null);
        mp3file.save();
        mp3file = new MP3File(mp3file.getMp3file());
        assertNull(mp3file.getID3v1Tag());
        assertTrue(mp3file.getID3v2Tag().equals(id3v2));
        assertTrue(mp3file.getLyrics3Tag().equals(lyrics3));
        assertEquals(1, (mp3file.getFilenameTag().getId3tag()).getFrameCount());
        tearDown();
        setUp();
        mp3file = this.testMusicArray[1];
        ((FrameBodyTALB) filenameId3.getFrame("TALB").getBody()).setText(albumTitle);

        // id3v2 & filename
        mp3file.setID3v1Tag(null);
        mp3file.setID3v2Tag(id3v2);
        mp3file.setLyrics3Tag(null);
        mp3file.getFilenameTag().setId3tag(filenameId3);
        ((FrameBodyTALB) filenameId3.getFrame("TALB").getBody()).setText(newAlbumTitle);
        mp3file.getFilenameTag().setId3tag(filenameId3);
        try {
            mp3file.save();
        } catch (TagException ex) {
            if ((ex.getMessage().startsWith("Unable to delete original file:") == false) &&
                (ex.getMessage().startsWith("Unable to rename file:") == false)) {
                throw ex;
            }

            // handle this exception for now.
            // @todo fix this
        }
        assertTrue(renamedFile.exists());
        mp3file = new MP3File(renamedFile);
        assertNull(mp3file.getID3v1Tag());
        assertTrue(mp3file.getID3v2Tag().equals(id3v2));
        assertNull(mp3file.getLyrics3Tag());
        assertEquals(0, (mp3file.getFilenameTag().getId3tag()).getFrameCount());
        tearDown();
        setUp();
        mp3file = this.testMusicArray[1];
        ((FrameBodyTALB) filenameId3.getFrame("TALB").getBody()).setText(albumTitle);

        // lyrics3 & filename
        mp3file.setID3v1Tag(null);
        mp3file.setID3v2Tag(null);
        mp3file.setLyrics3Tag(lyrics3);
        mp3file.getFilenameTag().setId3tag(filenameId3);
        ((FrameBodyTALB) filenameId3.getFrame("TALB").getBody()).setText(newAlbumTitle);
        mp3file.getFilenameTag().setId3tag(filenameId3);
        try {
            mp3file.save();
        } catch (TagException ex) {
            if ((ex.getMessage().startsWith("Unable to delete original file:") == false) &&
                (ex.getMessage().startsWith("Unable to rename file:") == false)) {
                throw ex;
            }

            // handle this exception for now.
            // @todo fix this
        }
        assertTrue(renamedFile.exists());
        mp3file = new MP3File(renamedFile);
        assertNull(mp3file.getID3v1Tag());
        assertNull(mp3file.getID3v2Tag());
        assertTrue(mp3file.getLyrics3Tag().equals(lyrics3));
        assertEquals(0, (mp3file.getFilenameTag().getId3tag()).getFrameCount());
        assertTrue(renamedFile.delete());
        tearDown();
        setUp();
        mp3file = this.testMusicArray[1];
        ((FrameBodyTALB) filenameId3.getFrame("TALB").getBody()).setText(albumTitle);

        // id3v1 & id3v2 & lyrics3
        mp3file.setID3v1Tag(id3v1);
        mp3file.setID3v2Tag(id3v2);
        mp3file.setLyrics3Tag(lyrics3);
        mp3file.setFilenameTag(null);
        mp3file.save();
        mp3file = new MP3File(mp3file.getMp3file());
        assertTrue(mp3file.getID3v1Tag().equals(id3v1));
        assertTrue(mp3file.getID3v2Tag().equals(id3v2));
        assertTrue(mp3file.getLyrics3Tag().equals(lyrics3));
        assertEquals(1, (mp3file.getFilenameTag().getId3tag()).getFrameCount());
        tearDown();
        setUp();
        mp3file = this.testMusicArray[1];
        ((FrameBodyTALB) filenameId3.getFrame("TALB").getBody()).setText(albumTitle);

        // id3v1 & id3v2 & filename
        mp3file.setID3v1Tag(id3v1);
        mp3file.setID3v2Tag(id3v2);
        mp3file.setLyrics3Tag(null);
        mp3file.getFilenameTag().setId3tag(filenameId3);
        ((FrameBodyTALB) filenameId3.getFrame("TALB").getBody()).setText(newAlbumTitle);
        mp3file.getFilenameTag().setId3tag(filenameId3);
        try {
            mp3file.save();
        } catch (TagException ex) {
            if ((ex.getMessage().startsWith("Unable to delete original file:") == false) &&
                (ex.getMessage().startsWith("Unable to rename file:") == false)) {
                throw ex;
            }

            // handle this exception for now.
            // @todo fix this
        }
        assertTrue(renamedFile.exists());
        mp3file = new MP3File(renamedFile);
        assertTrue(mp3file.getID3v1Tag().equals(id3v1));
        assertTrue(mp3file.getID3v2Tag().equals(id3v2));
        assertNull(mp3file.getLyrics3Tag());
        assertEquals(0, (mp3file.getFilenameTag().getId3tag()).getFrameCount());
        tearDown();
        setUp();
        mp3file = this.testMusicArray[1];
        ((FrameBodyTALB) filenameId3.getFrame("TALB").getBody()).setText(albumTitle);

        // id3v1 & lyrics3 & filename
        mp3file.setID3v1Tag(id3v1);
        mp3file.setID3v2Tag(null);
        mp3file.setLyrics3Tag(lyrics3);
        mp3file.getFilenameTag().setId3tag(filenameId3);
        ((FrameBodyTALB) filenameId3.getFrame("TALB").getBody()).setText(newAlbumTitle);
        mp3file.getFilenameTag().setId3tag(filenameId3);
        try {
            mp3file.save();
        } catch (TagException ex) {
            if ((ex.getMessage().startsWith("Unable to delete original file:") == false) &&
                (ex.getMessage().startsWith("Unable to rename file:") == false)) {
                throw ex;
            }

            // handle this exception for now.
            // @todo fix this
        }
        assertTrue(renamedFile.exists());
        mp3file = new MP3File(renamedFile);
        assertTrue(mp3file.getID3v1Tag().equals(id3v1));
        assertNull(mp3file.getID3v2Tag());
        assertTrue(mp3file.getLyrics3Tag().equals(lyrics3));
        assertEquals(0, (mp3file.getFilenameTag().getId3tag()).getFrameCount());
        tearDown();
        setUp();
        mp3file = this.testMusicArray[1];
        ((FrameBodyTALB) filenameId3.getFrame("TALB").getBody()).setText(albumTitle);

        // id3v2 & lyrics3 & filename
        mp3file.setID3v1Tag(null);
        mp3file.setID3v2Tag(id3v2);
        mp3file.setLyrics3Tag(lyrics3);
        mp3file.getFilenameTag().setId3tag(filenameId3);
        ((FrameBodyTALB) filenameId3.getFrame("TALB").getBody()).setText(newAlbumTitle);
        mp3file.getFilenameTag().setId3tag(filenameId3);
        try {
            mp3file.save();
        } catch (TagException ex) {
            if ((ex.getMessage().startsWith("Unable to delete original file:") == false) &&
                (ex.getMessage().startsWith("Unable to rename file:") == false)) {
                throw ex;
            }

            // handle this exception for now.
            // @todo fix this
        }
        assertTrue(renamedFile.exists());
        mp3file = new MP3File(renamedFile);
        assertNull(mp3file.getID3v1Tag());
        assertTrue(mp3file.getID3v2Tag().equals(id3v2));
        assertTrue(mp3file.getLyrics3Tag().equals(lyrics3));
        assertEquals(0, (mp3file.getFilenameTag().getId3tag()).getFrameCount());
        tearDown();
        setUp();
        mp3file = this.testMusicArray[1];
        ((FrameBodyTALB) filenameId3.getFrame("TALB").getBody()).setText(albumTitle);

        // id3v1 & id3v2 & lyrics3 & filename
        mp3file.setID3v1Tag(id3v1);
        mp3file.setID3v2Tag(id3v2);
        mp3file.setLyrics3Tag(lyrics3);
        mp3file.getFilenameTag().setId3tag(filenameId3);
        ((FrameBodyTALB) filenameId3.getFrame("TALB").getBody()).setText(newAlbumTitle);
        mp3file.getFilenameTag().setId3tag(filenameId3);
        try {
            mp3file.save();
        } catch (TagException ex) {
            if ((ex.getMessage().startsWith("Unable to delete original file:") == false) &&
View Full Code Here

        mp3file.getID3v1Tag().getAlbum().equals(testString);
        assertNull(mp3file.getID3v2Tag());
        assertNull(mp3file.getLyrics3Tag());
        assertNull(mp3file.getFilenameTag());
        mp3file.setID3v1Tag(null);
        mp3file.setID3v2Tag(new ID3v2_4());
        mp3file.setLyrics3Tag(null);
        mp3file.setFilenameTag(null);
        mp3file.setFrameAcrossTags(frame);
        assertNull(mp3file.getID3v1Tag());
        ((FrameBodyTALB) mp3file.getID3v2Tag().getFrame("TALB").getBody()).getText().equals(testString);
        assertNull(mp3file.getLyrics3Tag());
        assertNull(mp3file.getFilenameTag());
        mp3file.setID3v1Tag(null);
        mp3file.setID3v2Tag(null);
        mp3file.setLyrics3Tag(new Lyrics3v2());
        mp3file.setFilenameTag(null);
        mp3file.setFrameAcrossTags(frame);
        assertNull(mp3file.getID3v1Tag());
        assertNull(mp3file.getID3v2Tag());
        ((FieldBodyEAL) ((Lyrics3v2) mp3file.getLyrics3Tag()).getField("EAL").getBody()).getAlbum().equals(testString);
        assertNull(mp3file.getFilenameTag());
        mp3file.setID3v1Tag(null);
        mp3file.setID3v2Tag(null);
        mp3file.setLyrics3Tag(null);
        mp3file.setFilenameTag(FilenameTagBuilder.createEmptyFilenameTag());
        mp3file.setFrameAcrossTags(frame);
        assertNull(mp3file.getID3v1Tag());
        assertNull(mp3file.getID3v2Tag());
        assertNull(mp3file.getLyrics3Tag());
        ((FrameBodyTALB) mp3file.getFilenameTag().getFrame("TALB").getBody()).getText().equals(testString);
        mp3file.setID3v1Tag(new ID3v1_1());
        mp3file.setID3v2Tag(new ID3v2_4());
        mp3file.setLyrics3Tag(null);
        mp3file.setFilenameTag(null);
        mp3file.setFrameAcrossTags(frame);
        mp3file.getID3v1Tag().getAlbum().equals(testString);
        ((FrameBodyTALB) mp3file.getID3v2Tag().getFrame("TALB").getBody()).getText().equals(testString);
        assertNull(mp3file.getLyrics3Tag());
        assertNull(mp3file.getFilenameTag());
        mp3file.setID3v1Tag(new ID3v1_1());
        mp3file.setID3v2Tag(null);
        mp3file.setLyrics3Tag(new Lyrics3v2());
        mp3file.setFilenameTag(null);
        mp3file.setFrameAcrossTags(frame);
        mp3file.getID3v1Tag().getAlbum().equals(testString);
        assertNull(mp3file.getID3v2Tag());
        ((FieldBodyEAL) ((Lyrics3v2) mp3file.getLyrics3Tag()).getField("EAL").getBody()).getAlbum().equals(testString);
        assertNull(mp3file.getFilenameTag());
        mp3file.setID3v1Tag(new ID3v1_1());
        mp3file.setID3v2Tag(null);
        mp3file.setLyrics3Tag(null);
        mp3file.setFilenameTag(FilenameTagBuilder.createEmptyFilenameTag());
        mp3file.setFrameAcrossTags(frame);
        mp3file.getID3v1Tag().getAlbum().equals(testString);
        assertNull(mp3file.getID3v2Tag());
        assertNull(mp3file.getLyrics3Tag());
        ((FrameBodyTALB) mp3file.getFilenameTag().getFrame("TALB").getBody()).getText().equals(testString);
        mp3file.setID3v1Tag(null);
        mp3file.setID3v2Tag(new ID3v2_4());
        mp3file.setLyrics3Tag(new Lyrics3v2());
        mp3file.setFilenameTag(null);
        mp3file.setFrameAcrossTags(frame);
        assertNull(mp3file.getID3v1Tag());
        ((FrameBodyTALB) mp3file.getID3v2Tag().getFrame("TALB").getBody()).getText().equals(testString);
        ((FieldBodyEAL) ((Lyrics3v2) mp3file.getLyrics3Tag()).getField("EAL").getBody()).getAlbum().equals(testString);
        assertNull(mp3file.getFilenameTag());
        mp3file.setID3v1Tag(null);
        mp3file.setID3v2Tag(new ID3v2_4());
        mp3file.setLyrics3Tag(null);
        mp3file.setFilenameTag(FilenameTagBuilder.createEmptyFilenameTag());
        mp3file.setFrameAcrossTags(frame);
        assertNull(mp3file.getID3v1Tag());
        ((FrameBodyTALB) mp3file.getID3v2Tag().getFrame("TALB").getBody()).getText().equals(testString);
        assertNull(mp3file.getLyrics3Tag());
        ((FrameBodyTALB) mp3file.getFilenameTag().getFrame("TALB").getBody()).getText().equals(testString);
        mp3file.setID3v1Tag(null);
        mp3file.setID3v2Tag(null);
        mp3file.setLyrics3Tag(new Lyrics3v2());
        mp3file.setFilenameTag(FilenameTagBuilder.createEmptyFilenameTag());
        mp3file.setFrameAcrossTags(frame);
        assertNull(mp3file.getID3v1Tag());
        assertNull(mp3file.getID3v2Tag());
        ((FieldBodyEAL) ((Lyrics3v2) mp3file.getLyrics3Tag()).getField("EAL").getBody()).getAlbum().equals(testString);
        ((FrameBodyTALB) mp3file.getFilenameTag().getFrame("TALB").getBody()).getText().equals(testString);
        mp3file.setID3v1Tag(new ID3v1_1());
        mp3file.setID3v2Tag(new ID3v2_4());
        mp3file.setLyrics3Tag(new Lyrics3v2());
        mp3file.setFilenameTag(null);
        mp3file.setFrameAcrossTags(frame);
        mp3file.getID3v1Tag().getAlbum().equals(testString);
        ((FrameBodyTALB) mp3file.getID3v2Tag().getFrame("TALB").getBody()).getText().equals(testString);
        ((FieldBodyEAL) ((Lyrics3v2) mp3file.getLyrics3Tag()).getField("EAL").getBody()).getAlbum().equals(testString);
        assertNull(mp3file.getFilenameTag());
        mp3file.setID3v1Tag(new ID3v1_1());
        mp3file.setID3v2Tag(new ID3v2_4());
        mp3file.setLyrics3Tag(null);
        mp3file.setFilenameTag(FilenameTagBuilder.createEmptyFilenameTag());
        mp3file.setFrameAcrossTags(frame);
        mp3file.getID3v1Tag().getAlbum().equals(testString);
        ((FrameBodyTALB) mp3file.getID3v2Tag().getFrame("TALB").getBody()).getText().equals(testString);
        assertNull(mp3file.getLyrics3Tag());
        ((FrameBodyTALB) mp3file.getFilenameTag().getFrame("TALB").getBody()).getText().equals(testString);
        mp3file.setID3v1Tag(new ID3v1_1());
        mp3file.setID3v2Tag(null);
        mp3file.setLyrics3Tag(new Lyrics3v2());
        mp3file.setFilenameTag(FilenameTagBuilder.createEmptyFilenameTag());
        mp3file.setFrameAcrossTags(frame);
        mp3file.getID3v1Tag().getAlbum().equals(testString);
        assertNull(mp3file.getID3v2Tag());
        ((FieldBodyEAL) ((Lyrics3v2) mp3file.getLyrics3Tag()).getField("EAL").getBody()).getAlbum().equals(testString);
        ((FrameBodyTALB) mp3file.getFilenameTag().getFrame("TALB").getBody()).getText().equals(testString);
        mp3file.setID3v1Tag(null);
        mp3file.setID3v2Tag(new ID3v2_4());
        mp3file.setLyrics3Tag(new Lyrics3v2());
        mp3file.setFilenameTag(FilenameTagBuilder.createEmptyFilenameTag());
        mp3file.setFrameAcrossTags(frame);
        assertNull(mp3file.getID3v1Tag());
        ((FrameBodyTALB) mp3file.getID3v2Tag().getFrame("TALB").getBody()).getText().equals(testString);
        ((FieldBodyEAL) ((Lyrics3v2) mp3file.getLyrics3Tag()).getField("EAL").getBody()).getAlbum().equals(testString);
        ((FrameBodyTALB) mp3file.getFilenameTag().getFrame("TALB").getBody()).getText().equals(testString);

        // test all
        mp3file.setID3v1Tag(new ID3v1_1());
        mp3file.setID3v2Tag(new ID3v2_4());
        mp3file.setLyrics3Tag(new Lyrics3v2());
        mp3file.setFilenameTag(FilenameTagBuilder.createEmptyFilenameTag());
        frameBody = new FrameBodyTIT2();
        ((FrameBodyTIT2) frameBody).setText(testString);
        frame.setBody(frameBody);
        mp3file.setFrameAcrossTags(frame);
        mp3file.getID3v1Tag().getTitle().equals(testString);
        ((FrameBodyTIT2) mp3file.getID3v2Tag().getFrame("TIT2").getBody()).getText().equals(testString);
        ((FieldBodyETT) ((Lyrics3v2) mp3file.getLyrics3Tag()).getField("ETT").getBody()).getTitle().equals(testString);
        ((FrameBodyTIT2) mp3file.getFilenameTag().getFrame("TIT2").getBody()).getText().equals(testString);
        mp3file.setID3v1Tag(new ID3v1_1());
        mp3file.setID3v2Tag(new ID3v2_4());
        mp3file.setLyrics3Tag(new Lyrics3v2());
        mp3file.setFilenameTag(FilenameTagBuilder.createEmptyFilenameTag());
        frameBody = new FrameBodyTPE1();
        ((FrameBodyTPE1) frameBody).setText(testString);
        frame.setBody(frameBody);
        mp3file.setFrameAcrossTags(frame);
        mp3file.getID3v1Tag().getArtist().equals(testString);
        ((FrameBodyTPE1) mp3file.getID3v2Tag().getFrame("TPE1").getBody()).getText().equals(testString);
        ((FieldBodyEAR) ((Lyrics3v2) mp3file.getLyrics3Tag()).getField("EAR").getBody()).getArtist().equals(testString);
        ((FrameBodyTPE1) mp3file.getFilenameTag().getFrame("TPE1").getBody()).getText().equals(testString);
        mp3file.setID3v1Tag(new ID3v1_1());
        mp3file.setID3v2Tag(new ID3v2_4());
        mp3file.setLyrics3Tag(new Lyrics3v2());
        mp3file.setFilenameTag(FilenameTagBuilder.createEmptyFilenameTag());
        frameBody = new FrameBodyTALB();
        ((FrameBodyTALB) frameBody).setText(testString);
        frame.setBody(frameBody);
        mp3file.setFrameAcrossTags(frame);
        mp3file.getID3v1Tag().getAlbum().equals(testString);
        ((FrameBodyTALB) mp3file.getID3v2Tag().getFrame("TALB").getBody()).getText().equals(testString);
        ((FieldBodyEAL) ((Lyrics3v2) mp3file.getLyrics3Tag()).getField("EAL").getBody()).getAlbum().equals(testString);
        ((FrameBodyTALB) mp3file.getFilenameTag().getFrame("TALB").getBody()).getText().equals(testString);
        mp3file.setID3v1Tag(new ID3v1_1());
        mp3file.setID3v2Tag(new ID3v2_4());
        mp3file.setLyrics3Tag(new Lyrics3v2());
        mp3file.setFilenameTag(FilenameTagBuilder.createEmptyFilenameTag());
        frameBody = new FrameBodyTDRC();
        ((FrameBodyTDRC) frameBody).setText("2003");
        frame.setBody(frameBody);
        mp3file.setFrameAcrossTags(frame);
        mp3file.getID3v1Tag().getYear().equals("2003");
        ((FrameBodyTDRC) mp3file.getID3v2Tag().getFrame("TDRC").getBody()).getText().equals("2003");
        assertEquals(0, ((Lyrics3v2) mp3file.getLyrics3Tag()).getFieldCount());
        ((FrameBodyTDRC) mp3file.getFilenameTag().getFrame("TDRC").getBody()).getText().equals("2003");
        mp3file.setID3v1Tag(new ID3v1_1());
        mp3file.setID3v2Tag(new ID3v2_4());
        mp3file.setLyrics3Tag(new Lyrics3v2());
        mp3file.setFilenameTag(FilenameTagBuilder.createEmptyFilenameTag());
        frameBody = new FrameBodyCOMM();
        ((FrameBodyCOMM) frameBody).setText(testString);
        frame.setBody(frameBody);
        mp3file.setFrameAcrossTags(frame);
        mp3file.getID3v1Tag().getComment().equals(testString);
        ((FrameBodyCOMM) ((ID3v2_4Frame) mp3file.getID3v2Tag().getFrameOfType("COMM").next()).getBody()).getText()
                .equals(testString);
        ((FieldBodyINF) ((Lyrics3v2) mp3file.getLyrics3Tag()).getField("INF").getBody()).getAdditionalInformation()
                .equals(testString);
        ((FrameBodyCOMM) ((ID3v2_4Frame) mp3file.getFilenameTag().getFrameOfType("COMM").next()).getBody()).getText()
                .equals(testString);
        mp3file.setID3v1Tag(new ID3v1_1());
        mp3file.setID3v2Tag(new ID3v2_4());
        mp3file.setLyrics3Tag(new Lyrics3v2());
        mp3file.setFilenameTag(FilenameTagBuilder.createEmptyFilenameTag());
        frameBody = new FrameBodyTCON();
        ((FrameBodyTCON) frameBody).setText("42");
        frame.setBody(frameBody);
        mp3file.setFrameAcrossTags(frame);
        assertEquals(42, mp3file.getID3v1Tag().getGenre());
        ((FrameBodyTCON) mp3file.getID3v2Tag().getFrame("TCON").getBody()).getText().equals("42");
        assertEquals(0, ((Lyrics3v2) mp3file.getLyrics3Tag()).getFieldCount());
        ((FrameBodyTCON) mp3file.getFilenameTag().getFrame("TCON").getBody()).getText().equals("42");
        mp3file.setID3v1Tag(new ID3v1_1());
        mp3file.setID3v2Tag(new ID3v2_4());
        mp3file.setLyrics3Tag(new Lyrics3v2());
        mp3file.setFilenameTag(FilenameTagBuilder.createEmptyFilenameTag());
        frameBody = new FrameBodyTRCK();
        ((FrameBodyTRCK) frameBody).setText("42");
        frame.setBody(frameBody);
        mp3file.setFrameAcrossTags(frame);
        assertEquals(42, ((ID3v1_1) mp3file.getID3v1Tag()).getTrack());
        ((FrameBodyTRCK) mp3file.getID3v2Tag().getFrame("TRCK").getBody()).getText().equals("42");
        assertEquals(0, ((Lyrics3v2) mp3file.getLyrics3Tag()).getFieldCount());
        ((FrameBodyTRCK) mp3file.getFilenameTag().getFrame("TRCK").getBody()).getText().equals("42");
        mp3file.setID3v1Tag(new ID3v1_1());
        mp3file.setID3v2Tag(new ID3v2_4());
        mp3file.setLyrics3Tag(new Lyrics3v2());
        mp3file.setFilenameTag(FilenameTagBuilder.createEmptyFilenameTag());
        frameBody = new FrameBodySYLT();
        ((FrameBodySYLT) frameBody).addLyric(0, testString);
        frame.setBody(frameBody);
        mp3file.setFrameAcrossTags(frame);
        assertEquals(0, (new ID3v2_4(mp3file.getID3v1Tag())).getFrameCount());
        ((FrameBodySYLT) mp3file.getID3v2Tag().getFrame("SYLT").getBody()).getLyric().equals(testString);
        ((FieldBodyLYR) ((Lyrics3v2) mp3file.getLyrics3Tag()).getField("LYR").getBody()).getLyric().equals(testString);
        ((FrameBodySYLT) mp3file.getFilenameTag().getFrame("SYLT").getBody()).getLyric().equals(testString);
        mp3file.setID3v1Tag(new ID3v1_1());
        mp3file.setID3v2Tag(new ID3v2_4());
        mp3file.setLyrics3Tag(new Lyrics3v2());
        mp3file.setFilenameTag(FilenameTagBuilder.createEmptyFilenameTag());
        frameBody = new FrameBodyUSLT();
        ((FrameBodyUSLT) frameBody).setLyric(testString);
        frame.setBody(frameBody);
        mp3file.setFrameAcrossTags(frame);
        assertEquals(0, (new ID3v2_4(mp3file.getID3v1Tag())).getFrameCount());
        ((FrameBodyUSLT) ((ID3v2_4Frame) mp3file.getID3v2Tag().getFrameOfType("USLT").next()).getBody()).getLyric()
                .equals(testString);
        ((FieldBodyLYR) ((Lyrics3v2) mp3file.getLyrics3Tag()).getField("LYR").getBody()).getLyric().equals(testString);
        ((FrameBodyUSLT) ((ID3v2_4Frame) mp3file.getFilenameTag().getFrameOfType("USLT").next()).getBody()).getLyric()
                .equals(testString);
        mp3file.setID3v1Tag(new ID3v1_1());
        mp3file.setID3v2Tag(new ID3v2_4());
        mp3file.setLyrics3Tag(new Lyrics3v2());
        mp3file.setFilenameTag(FilenameTagBuilder.createEmptyFilenameTag());
        frameBody = new FrameBodyTCOM();
        ((FrameBodyTCOM) frameBody).setText(testString);
        frame.setBody(frameBody);
View Full Code Here

            }
        } catch (TagNotFoundException ex) {
            // ok if it's null
        }
        try {
            id3v2tag = new ID3v2_4(newFile);
        } catch (TagNotFoundException ex) {
            // maybe different version
        }
        try {
            if (id3v2tag == null) {
View Full Code Here

     * @param frame frame to set / replace in all four tags.
     */
    //todo this method is very inefficient.
    public void setFrameAcrossTags(final AbstractID3v2Frame frame) {
        if (id3v1tag != null) {
            final ID3v2_4 id3v1 = new ID3v2_4(id3v1tag);
            id3v1.setFrame(frame);
            id3v1tag.overwrite(id3v1);
        }
        if (id3v2tag != null) {
            id3v2tag.setFrame(frame);
        }
        if (lyrics3tag != null) {
            final ID3v2_4 lyrics3 = new ID3v2_4(lyrics3tag);
            lyrics3.setFrame(frame);
            lyrics3tag = new Lyrics3v2(lyrics3);
        }
        if (filenameTag != null) {
            filenameTag.setFrame(frame);
        }
View Full Code Here

TOP

Related Classes of org.farng.mp3.id3.FrameBodyTPE4

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.