Package org.jaudiotagger.tag

Examples of org.jaudiotagger.tag.Tag


    }
   
    // Then update the file.
    try {
      AudioFile file;
      Tag tag;
           
      file = AudioFileIO.read(new File(fileName));
      tag = file.getTag();                   
         
      if (updateTrackNumber) { 
        try {
          tag.setTrack(trackNumber);
        } catch (Exception e) {
          String message = "Error while writting tracknumber: " + e.getMessage() + " (" + e.toString() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
          result.add(message);
          Log.getInstance(HSQLController.class).warn(message);
        }
      }
      if (updateTitle) {
        try {
          tag.setTitle(title);
        } catch (Exception e) {
          String message = "Error while writting title: " + e.getMessage() + " (" + e.toString() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
          result.add(message);
          Log.getInstance(HSQLController.class).warn(message);
        }
      }
      if (updateArtist) { 
        try {
          tag.setArtist(artist);
        } catch (Exception e) {
          String message = "Error while writting artist: " + e.getMessage() + " (" + e.toString() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
          result.add(message);
          Log.getInstance(HSQLController.class).warn(message);
        }
      }
      if (updateAlbum) {   
        try {
          tag.setAlbum(album);
        } catch (Exception e) {
          String message = "Error while writting album: " + e.getMessage() + " (" + e.toString() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
          result.add(message);
          Log.getInstance(HSQLController.class).warn(message);
        }
      }
      if (updateGenre) { 
        try {
          tag.setGenre(genre);
        } catch (Exception e) {
          String message = "Error while writting genre: " + e.getMessage() + " (" + e.toString() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
          result.add(message);
          Log.getInstance(HSQLController.class).warn(message);
        }
      }
      if (updateYear) {   
        try {
          tag.setYear(year);
        } catch (Exception e) {
          String message = "Error while writting year: " + e.getMessage() + " (" + e.toString() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
          result.add(message);
          Log.getInstance(HSQLController.class).warn(message);
        }
      }
      if (updateComment) {   
        try {
          tag.setComment(comment);
        } catch (Exception e) {
          String message = "Error while writting comment: " + e.getMessage() + " (" + e.toString() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
          result.add(message);
          Log.getInstance(HSQLController.class).warn(message);
        }
View Full Code Here


  public void addFiles(File[] files) {
    if (files != null && files.length > 0) {

      AudioFile audioFile;
      Tag tag;
      SongFile songFile;
      List<Expression> list = new ArrayList<Expression>(2);
      list.add(ExpressionFactory.matchExp(SongFile.FILENAME_PROPERTY,
               new ExpressionParameter("filename")));
      list.add(ExpressionFactory.matchExp(SongFile.PATH_PROPERTY,
               new ExpressionParameter("path")));
      Expression andExpression = ExpressionFactory.joinExp(Expression.AND, list);
      SelectQuery query = new SelectQuery(SongFile.class, andExpression);
      query.setFetchLimit(1);
      Map<String, String> args = new HashMap<String, String>();
      for (File file : files) {
        args.put("filename", file.getName());
        args.put("path", file.getParent());
       
        System.out.println(file.getAbsolutePath());
       
        SelectQuery queryWithParameters = query.queryWithParameters(args);
        System.out.println(queryWithParameters.toString());
       
        List<?> existingSongFiles = context.performQuery(queryWithParameters);
        if (existingSongFiles.isEmpty()) {
          songFile = context.newObject(SongFile.class);
         
          songFile.setFilename(file.getName());
          songFile.setPath(file.getParent());

          songFiles.add(songFile);
        }
        else {
          songFile = (SongFile) existingSongFiles.get(0);
        }
       
        try {
          audioFile = AudioFileIO.read(file);
         
          AudioHeader header = audioFile.getAudioHeader();
         
          songFile.setTrackLength(header.getTrackLength());
          songFile.setBitRate(header.getBitRate());
          songFile.setEncoding(header.getEncodingType());
         
          tag = audioFile.getTag();
          if (tag != null) {
            List<TagField> artistFields = tag.getFields(FieldKey.ARTIST);
            for (TagField artistField : artistFields) {
              System.out.println(artistField.toString());
            }
          }
        } catch (CannotReadException e) {
View Full Code Here

  public Tag getTagFromFile(File inputSong) throws CannotReadException, IOException, TagException, ReadOnlyFileException,
      InvalidAudioFrameException {

    if (!songTagCache.containsKey(inputSong)) {
      AudioFile song = AudioFileIO.read(inputSong);
      Tag songTag = song.getTag();
      songTagCache.put(inputSong, songTag);
    }

    return songTagCache.get(inputSong);
View Full Code Here

    }

    // HERE call the methods to generate the newName
    try {
      MetadataTagCache tagCache = MetadataTagCache.getInstance();
      Tag songTag = tagCache.getTagFromFile(file);

      for (MetadataTag tag : tagList.getTags()) {
        FieldKey key = tag.getFieldKey();
        // pull the values out, tack them on to the newName

        String value;
        // if the metadat is empty, or the tag key is null, use the
        // tag's default text
        if (key == null) {
          value = tag.getDefaultText();
        } else {
          value = songTag.getFirst(key);
          if (value.isEmpty()) {
            value = tag.getDefaultText();
          }
        }
View Full Code Here

            throws IOException
    {
        try
        {
            AudioFile f = AudioFileIO.read(file);
            Tag tag = f.getTag();
            if (tag == null)
            {
                tag = new ID3v24Tag();
            }
            tag.setField(FieldKey.ALBUM, track.getAlbum());
            tag.setField(FieldKey.ALBUM_ARTIST, track.getAlbumArtist());
            tag.setField(FieldKey.ARTIST, track.getArtist());
            tag.setField(FieldKey.COMPOSER, track.getComposer());
            tag.setField(FieldKey.DISC_NO,
                    String.valueOf(track.getDiscNumber()));
            tag.setField(FieldKey.DISC_TOTAL,
                    String.valueOf(track.getTotalDiscCount()));
            tag.setField(FieldKey.GENRE, track.getGenre());
            tag.setField(FieldKey.TITLE, track.getTitle());
            tag.setField(FieldKey.TRACK, String.valueOf(track.getTrackNumber()));
            tag.setField(FieldKey.TRACK_TOTAL,
                    String.valueOf(track.getTotalTrackCount()));
            tag.setField(FieldKey.YEAR, String.valueOf(track.getYear()));

            if (track.getAlbumArtRef() != null
                    && !track.getAlbumArtRef().isEmpty())
            {
                AlbumArtRef[] array = track.getAlbumArtRef().toArray(
                        new AlbumArtRef[track.getAlbumArtRef().size()]);
                for (int i = 0; i < array.length; i++)
                {
                    Artwork artwork = new Artwork();
                    File imageFile = new File(new File(".")
                            + System.getProperty("path.separator")
                            + track.getId() + ".im");
                    Files.write(Resources.toByteArray(array[i].getUrlAsURI()
                            .toURL()), imageFile);
                    artwork.setFromFile(imageFile);
                    tag.addField(artwork);

                    artwork.setFromFile(imageFile);
                    tag.addField(artwork);
                }
            }

            f.setTag(tag);
            AudioFileIO.write(f);
View Full Code Here

            throws IOException
    {
        try
        {
            AudioFile f = AudioFileIO.read(file);
            Tag tag = f.getTag();
            if (tag == null)
            {
                tag = new ID3v24Tag();
            }
            tag.setField(FieldKey.ALBUM, song.getAlbum());
            tag.setField(FieldKey.ALBUM_ARTIST, song.getAlbumArtist());
            tag.setField(FieldKey.ARTIST, song.getArtist());
            tag.setField(FieldKey.COMPOSER, song.getComposer());
            tag.setField(FieldKey.DISC_NO, String.valueOf(song.getDisc()));
            tag.setField(FieldKey.DISC_TOTAL,
                    String.valueOf(song.getTotalDiscs()));
            tag.setField(FieldKey.GENRE, song.getGenre());
            tag.setField(FieldKey.TITLE, song.getTitle());
            tag.setField(FieldKey.TRACK, String.valueOf(song.getTrack()));
            tag.setField(FieldKey.TRACK_TOTAL,
                    String.valueOf(song.getTotalTracks()));
            tag.setField(FieldKey.YEAR, String.valueOf(song.getYear()));

            if (song.getAlbumArtUrl() != null)
            {
                Artwork artwork = new Artwork();
                artwork.setBinaryData(Resources.toByteArray(song
                        .getAlbumArtUrlAsURI().toURL()));
                tag.addField(artwork);

                /*
                 * File imageFile = new File(new File(".") +
                 * System.getProperty("path.separator") + song.getId() + ".im");
                 * Files
 
View Full Code Here

              if (audio.getCodecA().contains("(windows media")) {
                audio.setCodecA(audio.getCodecA().substring(0, audio.getCodecA().indexOf("(windows media")).trim());
              }
            }

            Tag t = af.getTag();

            if (t != null) {
              if (t.getArtworkList().size() > 0) {
                thumb = t.getArtworkList().get(0).getBinaryData();
              } else {
                if (configuration.getAudioThumbnailMethod() > 0) {
                  thumb =
                    CoverUtil.get().getThumbnailFromArtistAlbum(
                      configuration.getAudioThumbnailMethod() == 1 ?
                        CoverUtil.AUDIO_AMAZON :
                        CoverUtil.AUDIO_DISCOGS,
                      audio.getArtist(), audio.getAlbum()
                    );
                }
              }

              if (!thumbOnly) {
                audio.setAlbum(t.getFirst(FieldKey.ALBUM));
                audio.setArtist(t.getFirst(FieldKey.ARTIST));
                audio.setSongname(t.getFirst(FieldKey.TITLE));
                String y = t.getFirst(FieldKey.YEAR);

                try {
                  if (y.length() > 4) {
                    y = y.substring(0, 4);
                  }
                  audio.setYear(Integer.parseInt(((y != null && y.length() > 0) ? y : "0")));
                  y = t.getFirst(FieldKey.TRACK);
                  audio.setTrack(Integer.parseInt(((y != null && y.length() > 0) ? y : "1")));
                  audio.setGenre(t.getFirst(FieldKey.GENRE));
                } catch (NumberFormatException | KeyNotFoundException e) {
                  LOGGER.debug("Error parsing unimportant metadata: " + e.getMessage());
                }
              }
            }
View Full Code Here

                writer.write(b);
            }
            writer.close();
            AudioFileIO.logger.getParent().setLevel(Level.OFF);
            AudioFile f = AudioFileIO.read(tmpFile);
            Tag tag = f.getTag();

            me = new Mp3Metadata();

            me.author = tag.getFirstArtist();
            me.album = tag.getFirstAlbum();
            me.title = tag.getFirstTitle();
            me.comment = tag.getFirstComment();
            me.year = tag.getFirstYear();

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (tmpFile != null) {
View Full Code Here

                fileOutputStream.write(b);
            }
            fileOutputStream.close();
            AudioFileIO.logger.getParent().setLevel(Level.OFF);
            AudioFile f = AudioFileIO.read(tmpFile);
            Tag tag = f.getTag();

            me = new Mp3Metadata();

            me.author = tag.getFirst(ARTIST);
            me.album = tag.getFirst(ALBUM);
            me.title = tag.getFirst(TITLE);
            me.comment = tag.getFirst(COMMENT);
            me.year = tag.getFirst(YEAR);

        } finally {
            if (tmpFile != null) {
                tmpFile.delete();
            }
View Full Code Here

              if (audio.getCodecA().contains("(windows media")) {
                audio.setCodecA(audio.getCodecA().substring(0, audio.getCodecA().indexOf("(windows media")).trim());
              }
            }

            Tag t = af.getTag();

            if (t != null) {
              if (t.getArtworkList().size() > 0) {
                setThumb(t.getArtworkList().get(0).getBinaryData());
              } else {
                if (configuration.getAudioThumbnailMethod() > 0) {
                  setThumb(
                    CoverUtil.get().getThumbnailFromArtistAlbum(
                      configuration.getAudioThumbnailMethod() == 1 ?
                        CoverUtil.AUDIO_AMAZON :
                        CoverUtil.AUDIO_DISCOGS,
                      audio.getArtist(), audio.getAlbum()
                    )
                  );
                }
              }

              if (!thumbOnly) {
                audio.setAlbum(t.getFirst(FieldKey.ALBUM));
                audio.setArtist(t.getFirst(FieldKey.ARTIST));
                audio.setSongname(t.getFirst(FieldKey.TITLE));
                String y = t.getFirst(FieldKey.YEAR);

                try {
                  if (y.length() > 4) {
                    y = y.substring(0, 4);
                  }
                  audio.setYear(Integer.parseInt(((y != null && y.length() > 0) ? y : "0")));
                  y = t.getFirst(FieldKey.TRACK);
                  audio.setTrack(Integer.parseInt(((y != null && y.length() > 0) ? y : "1")));
                  audio.setGenre(t.getFirst(FieldKey.GENRE));
                } catch (Throwable e) {
                  logger.debug("Error parsing unimportant metadata: " + e.getMessage());
                }
              }
            }
View Full Code Here

TOP

Related Classes of org.jaudiotagger.tag.Tag

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.