org.stanwood.media
Class MediaDirectory

java.lang.Object
  extended by org.stanwood.media.MediaDirectory

public class MediaDirectory
extends java.lang.Object

Used to represent a directory that contains media and can be managed by MediaManager


Constructor Summary
MediaDirectory(Controller controller, ConfigReader config, java.io.File mediaDir)
          The constructor
 
Method Summary
protected  void createSearchers()
           
 void fileChanged(java.io.File file)
          This is called to notify stores that a file has changed.
 java.util.List<IAction> getActions()
          Get the actions been used by the media directory
 Controller getController()
          Used to get the media controller
 IEpisode getEpisode(java.io.File rootMediaDir, java.io.File episodeFile, ISeason season, int episodeNum, boolean refresh)
          Get a episode with a given episode number.
 IFilm getFilm(java.io.File rootMediaDir, java.io.File filmFile, SearchResult searchResult, boolean refresh)
          Get a film with a given film id and source id.
 MediaDirConfig getMediaDirConfig()
          Get the configuration of the media directory
 java.io.File getPath(java.lang.String name)
          Used to get the full location of a file within the media directory
 ISeason getSeason(java.io.File rootMediaDir, java.io.File episodeFile, IShow show, int seasonNum, boolean refresh)
          Get a season with a given season number.
 IShow getShow(java.io.File rootMediaDir, java.io.File episodeFile, SearchResult searchResult, boolean refresh)
          Get a show with a given show id and source id.
 java.util.List<ISource> getSources()
          Get the sources been used by the media directory
 IEpisode getSpecial(java.io.File rootMediaDir, java.io.File specialFile, ISeason season, int specialNum, boolean refresh)
          Get a special episode with a given special episode number.
 java.util.List<IStore> getStores()
          Get the stores been used by the media directory
 void renamedFile(java.io.File rootMediaDir, java.io.File oldFile, java.io.File newFile)
          This is used when a file that holds a episode or film has been renamed
 SearchResult searchForVideoId(java.io.File mediaFile, boolean useSources)
          This will search for a show id in the stores and sources.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MediaDirectory

public MediaDirectory(Controller controller,
                      ConfigReader config,
                      java.io.File mediaDir)
               throws ConfigException
The constructor

Parameters:
controller - The media controller
config - The configuration of the media directory
mediaDir - The location of the media directory
Throws:
ConfigException - Thrown if their is a problem reading the configuration
Method Detail

createSearchers

protected void createSearchers()

getShow

public IShow getShow(java.io.File rootMediaDir,
                     java.io.File episodeFile,
                     SearchResult searchResult,
                     boolean refresh)
              throws java.net.MalformedURLException,
                     SourceException,
                     java.io.IOException,
                     StoreException
Get a show with a given show id and source id. This will first try to retrieve the show from the stores. If it is not able to do this, then it will try the sources. If it can't retrieve it from either the sources or the stores, then null is returned. If the refresh parameter is set too true, then the stores are ignored and it retrieves data strait from the sources. If data is retrieved from the source, then it makes an attempt to write it too the stores.

Parameters:
rootMediaDir - The root media directory
episodeFile - The file the episode is stored in
searchResult - The search results from looking for a show
refresh - If true, then the stores are ignored.
Returns:
The show, or null if it can't be found.
Throws:
java.net.MalformedURLException - Thrown if their is a problem creating URL's
SourceException - Thrown if their is a source related problem.
java.io.IOException - Thrown if their is a I/O related problem.
StoreException - Thrown if their is a store related problem.

getFilm

public IFilm getFilm(java.io.File rootMediaDir,
                     java.io.File filmFile,
                     SearchResult searchResult,
                     boolean refresh)
              throws java.net.MalformedURLException,
                     SourceException,
                     java.io.IOException,
                     StoreException
Get a film with a given film id and source id. This will first try to retrieve the film from the stores. If it is not able to do this, then it will try the sources. If it can't retrieve it from either the sources or the stores, then null is returned. If the refresh parameter is set too true, then the stores are ignored and it retrieves data strait from the sources. If data is retrieved from the source, then it makes an attempt to write it too the stores.

Parameters:
rootMediaDir - The root media directory
filmFile - The file the film is stored in
searchResult - The resulting film from a search
refresh - If true, then the stores are ignored.
Returns:
The film, or null if it can't be found.
Throws:
java.net.MalformedURLException - Thrown if their is a problem creating URL's
SourceException - Thrown if their is a source related problem.
java.io.IOException - Thrown if their is a I/O related problem.
StoreException - Thrown if their is a store related problem.

getSeason

public ISeason getSeason(java.io.File rootMediaDir,
                         java.io.File episodeFile,
                         IShow show,
                         int seasonNum,
                         boolean refresh)
                  throws SourceException,
                         java.io.IOException,
                         StoreException
Get a season with a given season number. This will first try to retrieve the season from the stores. If it is not able to do this, then it will try the sources. If it can't retrieve it from either the sources or the stores, then null is returned. If the refresh parameter is set too true, then the stores are ignored and it retrieves data strait from the sources. If data is retrieved from the source, then it makes an attempt to write it too the stores.

Parameters:
rootMediaDir - The root media directory
episodeFile - The file the episode is stored in
show - The show the season belongs too
seasonNum - The season number
refresh - If true, then the stores are ignored.
Returns:
The season, or null if it can't be found.
Throws:
SourceException - Thrown if their is a source related problem.
java.io.IOException - Thrown if their is a I/O related problem.
StoreException - Thrown if their is a store related problem.

getEpisode

public IEpisode getEpisode(java.io.File rootMediaDir,
                           java.io.File episodeFile,
                           ISeason season,
                           int episodeNum,
                           boolean refresh)
                    throws SourceException,
                           java.net.MalformedURLException,
                           java.io.IOException,
                           StoreException
Get a episode with a given episode number. This will first try to retrieve the episode from the stores. If it is not able to do this, then it will try the sources. If it can't retrieve it from either the sources or the stores, then null is returned. If the refresh parameter is set too true, then the stores are ignored and it retrieves data strait from the sources. If data is retrieved from the source, then it makes an attempt to write it too the stores.

Parameters:
rootMediaDir - The root media directory
season - The season the episode belongs too
episodeNum - The episode number
refresh - If true, then the stores are ignored.
episodeFile - The file the episode is stored in
Returns:
The episode, or null if it can't be found.
Throws:
java.net.MalformedURLException - Thrown if their is a problem creating URL's
SourceException - Thrown if their is a source related problem.
java.io.IOException - Thrown if their is a I/O related problem.
StoreException - Thrown if their is a store related problem.

getSpecial

public IEpisode getSpecial(java.io.File rootMediaDir,
                           java.io.File specialFile,
                           ISeason season,
                           int specialNum,
                           boolean refresh)
                    throws SourceException,
                           java.net.MalformedURLException,
                           java.io.IOException,
                           StoreException
Get a special episode with a given special episode number. This will first try to retrieve the special episode from the stores. If it is not able to do this, then it will try the sources. If it can't retrieve it from either the sources or the stores, then null is returned. If the refresh parameter is set too true, then the stores are ignored and it retrieves data strait from the sources. If data is retrieved from the source, then it makes an attempt to write it too the stores.

Parameters:
rootMediaDir - The root media directory
season - The season the episode belongs too
specialNum - The special episode number
refresh - If true, then the stores are ignored.
specialFile - The file the special episode is stored in
Returns:
The special episode, or null if it can't be found.
Throws:
java.net.MalformedURLException - Thrown if their is a problem creating URL's
SourceException - Thrown if their is a source related problem.
java.io.IOException - Thrown if their is a I/O related problem.
StoreException - Thrown if their is a store related problem.

fileChanged

public void fileChanged(java.io.File file)
                 throws StoreException
This is called to notify stores that a file has changed.

Parameters:
file - The file that has changed
Throws:
StoreException - Thrown if their are any problems

searchForVideoId

public SearchResult searchForVideoId(java.io.File mediaFile,
                                     boolean useSources)
                              throws SourceException,
                                     StoreException,
                                     java.net.MalformedURLException,
                                     java.io.IOException
This will search for a show id in the stores and sources. It will use the show directory as the name of the show if needed.

Parameters:
mediaFile - The file the media is stored in
useSources - True to search sources, otherwise will only use stores
Returns:
The results of searching for the show, or null if it can't be found.
Throws:
SourceException - Thrown if their is a problem reading from a source
StoreException - Thrown if their is a problem reading for a store
java.io.IOException - Throw if their is a IO problem
java.net.MalformedURLException - Throw if their is a problem creating a URL

renamedFile

public void renamedFile(java.io.File rootMediaDir,
                        java.io.File oldFile,
                        java.io.File newFile)
                 throws StoreException
This is used when a file that holds a episode or film has been renamed

Parameters:
rootMediaDir - The root media directory
oldFile - The old file
newFile - The new file
Throws:
StoreException - Thrown if their is a problem renaming files

getMediaDirConfig

public MediaDirConfig getMediaDirConfig()
Get the configuration of the media directory

Returns:
the configuration of the media directory

getStores

public java.util.List<IStore> getStores()
Get the stores been used by the media directory

Returns:
The stores

getSources

public java.util.List<ISource> getSources()
Get the sources been used by the media directory

Returns:
The sources

getActions

public java.util.List<IAction> getActions()
Get the actions been used by the media directory

Returns:
The actions

getPath

public java.io.File getPath(java.lang.String name)
Used to get the full location of a file within the media directory

Parameters:
name - the path of the file relative to the media directory
Returns:
the full location of a file within the media directory

getController

public Controller getController()
Used to get the media controller

Returns:
the media controller