com.melloware.jukes.file.tag
Class MusicTag

java.lang.Object
  extended by com.melloware.jukes.file.tag.MusicTag
All Implemented Interfaces:
ITag, java.lang.Comparable
Direct Known Subclasses:
AudioFileTag, Mp3Tag

public abstract class MusicTag
extends java.lang.Object
implements ITag, java.lang.Comparable

Abstract superclass for all tag types.

Copyright (c) 2006 Melloware, Inc.

Version:
4.0
Author:
Emil A. Lefkof III

Field Summary
protected  java.lang.String artist
           
protected  java.lang.Long bitRate
           
protected  java.lang.String comment
           
static java.lang.String CURRENT_YEAR
           
static java.lang.String DEFAULT_FILE_FORMAT
           
protected  java.lang.String disc
           
protected  java.lang.String encodedBy
           
protected  java.io.File file
           
protected  java.lang.String genre
           
protected  java.util.Map header
           
static java.lang.String NO_TAG
           
protected  java.lang.String title
           
protected  java.lang.String track
           
protected  long trackLength
           
protected  java.lang.String year
           
 
Constructor Summary
MusicTag(java.io.File aFile)
          Constructor that takes the music file.
 
Method Summary
 int compareTo(java.lang.Object o)
          CompareTo method for sorting tracks.
protected  java.lang.String createFilenameFromFormat(java.lang.String aFormat)
          Creates a new filename based on the format passed in.
 boolean equals(java.lang.Object obj)
          Default Equals method.
 java.lang.String extractTitleFromFilename()
          Tries to extract the title of the song from the filename.
 boolean fileExists()
          If the file exists or not.
 java.lang.String getAbsolutePath()
          Gets the absolute file path.
abstract  java.lang.String getArtist()
          Gets the artist.
abstract  java.lang.Long getBitRate()
          Gets the bitRate.
 java.lang.String getBitRateAsString()
          Returns the bit rate as a string.
abstract  java.lang.String getComment()
          Gets the comment.
abstract  java.lang.String getCopyrighted()
           
abstract  java.lang.String getDisc()
          Gets the disc.
abstract  java.lang.String getEmphasis()
           
abstract  java.lang.String getEncodedBy()
          Gets the encodedBy.
 java.io.File getFile()
          Gets the file.
abstract  java.lang.String getFrequency()
           
abstract  java.lang.String getGenre()
          Gets the genre.
static java.util.List getGenreTypes()
          Gets the genre list.
abstract  java.util.Map getHeader()
          Gets the header.
 java.lang.String getHeaderInfo()
          Returns the info about the audio file.
 java.lang.String getHeaderValue(java.lang.String aKey)
          Returns the info about the audio file.
abstract  java.lang.String getLayer()
           
abstract  java.lang.String getMode()
           
abstract  java.lang.String getTitle()
          Gets the title.
abstract  java.lang.String getTrack()
          Gets the track.
abstract  long getTrackLength()
          Gets the trackLength.
 java.lang.String getTrackLengthAsString()
          Gets the track length in seconds.
abstract  java.lang.String getVersion()
           
abstract  java.lang.String getYear()
          Gets the year.
 int hashCode()
          Default hashcode method.
abstract  boolean isVBR()
           
abstract  void removeTags()
          Removes tags from the audio file.
 boolean renameFile()
          Renames this Music file based on the default format of %n - %t.mp3 so it looks like 01 - Track.mp3.
abstract  boolean renameFile(java.lang.String aFormat)
          Renames this Music file based on a format from prefs.
abstract  void save()
          Saves the tag back to the file.
abstract  void setArtist(java.lang.String aArtist)
          Sets the artist.
abstract  void setComment(java.lang.String aComment)
          Sets the comment.
abstract  void setDisc(java.lang.String aDisc)
          Sets the disc.
abstract  void setEncodedBy(java.lang.String aEncodedBy)
          Sets the encodedBy.
abstract  void setGenre(java.lang.String aGenre)
          Sets the genre.
abstract  void setTitle(java.lang.String aTitle)
          Sets the title.
abstract  void setTrack(java.lang.String aTrack)
          Sets the track.
abstract  void setTrack(java.lang.String track, int padding)
          Sets the track.
abstract  void setTrackLength(long aTrackLength)
          Sets the trackLength.
abstract  void setYear(java.lang.String aYear)
          Sets the year.
 void synchronize()
          Synchronizes the tag to have the same data in the V1 and V2 tag.
 java.lang.String toString()
          Default toString() method.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

NO_TAG

public static final java.lang.String NO_TAG
See Also:
Constant Field Values

CURRENT_YEAR

public static final java.lang.String CURRENT_YEAR

DEFAULT_FILE_FORMAT

public static final java.lang.String DEFAULT_FILE_FORMAT
See Also:
Constant Field Values

file

protected java.io.File file

bitRate

protected java.lang.Long bitRate

trackLength

protected long trackLength

header

protected java.util.Map header

artist

protected java.lang.String artist

comment

protected java.lang.String comment

disc

protected java.lang.String disc

encodedBy

protected java.lang.String encodedBy

genre

protected java.lang.String genre

title

protected java.lang.String title

track

protected java.lang.String track

year

protected java.lang.String year
Constructor Detail

MusicTag

public MusicTag(java.io.File aFile)
         throws MusicTagException
Constructor that takes the music file.

Parameters:
aFile - the music file
Throws:
MusicTagException - if any error occurs opening tag
Method Detail

getArtist

public abstract java.lang.String getArtist()
Gets the artist.

Specified by:
getArtist in interface ITag
Returns:
Returns the artist.

getBitRate

public abstract java.lang.Long getBitRate()
Gets the bitRate.

Specified by:
getBitRate in interface ITag
Returns:
Returns the bitRate.

getComment

public abstract java.lang.String getComment()
Gets the comment.

Specified by:
getComment in interface ITag
Returns:
Returns the comment.

getCopyrighted

public abstract java.lang.String getCopyrighted()
Specified by:
getCopyrighted in interface ITag

getDisc

public abstract java.lang.String getDisc()
Gets the disc.

Specified by:
getDisc in interface ITag
Returns:
Returns the disc.

getEmphasis

public abstract java.lang.String getEmphasis()
Specified by:
getEmphasis in interface ITag

getEncodedBy

public abstract java.lang.String getEncodedBy()
Gets the encodedBy.

Specified by:
getEncodedBy in interface ITag
Returns:
Returns the encodedBy.

getFrequency

public abstract java.lang.String getFrequency()
Specified by:
getFrequency in interface ITag

getGenre

public abstract java.lang.String getGenre()
Gets the genre.

Specified by:
getGenre in interface ITag
Returns:
Returns the genre.

getHeader

public abstract java.util.Map getHeader()
Gets the header.

Specified by:
getHeader in interface ITag
Returns:
Returns the header.

getLayer

public abstract java.lang.String getLayer()
Specified by:
getLayer in interface ITag

getMode

public abstract java.lang.String getMode()
Specified by:
getMode in interface ITag

getTitle

public abstract java.lang.String getTitle()
Gets the title.

Specified by:
getTitle in interface ITag
Returns:
Returns the title.

getTrack

public abstract java.lang.String getTrack()
Gets the track.

Specified by:
getTrack in interface ITag
Returns:
Returns the track.

getTrackLength

public abstract long getTrackLength()
Gets the trackLength.

Specified by:
getTrackLength in interface ITag
Returns:
Returns the trackLength.

getVersion

public abstract java.lang.String getVersion()
Specified by:
getVersion in interface ITag

getYear

public abstract java.lang.String getYear()
Gets the year.

Specified by:
getYear in interface ITag
Returns:
Returns the year.

setArtist

public abstract void setArtist(java.lang.String aArtist)
Sets the artist.

Specified by:
setArtist in interface ITag
Parameters:
aArtist - The artist to set.

setComment

public abstract void setComment(java.lang.String aComment)
Sets the comment.

Specified by:
setComment in interface ITag
Parameters:
aComment - The comment to set.

setDisc

public abstract void setDisc(java.lang.String aDisc)
Sets the disc.

Specified by:
setDisc in interface ITag
Parameters:
aDisc - The disc to set.

setEncodedBy

public abstract void setEncodedBy(java.lang.String aEncodedBy)
Sets the encodedBy.

Specified by:
setEncodedBy in interface ITag
Parameters:
aEncodedBy - The encodedBy to set.

setGenre

public abstract void setGenre(java.lang.String aGenre)
Sets the genre.

Specified by:
setGenre in interface ITag
Parameters:
aGenre - The genre to set.

setTitle

public abstract void setTitle(java.lang.String aTitle)
Sets the title.

Specified by:
setTitle in interface ITag
Parameters:
aTitle - The title to set.

setTrack

public abstract void setTrack(java.lang.String aTrack)
Sets the track.

Specified by:
setTrack in interface ITag
Parameters:
aTrack - The track to set.

setTrack

public abstract void setTrack(java.lang.String track,
                              int padding)
Sets the track.

Specified by:
setTrack in interface ITag
Parameters:
aTrack - The track to set.
padding - the number of 0's to pad

setTrackLength

public abstract void setTrackLength(long aTrackLength)
Sets the trackLength.

Parameters:
aTrackLength - The trackLength to set.

setYear

public abstract void setYear(java.lang.String aYear)
Sets the year.

Specified by:
setYear in interface ITag
Parameters:
aYear - The year to set.

isVBR

public abstract boolean isVBR()
Specified by:
isVBR in interface ITag

removeTags

public abstract void removeTags()
                         throws MusicTagException
Removes tags from the audio file.

Throws:
MusicTagException - if any error occurs removing the tag

renameFile

public abstract boolean renameFile(java.lang.String aFormat)
Renames this Music file based on a format from prefs. The format is in aFormat and can have values %n for track number, %t for title, %a for artist, and %d for disc. Replaces any invalid characters (\\, /, :, , *, ?, ", <, >, or |) with underscores _ to prevent any errors on file systems. Examples: %n -%t = 01 - Track.mp3 %a - %d - %n - %t = Artist - Album - 01 - Track.mp3

Parameters:
aFormat - the string format like %n -%t to rename 01 - Track.mp3
Returns:
true if renamed, false if failure

save

public abstract void save()
                   throws MusicTagException
Saves the tag back to the file.

Throws:
MusicTagException - if any error occurs saving the file

getGenreTypes

public static java.util.List getGenreTypes()
Gets the genre list.

Returns:
Returns the genre list

getAbsolutePath

public java.lang.String getAbsolutePath()
Gets the absolute file path.

Returns:
Returns the absolute file path

getBitRateAsString

public java.lang.String getBitRateAsString()
Returns the bit rate as a string.

Returns:
the bitrate value as a string decoded with VBR

getFile

public java.io.File getFile()
Gets the file.

Specified by:
getFile in interface ITag
Returns:
Returns the file.

getHeaderInfo

public java.lang.String getHeaderInfo()
Returns the info about the audio file.

Returns:
string containing the info about the MP3 file

getHeaderValue

public java.lang.String getHeaderValue(java.lang.String aKey)
Returns the info about the audio file.

Returns:
string containing the info about the MP3 file

getTrackLengthAsString

public java.lang.String getTrackLengthAsString()
Gets the track length in seconds.

Returns:
Returns the track length in seconds.

equals

public boolean equals(java.lang.Object obj)
Default Equals method.

Overrides:
equals in class java.lang.Object

extractTitleFromFilename

public java.lang.String extractTitleFromFilename()
Tries to extract the title of the song from the filename.

EXAMPLES: 06 - Opiate.mp3 = Opiate Tool - Aenima - 06 - Opiate.mp3 = Opiate 02 - Positively 4th Street.mp3 = Positively 4th Street 11 - Nothing Compares 2 U.mp3 = Nothing Compares 2 U

Returns:
the title extracted from the filename

fileExists

public boolean fileExists()
If the file exists or not.

Returns:
Returns the file exists flag

hashCode

public int hashCode()
Default hashcode method.

Overrides:
hashCode in class java.lang.Object

renameFile

public boolean renameFile()
Renames this Music file based on the default format of %n - %t.mp3 so it looks like 01 - Track.mp3.

Returns:
true if renamed, false if failure

synchronize

public void synchronize()
Synchronizes the tag to have the same data in the V1 and V2 tag.


compareTo

public int compareTo(java.lang.Object o)
CompareTo method for sorting tracks.

Specified by:
compareTo in interface java.lang.Comparable

toString

public java.lang.String toString()
Default toString() method.

Overrides:
toString in class java.lang.Object

createFilenameFromFormat

protected java.lang.String createFilenameFromFormat(java.lang.String aFormat)
Creates a new filename based on the format passed in.

Parameters:
aFormat - the file format like %n -%t = 01 - Track.mp3
Returns:
the new file name


Copyright © 1999-2008 Melloware Inc. All Rights Reserved.