de.axelwernicke.mypod.ipod
Class ITunesDB

java.lang.Object
  extended byde.axelwernicke.mypod.ipod.ITunesDB

public class ITunesDB
extends java.lang.Object

An iTunes Database object is related to an database file on an Apple iPod. The database contains references to all music files on an iPod, as well as meta information about the songs. Further all information about playlists on the iPod. All information are stored in a binary file, and is contained in tags. The set of tags contains

 mhbd - root tag of a database
mhsd - list holder, contains song lists or playlists
mhlt - song list header contains song items
mhit - song item, stores song meta information and is followed by one or more
mhod - song item content - stores one strings like artist, filetype, path etc.
mhlp - playlist header, contains one or more playlist items
mhyp - playlist item holds the playlist in paires of
mhip - playlist index and mhod
an ITunesDB object stores the informations from the 'mhbd' tag and has references to the content of all other tags.

Author:
axelwe
See Also:
for more details

Constructor Summary
ITunesDB()
          Creates a new instance of an iTunesDB.
ITunesDB(java.lang.String iPodName)
          Constructs a new iTunesDB object.
 
Method Summary
 void addClip(int fileIndex, MP3MetaV2 meta)
          Adds a clip to song list and master playlist
 void createPlaylist(java.lang.String name, java.util.Vector fileIdc)
          Creates a new playlist on iPod containing all the songs in the Vector.
 java.lang.String getFilename(long fileIndex)
          Gets the filename for a song from its file index.
 long getFilesize(long fileIndex)
          Gets the filesize for a song from the file index.
 int getNextAvailableSongIndex(int fileIndex)
          Determines the next available file index.
 de.axelwernicke.mypod.ipod.ITunesDBPlaylistHeader getPlaylistHeader()
          Getter for property playlistHeader.
 de.axelwernicke.mypod.ipod.ITunesDBListHolder getPlaylistHolder()
          Getter for property playlistHolder.
 int getRecordSize()
          Getter for property recordSize.
 de.axelwernicke.mypod.ipod.ITunesDBSonglistHeader getSonglistHeader()
          Gets the songlist header record
 de.axelwernicke.mypod.ipod.ITunesDBListHolder getSonglistHolder()
          Gets the songlist holder record.
 int getTagSize()
          Getter for property tagSize.
 long getTotalFilesize()
          Gets the summarized size of all songs on the iPod
 long getTotalFilesize(java.util.Vector fileIdc)
          Gets the summarized size of all songs.
 int getUnknown3()
          Getter for property unknown3.
 int getUnknown4()
          Getter for property unknown4.
 int getUnknown5()
          Getter for property unknown5.
 void initPlaylistHeader(java.lang.String iPodName)
          Initializes playlist header record.
 void initPlaylistHolder()
          initializes the playlist holder record.
 void initSonglistHeader()
          initializes songlist header record.
 void initSonglistHolder()
          Initializes the songlist holder record of the database.
 void removeClip(long fileIndex)
          removes a song from the song list and all playlists.
 void removeEmptyPlaylists()
          iterates over all playlists and removes them, if not a masterplaylist, but empty.
 void setMasterPlaylistName(java.lang.String name)
          Sets the name of the masterplaylist of the db
 void setPlaylistHeader(de.axelwernicke.mypod.ipod.ITunesDBPlaylistHeader playlistHeader)
          Setter for property playlistHeader.
 void setPlaylistHolder(de.axelwernicke.mypod.ipod.ITunesDBListHolder playlistHolder)
          Setter for property playlistHolder.
 void setRecordSize(int recordSize)
          Setter for property recordSize.
 void setSonglistHeader(de.axelwernicke.mypod.ipod.ITunesDBSonglistHeader songlistHeader)
          Setter for property songlistHeader.
 void setSonglistHolder(de.axelwernicke.mypod.ipod.ITunesDBListHolder songlistHolder)
          Setter for property songlistHolder.
 void setTagSize(int tagSize)
          Setter for property tagSize.
 void setUnknown3(int unknown3)
          Setter for property unknown3.
 void setUnknown4(int unknown4)
          Setter for property unknown4.
 void setUnknown5(int unknown5)
          Setter for property unknown5.
 java.lang.String toString()
          generates a string that represents the current object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ITunesDB

public ITunesDB()
Creates a new instance of an iTunesDB. An core object without any content is created.


ITunesDB

public ITunesDB(java.lang.String iPodName)
Constructs a new iTunesDB object. An empty, but valid database is created.

Parameters:
iPodName - , used as name of the masterplaylist
Method Detail

initSonglistHolder

public void initSonglistHolder()
Initializes the songlist holder record of the database.


initSonglistHeader

public void initSonglistHeader()
initializes songlist header record.


initPlaylistHolder

public void initPlaylistHolder()
initializes the playlist holder record.


initPlaylistHeader

public void initPlaylistHeader(java.lang.String iPodName)
Initializes playlist header record. A masterplaylist is created.

Parameters:
iPodName - name of the master playlist (equals name of the iPod)

getSonglistHolder

public de.axelwernicke.mypod.ipod.ITunesDBListHolder getSonglistHolder()
Gets the songlist holder record.

Returns:
songlist holder record of the database

getSonglistHeader

public de.axelwernicke.mypod.ipod.ITunesDBSonglistHeader getSonglistHeader()
Gets the songlist header record

Returns:
songlist record

getTotalFilesize

public long getTotalFilesize()
Gets the summarized size of all songs on the iPod

Returns:
size of all songs in bytes

getTotalFilesize

public long getTotalFilesize(java.util.Vector fileIdc)
Gets the summarized size of all songs.

Parameters:
fileIdc - vector containing file indices to summarize size
Returns:
summarized size of selected songs

getFilename

public java.lang.String getFilename(long fileIndex)
Gets the filename for a song from its file index.

Parameters:
fileIndex - of the song
Returns:
filename for the song

getFilesize

public long getFilesize(long fileIndex)
Gets the filesize for a song from the file index.

Parameters:
fileIndex - fileindex of the song
Returns:
size of the song in bytes

removeClip

public void removeClip(long fileIndex)
removes a song from the song list and all playlists.
- iterate over all playlists and remove clip by fileindex (filename without extension)
- remove clip from the songlist

Parameters:
fileIndex - of the song to remove

addClip

public void addClip(int fileIndex,
                    MP3MetaV2 meta)
Adds a clip to song list and master playlist

Parameters:
fileIndex - of the song on the iPod
meta - information about the song

getNextAvailableSongIndex

public int getNextAvailableSongIndex(int fileIndex)
Determines the next available file index. This fileindex is used as base filename to store the song on iPod.

Parameters:
fileIndex - recently used file index or 0
Returns:
next available fileindex

removeEmptyPlaylists

public void removeEmptyPlaylists()
iterates over all playlists and removes them, if not a masterplaylist, but empty.


createPlaylist

public void createPlaylist(java.lang.String name,
                           java.util.Vector fileIdc)
Creates a new playlist on iPod containing all the songs in the Vector.

Parameters:
name - of the playlist
fileIdc - Vector of fileindices to include in the playlist

toString

public java.lang.String toString()
generates a string that represents the current object

Returns:
string representation of the database

getTagSize

public int getTagSize()
Getter for property tagSize.

Returns:
Value of property tagSize.

setTagSize

public void setTagSize(int tagSize)
Setter for property tagSize.

Parameters:
tagSize - New value of property tagSize.

getRecordSize

public int getRecordSize()
Getter for property recordSize.

Returns:
Value of property recordSize.

setRecordSize

public void setRecordSize(int recordSize)
Setter for property recordSize.

Parameters:
recordSize - New value of property recordSize.

getUnknown3

public int getUnknown3()
Getter for property unknown3.

Returns:
Value of property unknown3.

setUnknown3

public void setUnknown3(int unknown3)
Setter for property unknown3.

Parameters:
unknown3 - New value of property unknown3.

getUnknown4

public int getUnknown4()
Getter for property unknown4.

Returns:
Value of property unknown4.

setUnknown4

public void setUnknown4(int unknown4)
Setter for property unknown4.

Parameters:
unknown4 - New value of property unknown4.

getUnknown5

public int getUnknown5()
Getter for property unknown5.

Returns:
Value of property unknown5.

setUnknown5

public void setUnknown5(int unknown5)
Setter for property unknown5.

Parameters:
unknown5 - New value of property unknown5.

setSonglistHolder

public void setSonglistHolder(de.axelwernicke.mypod.ipod.ITunesDBListHolder songlistHolder)
Setter for property songlistHolder.

Parameters:
songlistHolder - New value of property songlistHolder.

setSonglistHeader

public void setSonglistHeader(de.axelwernicke.mypod.ipod.ITunesDBSonglistHeader songlistHeader)
Setter for property songlistHeader.

Parameters:
songlistHeader - New value of property songlistHeader.

getPlaylistHolder

public de.axelwernicke.mypod.ipod.ITunesDBListHolder getPlaylistHolder()
Getter for property playlistHolder.

Returns:
Value of property playlistHolder.

setPlaylistHolder

public void setPlaylistHolder(de.axelwernicke.mypod.ipod.ITunesDBListHolder playlistHolder)
Setter for property playlistHolder.

Parameters:
playlistHolder - New value of property playlistHolder.

getPlaylistHeader

public de.axelwernicke.mypod.ipod.ITunesDBPlaylistHeader getPlaylistHeader()
Getter for property playlistHeader.

Returns:
Value of property playlistHeader.

setPlaylistHeader

public void setPlaylistHeader(de.axelwernicke.mypod.ipod.ITunesDBPlaylistHeader playlistHeader)
Setter for property playlistHeader.

Parameters:
playlistHeader - New value of property playlistHeader.

setMasterPlaylistName

public void setMasterPlaylistName(java.lang.String name)
Sets the name of the masterplaylist of the db

Parameters:
name -