Package helliker.id3

Examples of helliker.id3.MP3File


    this.testID3v2Genre("(13)", "Pop");
  }

  private void testID3v1Genre(String input, String expectedOutput) throws ID3TagFileException {
    ID3v1 id3Mock = EasyMock.createMock(ID3v1.class);
    MP3File mp3FileMock = TagTestHelpLibrary.createMP3FileMockForID3v1(id3Mock);

    EasyMock.expect(id3Mock.getSongGenre()).andReturn(input);
    EasyMock.replay(id3Mock, mp3FileMock);

    ID3Tag tag = jidID3TagFactory.getID3Tag(mp3FileMock);
View Full Code Here


    EasyMock.verify(id3Mock, mp3FileMock);
  }
 
  private void testID3v2Genre(String input, String expectedOutput) throws ID3TagFileException {
    AbstractID3v2 id3Mock = EasyMock.createMock(AbstractID3v2.class);
    MP3File mp3FileMock = TagTestHelpLibrary.createMP3FileMockForID3v2(id3Mock);

    EasyMock.expect(id3Mock.getSongGenre()).andReturn(input);
    EasyMock.replay(id3Mock, mp3FileMock);

    ID3Tag tag = jidID3TagFactory.getID3Tag(mp3FileMock);
View Full Code Here

    jidID3TagFactory.getID3Tag(fileMock);
  }
 
  @Test
  public void ID3v1Test() throws ID3TagFileException{
    MP3File mp3FileMock = TagTestHelpLibrary.createMP3FileMockForID3v1(null);
    EasyMock.replay(mp3FileMock);
   
    ID3Tag id3Tag = jidID3TagFactory.getID3Tag(mp3FileMock);
 
    assertTrue(id3Tag.getClass().equals(ID3v1TagImpl.class));
View Full Code Here

    EasyMock.verify(mp3FileMock);
  }
 
  @Test
  public void ID3v2Test() throws ID3TagFileException{
    MP3File mp3FileMock = TagTestHelpLibrary.createMP3FileMockForID3v2(null);
    EasyMock.replay(mp3FileMock);
   
    ID3Tag id3Tag = jidID3TagFactory.getID3Tag(mp3FileMock);
 
    assertTrue(id3Tag.getClass().equals(ID3v2TagImpl.class));
View Full Code Here

    if (isM4A(file)) {
      throw new ID3M4AException(file);
    }

    try {
      MP3File mp3File = new MP3File(file, NOT_WRITEABLE);
      return getID3Tag(mp3File);

    } catch (IOException e) {
      throw new ID3TagFileException(e, file);
    } catch (TagException e) {
View Full Code Here

   *       </ul>
   */
  public static String[] getIDTags(String file) {
    String[] ret = new String[3];
    try {
      MP3File mp3 = new MP3File(file);
      String mtitle = null, martist=null, malbum=null;
      if(mp3.hasID3v1Tag()) {
        mtitle = mp3.getID3v1Tag().getTitle();
        martist = mp3.getID3v1Tag().getArtist();
        malbum = mp3.getID3v1Tag().getAlbum();
      } else if(mp3.hasID3v2Tag()) {
        mtitle = mp3.getID3v2Tag().getSongTitle();
        martist = mp3.getID3v2Tag().getLeadArtist();
        malbum = mp3.getID3v2Tag().getAlbumTitle();
      }
      ret[0] = toUTF8(martist);
      ret[1] = toUTF8(malbum);
      ret[2] = toUTF8(mtitle);
    } catch (Exception e) {
View Full Code Here

  @Override
  public void prepare(RawDocument rawDocument) throws RegainException {

    File rawFile = rawDocument.getContentAsFile(false);
    try {
      MP3File mp3file = new MP3File(rawFile);
      ArrayList<String> info = new ArrayList<String>();

      if (mp3file.hasID3v2Tag()) {
        ID3v24Tag id3v24tag = mp3file.getID3v2TagAsv24();

        info.add(id3v24tag.getFirst(ID3v24Frames.FRAME_ID_ARTIST).trim());
        info.add(id3v24tag.getFirst(ID3v24Frames.FRAME_ID_ALBUM).trim());
        info.add(id3v24tag.getFirst(ID3v24Frames.FRAME_ID_TITLE).trim());
        try {
          int year = new Integer(id3v24tag.getFirst(ID3v24Frames.FRAME_ID_YEAR).trim()).intValue();
          if (year > 0) {
            info.add(id3v24tag.getFirst(ID3v24Frames.FRAME_ID_YEAR).trim());
          }
        } catch (Exception ex) {
        }
        info.add(mp3file.getMP3AudioHeader().getTrackLengthAsString().trim());
        info.add(mp3file.getMP3AudioHeader().getBitRate().trim() + "kbps");

        setCleanedContent(concatenateStringParts(info, Integer.MAX_VALUE));
        setTitle(concatenateStringParts(info, 2));

      } else if (mp3file.hasID3v1Tag()) {
        ID3v1Tag tag = mp3file.getID3v1Tag();

        info.add(tag.getFirst(FieldKey.ARTIST).trim());
        info.add(tag.getFirst(FieldKey.ALBUM).trim());
        info.add(tag.getFirst(FieldKey.TITLE).trim());
        try {
          int year = new Integer(tag.getFirst(FieldKey.YEAR).trim()).intValue();
          if (year > 0) {
            info.add(tag.getFirst(FieldKey.YEAR).trim());
          }
        } catch (Exception ex) {
        }
        info.add(mp3file.getMP3AudioHeader().getTrackLengthAsString().trim());
        info.add(mp3file.getMP3AudioHeader().getBitRate().trim() + "kbps");

        setCleanedContent(concatenateStringParts(info, Integer.MAX_VALUE));
        setTitle(concatenateStringParts(info, 2));

      } else {
View Full Code Here

    public void parse( final File file ) {

        try {

            MP3File f = (MP3File) AudioFileIO.read( file );
            if ( f.hasID3v2Tag() )
                parseID3v2Tag( f );
            if ( f.hasID3v1Tag() )
                parseID3v1Tag( f );

        } catch ( Exception e ) {
            log.error( "Error parsing MP3 tag: " + e.getMessage() );
        }
View Full Code Here

    public Track readSingle(Track track) {
      TrackData trackData = track.getTrackData();
        TextEncoding.getInstanceOf().setDefaultNonUnicode(defaultCharset.name());
        ID3Tag.setDefaultEncoding(defaultCharset.name());
        MP3File mp3File = null;
        try {
            mp3File = new MP3File(trackData.getFile(), MP3File.LOAD_ALL, true);
        } catch (Exception ignored) {
            System.out.println("Couldn't read file: " + trackData.getFile());
        }

        ID3v24Tag v24Tag = null;
        if (mp3File != null) {
            try {
                v24Tag = mp3File.getID3v2TagAsv24();
                if (v24Tag != null) {
                    copyCommonTagFields(v24Tag, track);
                    copySpecificTagFields(v24Tag, track);
                }

                ID3v1Tag id3v1Tag = mp3File.getID3v1Tag();
                if (id3v1Tag != null) {
                    copyCommonTagFields(id3v1Tag, track);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

            MP3AudioHeader mp3AudioHeader = mp3File.getMP3AudioHeader();
            copyHeaderFields(mp3AudioHeader, track);

            long totalSamples = trackData.getTotalSamples();
            int enc_delay = GAPLESS_DELAY;
View Full Code Here

                apeTagProcessor.writeAPEv2Tag(track);
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else {
            MP3File mp3File;
            try {
                mp3File = new MP3File(file, MP3File.LOAD_ALL, false);

                ID3v24Tag id3v2tag = mp3File.getID3v2TagAsv24();
                if (id3v2tag == null) {
                    id3v2tag = new ID3v24Tag();
                }
                copyTagFields(id3v2tag, track);

                ID3v11Tag id3v1Tag = new ID3v11Tag(id3v2tag);
                mp3File.setID3v1Tag(id3v1Tag);
                mp3File.setID3v2Tag(id3v2tag);

                mp3File.commit();
            } catch (Exception e) {
                throw new TagWriteException(e);
            }
        }
    }
View Full Code Here

TOP

Related Classes of helliker.id3.MP3File

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.