Search in sources :

Example 1 with VorbisCommentTag

use of org.jaudiotagger.tag.vorbiscomment.VorbisCommentTag in project MusicDNA by harjot-oberai.

the class FlacTagReader method read.

public FlacTag read(RandomAccessFile raf) throws CannotReadException, IOException {
    FlacStreamReader flacStream = new FlacStreamReader(raf);
    flacStream.findStream();
    //Hold the metadata
    VorbisCommentTag tag = null;
    List<MetadataBlockDataPicture> images = new ArrayList<MetadataBlockDataPicture>();
    //Seems like we have a valid stream
    boolean isLastBlock = false;
    while (!isLastBlock) {
        if (logger.isLoggable(Level.CONFIG)) {
            logger.config("Looking for MetaBlockHeader at:" + raf.getFilePointer());
        }
        //Read the header
        MetadataBlockHeader mbh = MetadataBlockHeader.readHeader(raf);
        if (mbh == null) {
            break;
        }
        if (logger.isLoggable(Level.CONFIG)) {
            logger.config("Reading MetadataBlockHeader:" + mbh.toString() + " ending at " + raf.getFilePointer());
        }
        //JAUDIOTAGGER-466:CBlocktype can be null
        if (mbh.getBlockType() != null) {
            switch(mbh.getBlockType()) {
                //We got a vorbiscomment comment block, parse it
                case VORBIS_COMMENT:
                    byte[] commentHeaderRawPacket = new byte[mbh.getDataLength()];
                    raf.read(commentHeaderRawPacket);
                    tag = vorbisCommentReader.read(commentHeaderRawPacket, false);
                    break;
                case PICTURE:
                    try {
                        MetadataBlockDataPicture mbdp = new MetadataBlockDataPicture(mbh, raf);
                        images.add(mbdp);
                    } catch (IOException ioe) {
                        logger.warning("Unable to read picture metablock, ignoring:" + ioe.getMessage());
                    } catch (InvalidFrameException ive) {
                        logger.warning("Unable to read picture metablock, ignoring" + ive.getMessage());
                    }
                    break;
                //This is not a metadata block we are interested in so we skip to next block
                default:
                    if (logger.isLoggable(Level.CONFIG)) {
                        logger.config("Ignoring MetadataBlock:" + mbh.getBlockType());
                    }
                    raf.seek(raf.getFilePointer() + mbh.getDataLength());
                    break;
            }
        }
        isLastBlock = mbh.isLastBlock();
        mbh = null;
    }
    //just initialize Flac with an empty VorbisTag
    if (tag == null) {
        tag = VorbisCommentTag.createNewTag();
    }
    FlacTag flacTag = new FlacTag(tag, images);
    return flacTag;
}
Also used : MetadataBlockHeader(org.jaudiotagger.audio.flac.metadatablock.MetadataBlockHeader) FlacTag(org.jaudiotagger.tag.flac.FlacTag) ArrayList(java.util.ArrayList) IOException(java.io.IOException) VorbisCommentTag(org.jaudiotagger.tag.vorbiscomment.VorbisCommentTag) InvalidFrameException(org.jaudiotagger.tag.InvalidFrameException) MetadataBlockDataPicture(org.jaudiotagger.audio.flac.metadatablock.MetadataBlockDataPicture)

Example 2 with VorbisCommentTag

use of org.jaudiotagger.tag.vorbiscomment.VorbisCommentTag in project MusicDNA by harjot-oberai.

the class OggVorbisTagReader method read.

/**
     * Read the Logical VorbisComment Tag from the file
     *
     * <p>Read the CommenyTag, within an OggVorbis file the VorbisCommentTag is mandatory
     *
     * @param raf
     * @return
     * @throws CannotReadException
     * @throws IOException
     */
public Tag read(RandomAccessFile raf) throws CannotReadException, IOException {
    logger.config("Starting to read ogg vorbis tag from file:");
    byte[] rawVorbisCommentData = readRawPacketData(raf);
    //Begin tag reading
    VorbisCommentTag tag = vorbisCommentReader.read(rawVorbisCommentData, true);
    logger.fine("CompletedReadCommentTag");
    return tag;
}
Also used : VorbisCommentTag(org.jaudiotagger.tag.vorbiscomment.VorbisCommentTag)

Example 3 with VorbisCommentTag

use of org.jaudiotagger.tag.vorbiscomment.VorbisCommentTag in project MusicDNA by harjot-oberai.

the class OggVorbisTagWriter method delete.

public void delete(RandomAccessFile raf, RandomAccessFile tempRaf) throws IOException, CannotReadException, CannotWriteException {
    try {
        reader.read(raf);
    } catch (CannotReadException e) {
        write(VorbisCommentTag.createNewTag(), raf, tempRaf);
        return;
    }
    VorbisCommentTag emptyTag = VorbisCommentTag.createNewTag();
    //Go back to start of file
    raf.seek(0);
    write(emptyTag, raf, tempRaf);
}
Also used : CannotReadException(org.jaudiotagger.audio.exceptions.CannotReadException) VorbisCommentTag(org.jaudiotagger.tag.vorbiscomment.VorbisCommentTag)

Aggregations

VorbisCommentTag (org.jaudiotagger.tag.vorbiscomment.VorbisCommentTag)3 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 CannotReadException (org.jaudiotagger.audio.exceptions.CannotReadException)1 MetadataBlockDataPicture (org.jaudiotagger.audio.flac.metadatablock.MetadataBlockDataPicture)1 MetadataBlockHeader (org.jaudiotagger.audio.flac.metadatablock.MetadataBlockHeader)1 InvalidFrameException (org.jaudiotagger.tag.InvalidFrameException)1 FlacTag (org.jaudiotagger.tag.flac.FlacTag)1