Package org.farng.mp3.id3

Examples of org.farng.mp3.id3.FrameBodyTPUB


    }

    public void setTrackNumberOnAlbum(String trackNumberOnAlbum) {
        AbstractID3v2Frame field = getFrame("TRCK");
        if (field == null) {
            field = new ID3v2_3Frame(new FrameBodyTRCK((byte) 0, trackNumberOnAlbum.trim()));
            setFrame(field);
        } else {
            ((FrameBodyTRCK) field.getBody()).setText(trackNumberOnAlbum.trim());
        }
    }
View Full Code Here


        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());
View Full Code Here

        ((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()
View Full Code Here

            text = body.getLyric();
        }
        if (text == null) {
            frame = getFrame("USLT");
            if (frame != null) {
                FrameBodyUSLT body = (FrameBodyUSLT) frame.getBody();
                text = body.getLyric();
            }
        }
        return text.trim();
    }
View Full Code Here

    }

    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

        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());
View Full Code Here

        }
    }

    private void precisaCriar() {
        //  if (mp3File.hasID3v1Tag()) {
        ID3v1 id = new ID3v1();
        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.setID3v1Tag(id);
        alterarMusica();
        try {
            mp3File.save(TagConstant.MP3_FILE_SAVE_APPEND);
            // }
View Full Code Here

     *
     */
    public void testGetFrameAcrossTags() {
        MP3File mp3file = this.testMusicArray[0];
        AbstractID3v2 id3v2 = mp3file.getID3v2Tag();
        ID3v1 id3v1 = mp3file.getID3v1Tag();
        AbstractLyrics3 lyrics3 = mp3file.getLyrics3Tag();
        FilenameTag filename = mp3file.getFilenameTag();
        AbstractID3v2Frame frame = id3v2.getFrame("TIT2");
        assertEquals(2, mp3file.getFrameAcrossTags("TIT2").size());
        assertNull(lyrics3);
        assertTrue(filename != null);
        assertFalse(filename.hasFrame("TIT2"));
        lyrics3 = new Lyrics3v2();
        try {
            ((Lyrics3v2) lyrics3).setField(new Lyrics3v2Field(frame));
        } catch (TagException ex) {
            fail(ex.getMessage());
        }
        mp3file.setLyrics3Tag(lyrics3);
        assertEquals(3, mp3file.getFrameAcrossTags("TIT2").size());
        filename.setFrame(frame);
        assertEquals(4, mp3file.getFrameAcrossTags("TIT2").size());
        mp3file.setFilenameTag(null);
        assertEquals(3, mp3file.getFrameAcrossTags("TIT2").size());
        mp3file.setID3v2Tag(null);
        assertEquals(2, mp3file.getFrameAcrossTags("TIT2").size());
        mp3file.setID3v1Tag(null);
        assertEquals(1, mp3file.getFrameAcrossTags("TIT2").size());
        mp3file.setLyrics3Tag(null);
        assertEquals(0, mp3file.getFrameAcrossTags("TIT2").size());

        // test nulls
        assertNull(mp3file.getFrameAcrossTags(null));
        assertNull(mp3file.getFrameAcrossTags(""));

        // test all different fields
        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) {
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);
View Full Code Here

  }

  private Parse getID3v1Parse(MP3File mp3, Metadata contentMeta)
  throws MalformedURLException {

    ID3v1 tag = mp3.getID3v1Tag();
    metadataCollector.notifyProperty("TALB-Text", tag.getAlbum());
    metadataCollector.notifyProperty("TPE1-Text", tag.getArtist());
    metadataCollector.notifyProperty("COMM-Text", tag.getComment());
    metadataCollector.notifyProperty("TCON-Text", "(" + tag.getGenre() + ")");
    metadataCollector.notifyProperty("TIT2-Text", tag.getTitle());
    metadataCollector.notifyProperty("TYER-Text", tag.getYear());
    ParseData parseData = new ParseData(ParseStatus.STATUS_SUCCESS,
                                        metadataCollector.getTitle(),
                                        metadataCollector.getOutlinks(),
                                        contentMeta,
                                        metadataCollector.getData());
View Full Code Here

TOP

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

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.