org.stanwood.media.store.mp4
Class MP4ITunesStore

java.lang.Object
  extended by org.stanwood.media.store.mp4.MP4ITunesStore
All Implemented Interfaces:
IExtension, IStore

public class MP4ITunesStore
extends java.lang.Object
implements IStore

This store is used to store Film/TV show information in .mp4/.m4v files used by iTunes. This allows iTunes to use the meta data and see the files complete with their meta data.

In order to function, this store uses the command line tools provided by the AtomicParsley application. Their are different forks of this application on the Internet. The most feature rich version I've found is at "https://bitbucket.org/shield007/atomicparsley". Media manager uses this one to add atoms that some of the other versions can't. The application must be installed on the PATH, or pointed to by the optional store parameters.

If using a version of AtomicParsley that does not support the setting of all fields that this store can handle, then a warning will be printed. A version with the above link that fully supports this store can downloaded from the MediaManager web site or installed via the installer.

This store has following optional parameters:


Constructor Summary
MP4ITunesStore(MP4ITunesStoreInfo storeInfo)
          The constructor
 
Method Summary
 void cacheEpisode(java.io.File rootMediaDir, java.io.File episodeFile, IEpisode episode)
          This is used to store episode information of a TVShow MP4 file into the file as meta data so that iTunes can read it.
 void cacheFilm(java.io.File rootMediaDir, java.io.File filmFile, IFilm film, java.lang.Integer part)
          This is used to write a film to the store.
 void cacheSeason(java.io.File rootMediaDir, java.io.File episodeFile, ISeason season)
          This does nothing as the season information can't be stored by this store
 void cacheShow(java.io.File rootMediaDir, java.io.File episodeFile, IShow show)
          This does nothing as the show information can't be stored by this store
 void fileDeleted(MediaDirectory dir, java.io.File file)
          This is called when a file is deleted from a media directory
 void fileUpdated(MediaDirectory mediaDirectory, java.io.File file)
          This is called when a file is updated within a media directory.
protected static void genericAtoms(IMediaFileInfo info, IMP4Manager mp4Manager, java.util.List<IAtom> atoms, java.lang.String flavour)
           
protected static IAtom getArtworkAtom(IMP4Manager mp4Manager, java.io.File mp4File, IVideo video)
           
 IEpisode getEpisode(java.io.File rootMediaDir, java.io.File episodeFile, ISeason season, int episodeNum)
          This will always return null as this is a write only store
 IEpisode getEpisode(MediaDirectory dir, java.io.File file)
          This is used to get a episode from a store via it's file name.
 IFilm getFilm(java.io.File rootMediaDir, java.io.File filmFile, java.lang.String filmId)
          Always returns null as it is not implemented for this store.
 IFilm getFilm(MediaDirectory dir, java.io.File file)
          This is used to get a film from a store via it's file name.
 java.lang.String getParameter(java.lang.String key)
          Used to get the value of a source parameter.
 ISeason getSeason(java.io.File rootMediaDir, java.io.File episodeFile, IShow show, int seasonNum)
          This will always return null as this is a write only store
 IShow getShow(java.io.File rootMediaDir, java.io.File episodeFile, java.lang.String showId)
          This will always return null as this is a write only store
 IEpisode getSpecial(java.io.File rootMediaDir, java.io.File episodeFile, ISeason season, int specialNumber)
          This will always return null as this is a write only store
static java.net.URL getVideoURL(IVideo video)
          Used to get the image URL of a video
 void init(Controller controller, java.io.File nativeDir)
          Called to initialise the stores and check all their resources can be found.
protected  boolean isItunesExtension(java.io.File file)
           
 java.util.List<IEpisode> listEpisodes(MediaDirConfig dirConfig, IProgressMonitor monitor)
          This is used to list all the episodes within the store if the store supports the operation.
 java.util.List<IFilm> listFilms(MediaDirConfig dirConfig, IProgressMonitor monitor)
          This is used to list all the films within the store if the store supports the operation.
 void performedActions(MediaDirectory dir)
          This is called after all the actions on all the media files have been performed so that the store can clean up any stale data.
protected  java.util.Properties readStoreConfig(MediaDirectory mediaDirectory, java.io.File configFile)
           
 void renamedFile(java.io.File rootMediaDir, java.io.File oldFile, java.io.File newFile)
          This does nothing as the meta data is stored in the actual file
protected  void saveStoreVersion(MediaDirectory mediaDirectory)
           
 SearchResult searchMedia(java.lang.String name, Mode mode, java.lang.Integer part, MediaDirConfig dirConfig, java.io.File mediaFile)
          Used to search for store for media
 void setParameter(java.lang.String key, java.lang.String value)
          Used to set source parameters.
static void updateEpsiode(Controller controller, IMP4Manager mp4Manager, java.io.File mp4File, IEpisode episode)
          Used to add atoms to a MP4 file that makes iTunes see it as a TV Show episode
static void updateFilm(Controller controller, IMP4Manager mp4Manager, java.io.File mp4File, IFilm film, java.lang.Integer part)
          Used to add atoms to a MP4 file that makes iTunes see it as a Film.
 void upgrade(MediaDirectory mediaDirectory)
          This is called to check if a upgrade is needed and perform the upgrade if required
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MP4ITunesStore

public MP4ITunesStore(MP4ITunesStoreInfo storeInfo)
The constructor

Parameters:
storeInfo - The store information
Method Detail

init

public void init(Controller controller,
                 java.io.File nativeDir)
          throws StoreException
Called to initialise the stores and check all their resources can be found. This is called before performing any actions.

Specified by:
init in interface IStore
Parameters:
controller - The media controller
nativeDir - The native folder been used or configured. Null if can't be found
Throws:
StoreException - Thrown if their are any problems

cacheEpisode

public void cacheEpisode(java.io.File rootMediaDir,
                         java.io.File episodeFile,
                         IEpisode episode)
                  throws StoreException
This is used to store episode information of a TVShow MP4 file into the file as meta data so that iTunes can read it.

Specified by:
cacheEpisode in interface IStore
Parameters:
episodeFile - The mp4 episode file
episode - The episode details
rootMediaDir - This is the directory which is the root of media, this can be the current directory if it was not specified on the command line.
Throws:
StoreException - Thrown if their is a problem storing the meta data

cacheSeason

public void cacheSeason(java.io.File rootMediaDir,
                        java.io.File episodeFile,
                        ISeason season)
                 throws StoreException
This does nothing as the season information can't be stored by this store

Specified by:
cacheSeason in interface IStore
Parameters:
episodeFile - The mp4 episode file
season - The season details
rootMediaDir - This is the directory which is the root of media, this can be the current directory if it was not specified on the command line.
Throws:
StoreException - Thrown if their is a problem storing the meta data

cacheShow

public void cacheShow(java.io.File rootMediaDir,
                      java.io.File episodeFile,
                      IShow show)
               throws StoreException
This does nothing as the show information can't be stored by this store

Specified by:
cacheShow in interface IStore
Parameters:
episodeFile - The mp4 episode file
show - The show details
rootMediaDir - This is the directory which is the root of media, this can be the current directory if it was not specified on the command line.
Throws:
StoreException - Thrown if their is a problem storing the meta data

getEpisode

public IEpisode getEpisode(java.io.File rootMediaDir,
                           java.io.File episodeFile,
                           ISeason season,
                           int episodeNum)
                    throws StoreException
This will always return null as this is a write only store

Specified by:
getEpisode in interface IStore
Parameters:
episodeFile - the file which the episode is stored in
season - The season the episode belongs too
episodeNum - The number of the episode too get
rootMediaDir - This is the directory which is the root of media, this can be the current directory if it was not specified on the command line.
Returns:
Always returns null
Throws:
StoreException - Thrown if their is a problem storing the meta data

getSeason

public ISeason getSeason(java.io.File rootMediaDir,
                         java.io.File episodeFile,
                         IShow show,
                         int seasonNum)
                  throws StoreException
This will always return null as this is a write only store

Specified by:
getSeason in interface IStore
Parameters:
episodeFile - the file which the episode is stored in
show - The show the season belongs too
seasonNum - The number of the season too get
rootMediaDir - This is the directory which is the root of media, this can be the current directory if it was not specified on the command line.
Returns:
Always returns null
Throws:
StoreException - Thrown if their is a problem storing the meta data

getShow

public IShow getShow(java.io.File rootMediaDir,
                     java.io.File episodeFile,
                     java.lang.String showId)
              throws StoreException
This will always return null as this is a write only store

Specified by:
getShow in interface IStore
Parameters:
episodeFile - the file which the episode is stored in
showId - The show Id of the show too get
rootMediaDir - This is the directory which is the root of media, this can be the current directory if it was not specified on the command line.
Returns:
Always returns null
Throws:
StoreException - Thrown if their is a problem storing the meta data

cacheFilm

public void cacheFilm(java.io.File rootMediaDir,
                      java.io.File filmFile,
                      IFilm film,
                      java.lang.Integer part)
               throws StoreException
This is used to write a film to the store.

Specified by:
cacheFilm in interface IStore
Parameters:
filmFile - The file which the film is stored in
film - The film to write
rootMediaDir - This is the directory which is the root of media, this can be the current directory if it was not specified on the command line.
part - The part number of the film
Throws:
StoreException - Thrown if their is a problem with the store

getSpecial

public IEpisode getSpecial(java.io.File rootMediaDir,
                           java.io.File episodeFile,
                           ISeason season,
                           int specialNumber)
                    throws java.net.MalformedURLException,
                           java.io.IOException,
                           StoreException
This will always return null as this is a write only store

Specified by:
getSpecial in interface IStore
Parameters:
episodeFile - the file which the special episode is stored in
season - The season the episode belongs too
specialNumber - The number of the special episode too get
rootMediaDir - This is the directory which is the root of media, this can be the current directory if it was not specified on the command line.
Returns:
Always returns null
Throws:
StoreException - Thrown if their is a problem storing the meta data
java.net.MalformedURLException - Thrown if their is a problem creating URL's
java.io.IOException - Thrown if their is a I/O related problem.

renamedFile

public void renamedFile(java.io.File rootMediaDir,
                        java.io.File oldFile,
                        java.io.File newFile)
This does nothing as the meta data is stored in the actual file

Specified by:
renamedFile in interface IStore
Parameters:
oldFile - The old file
newFile - The new file
rootMediaDir - This is the directory which is the root of media, this can be the current directory if it was not specified on the command line.

getFilm

public IFilm getFilm(java.io.File rootMediaDir,
                     java.io.File filmFile,
                     java.lang.String filmId)
              throws StoreException,
                     java.net.MalformedURLException,
                     java.io.IOException
Always returns null as it is not implemented for this store.

Specified by:
getFilm in interface IStore
Parameters:
filmFile - The file the film is stored in
filmId - The id of the film
rootMediaDir - This is the directory which is the root of media, this can be the current directory if it was not specified on the command line.
Returns:
The film, or null if it can't be found
Throws:
StoreException - Thrown if their is a problem retrieving the data
java.net.MalformedURLException - Thrown if their is a problem creating URL's
java.io.IOException - Thrown if their is a I/O related problem.

searchMedia

public SearchResult searchMedia(java.lang.String name,
                                Mode mode,
                                java.lang.Integer part,
                                MediaDirConfig dirConfig,
                                java.io.File mediaFile)
                         throws StoreException
Used to search for store for media

Specified by:
searchMedia in interface IStore
Parameters:
name - The search term
mode - The mode of the search
part - The part number to search for
dirConfig - The Media directory configuration
mediaFile - The media file the search is associated with
Returns:
The search result or NULL if it could not be found
Throws:
StoreException - Thrown if their is a problem with the store

setParameter

public void setParameter(java.lang.String key,
                         java.lang.String value)
                  throws StoreException

Used to set source parameters. If the key is not supported by this source, then a SourceException is thrown.

Specified by:
setParameter in interface IStore
Parameters:
key - The key of the parameter
value - The value of the parameter
Throws:
StoreException - Throw if the key is not supported by this store.

getParameter

public java.lang.String getParameter(java.lang.String key)
                              throws StoreException

Used to get the value of a source parameter. If the key is not supported by this source, then a SourceException is thrown.

Specified by:
getParameter in interface IStore
Parameters:
key - The key of the parameter
Returns:
The value of the parameter
Throws:
StoreException - Throw if the key is not supported by this store.

performedActions

public void performedActions(MediaDirectory dir)
This is called after all the actions on all the media files have been performed so that the store can clean up any stale data.

Specified by:
performedActions in interface IStore
Parameters:
dir - The media directory

fileDeleted

public void fileDeleted(MediaDirectory dir,
                        java.io.File file)
This is called when a file is deleted from a media directory

Specified by:
fileDeleted in interface IStore
Parameters:
dir - The media directory
file - The file

getEpisode

public IEpisode getEpisode(MediaDirectory dir,
                           java.io.File file)
                    throws StoreException
This is used to get a episode from a store via it's file name. If it can't be found, then this will return null.

Specified by:
getEpisode in interface IStore
Parameters:
dir - The media directory
file - The media file
Returns:
The episode or null if it can't be found
Throws:
StoreException - Thrown if their are any problems

getFilm

public IFilm getFilm(MediaDirectory dir,
                     java.io.File file)
              throws StoreException
This is used to get a film from a store via it's file name. If it can't be found, then this will return null.

Specified by:
getFilm in interface IStore
Parameters:
dir - The media directory
file - The media file
Returns:
The film or null if it can't be found
Throws:
StoreException - Thrown if their are any problems

updateEpsiode

public static void updateEpsiode(Controller controller,
                                 IMP4Manager mp4Manager,
                                 java.io.File mp4File,
                                 IEpisode episode)
                          throws MP4Exception
Used to add atoms to a MP4 file that makes iTunes see it as a TV Show episode

Parameters:
controller - the media file controller
mp4Manager - MP4 Manager
mp4File - The MP4 file
episode - The episode details
Throws:
MP4Exception - Thrown if their is a problem updating the atoms

getArtworkAtom

protected static IAtom getArtworkAtom(IMP4Manager mp4Manager,
                                      java.io.File mp4File,
                                      IVideo video)
                               throws MP4Exception
Throws:
MP4Exception

getVideoURL

public static java.net.URL getVideoURL(IVideo video)
Used to get the image URL of a video

Parameters:
video - The video information
Returns:
The image URL of the video, or null if it could not be found

updateFilm

public static void updateFilm(Controller controller,
                              IMP4Manager mp4Manager,
                              java.io.File mp4File,
                              IFilm film,
                              java.lang.Integer part)
                       throws MP4Exception
Used to add atoms to a MP4 file that makes iTunes see it as a Film. It also removes any artwork before adding the Film atoms and artwork.

Parameters:
controller - The media controller
mp4Manager - MP4 Manager
mp4File - The MP4 file
film - The film details
part - The part number of the film, or null if it does not have parts
Throws:
MP4Exception - Thrown if their is a problem updating the atoms

genericAtoms

protected static void genericAtoms(IMediaFileInfo info,
                                   IMP4Manager mp4Manager,
                                   java.util.List<IAtom> atoms,
                                   java.lang.String flavour)

listEpisodes

public java.util.List<IEpisode> listEpisodes(MediaDirConfig dirConfig,
                                             IProgressMonitor monitor)
This is used to list all the episodes within the store if the store supports the operation. It this store can't list episodes, then it will return null

Specified by:
listEpisodes in interface IStore
Parameters:
dirConfig - The media directory configuration
monitor - The progress monitor
Returns:
Null or a list of episodes in the store

listFilms

public java.util.List<IFilm> listFilms(MediaDirConfig dirConfig,
                                       IProgressMonitor monitor)
This is used to list all the films within the store if the store supports the operation. It this store can't list films, then it will return null

Specified by:
listFilms in interface IStore
Parameters:
dirConfig - The media directory configuration
monitor - The progress monitor
Returns:
Null or a list of films in the store

isItunesExtension

protected boolean isItunesExtension(java.io.File file)

upgrade

public void upgrade(MediaDirectory mediaDirectory)
             throws StoreException
This is called to check if a upgrade is needed and perform the upgrade if required

Specified by:
upgrade in interface IStore
Parameters:
mediaDirectory - The media directory been upgraded
Throws:
StoreException - Thrown if thier are any problems

saveStoreVersion

protected void saveStoreVersion(MediaDirectory mediaDirectory)
                         throws StoreException
Throws:
StoreException

readStoreConfig

protected java.util.Properties readStoreConfig(MediaDirectory mediaDirectory,
                                               java.io.File configFile)
                                        throws StoreException
Throws:
StoreException

fileUpdated

public void fileUpdated(MediaDirectory mediaDirectory,
                        java.io.File file)
                 throws StoreException
This is called when a file is updated within a media directory. This is typically called during the upgrade process if the meta data in the file has changed.

Specified by:
fileUpdated in interface IStore
Parameters:
mediaDirectory - The media directory the file belongs to
file - The media file
Throws:
StoreException - Thrown if their are any problems