Class CrateDigger


  • @API(status=STABLE)
    public class CrateDigger
    extends Object

    Uses the Crate Digger library to provide an even more reliable source of track metadata, even when there are four players in use on the network and the VirtualCdj is forced to use a non-standard player number.

    To take advantage of these capabilities, simply call the start() method and then use the MetadataFinder as you would have without this class.

    Since:
    0.5.0
    Author:
    James Elliott
    • Field Detail

      • DEVICE_SQL_FILENAME

        public static final String DEVICE_SQL_FILENAME
        The file name rekordbox uses to create legacy DeviceSQL export databases.
        See Also:
        Constant Field Values
      • SQLITE_FILENAME

        public static final String SQLITE_FILENAME
        The file name rekordbox uses to create newer SQLite export databases.
        See Also:
        Constant Field Values
      • downloadDirectory

        @API(status=STABLE)
        public final File downloadDirectory
        The folder into which database exports and track analysis files will be downloaded.
    • Method Detail

      • getRetryLimit

        @API(status=STABLE)
        public int getRetryLimit()
        Check how many times we will try to download a file from a player before giving up.
        Returns:
        the maximum number of attempts we will make when a file download fails
      • setRetryLimit

        @API(status=STABLE)
        public void setRetryLimit​(int limit)
        Set how many times we will try to download a file from a player before giving up.
        Parameters:
        limit - the maximum number of attempts we will make when a file download fails
      • isRunning

        @API(status=STABLE)
        public boolean isRunning()
        Check whether we are currently running.
        Returns:
        true if track metadata is being fetched using NFS for all active players
      • humanReadableByteCount

        @API(status=STABLE)
        public static String humanReadableByteCount​(long bytes,
                                                    boolean si)
        Format a number of bytes in a human-centric format. From Stack Overflow
        Parameters:
        bytes - the number of bytes
        si - {code @true} if we should use SI interpretation where k=1000
        Returns:
        the nicely readable summary string
      • canUseDatabase

        @API(status=EXPERIMENTAL)
        public boolean canUseDatabase​(SlotReference slot)
        Check whether we would be able to use a database read from the specified slot. Makes sure the device that owns the slot uses DeviceSQL track IDs, or that we know how to access SQLite databases if it doesn’t.
        Parameters:
        slot - the slot from which a track was loaded
        Returns:
        true if we will be able to read track metadata from a database downloaded from that slot
      • findDatabase

        @API(status=STABLE)
        public Database findDatabase​(DataReference reference)
        Find the database we have downloaded and parsed that can provide information about the supplied data reference, if any.
        Parameters:
        reference - identifies the location from which data is desired
        Returns:
        the appropriate rekordbox extract to start from in finding that data, if we have one
      • findDatabase

        @API(status=STABLE)
        public Database findDatabase​(SlotReference slot)
        Find the database we have downloaded and parsed that can provide information about the supplied slot reference, if any.
        Parameters:
        slot - identifies the slot from which data is desired
        Returns:
        the appropriate rekordbox extract to start from in finding that data, if we have one
      • findJdbcConnection

        @API(status=EXPERIMENTAL)
        public Connection findJdbcConnection​(DataReference reference)
        Find the JDBC connection, if any, we have opened to the SQLite (Device Library 2) database we downloaded that can provide information about the supplied data reference.
        Parameters:
        reference - identifies the location from which data is desired
        Returns:
        the appropriate JDBC connection to start from in finding that data, if we have one
      • findJdbcConnection

        @API(status=EXPERIMENTAL)
        public Connection findJdbcConnection​(SlotReference slot)
        Find the JDBC connection, if any, we have opened to the SQLite (Device Library 2) database we downloaded that can provide information about the supplied slot reference.
        Parameters:
        slot - identifies the location from which data is desired
        Returns:
        the appropriate JDBC connection to start from in finding that data, if we have one
      • logTrackAnalysis

        @API(status=EXPERIMENTAL)
        public void logTrackAnalysis​(DataReference track,
                                     String extension,
                                     String reason,
                                     File logDir)
                              throws IOException
        Capture a log copy of a track analysis for which a data problem has been identified, to assist in further research.
        Parameters:
        track - the track whose analysis file is to be logged
        extension - the file extension (such as ".DAT" or ".EXT") which identifies the type of file to be logged
        reason - a description of why the file is being logged, for the application log
        logDir - the directory into which the file should be logged
        Throws:
        IOException - if there is a problem copying the analysis file to the log directory
        IllegalArgumentException - if the track or its analysis file can't be found
      • start

        @API(status=STABLE)
        public void start()
                   throws Exception
        Start finding track metadata for all active players using the NFS server on the players to pull the exported database and track analysis files. Starts the MetadataFinder if it is not already running, because we build on its features. This will transitively start many of the other Beat Link subsystems, and stopping any of them will stop us as well.
        Throws:
        Exception - if there is a problem starting the required components
      • stop

        @API(status=STABLE)
        public void stop()
        Stop finding track metadata for all active players.
      • getInstance

        @API(status=STABLE)
        public static CrateDigger getInstance()
        Get the singleton instance of this class.
        Returns:
        the only instance of this class which exists.
      • addDatabaseListener

        @API(status=STABLE)
        public void addDatabaseListener​(DatabaseListener listener)
        Adds the specified database listener to receive updates when a DeviceSQL database has been obtained for a media slot, or when the underlying media for a database has been unmounted, so it is no longer relevant. If listener is null or already present in the set of registered listeners, no exception is thrown and no action is performed.

        To reduce latency, updates are delivered to listeners directly on the thread that is receiving packets from the network, so if you want to interact with user interface objects in listener methods, you need to use javax.swing.SwingUtilities.invokeLater(Runnable) to do so on the Event Dispatch Thread.

        Even if you are not interacting with user interface objects, any code in the listener method must finish quickly, or it will add latency for other listeners, and updates will back up. If you want to perform lengthy processing of any sort, do so on another thread.

        Parameters:
        listener - the database update listener to add
      • removeDatabaseListener

        @API(status=STABLE)
        public void removeDatabaseListener​(DatabaseListener listener)
        Removes the specified database listener so that it no longer receives updates when there are changes to the available set of DeviceSQL databases. If listener is null or not present in the set of registered listeners, no exception is thrown and no action is performed.
        Parameters:
        listener - the database update listener to remove
      • getDatabaseListeners

        @API(status=STABLE)
        public Set<DatabaseListener> getDatabaseListeners()
        Get the list of registered listeners for mounted DeviceSQL databases.
        Returns:
        an immutable copy of the list of currently-registered listeners.
      • addSQLiteListener

        @API(status=STABLE)
        public void addSQLiteListener​(SQLiteConnectionListener listener)
        Adds the specified database listener to receive updates when a rekordbox database has been obtained for a media slot, or when the underlying media for a database has been unmounted, so it is no longer relevant. If listener is null or already present in the set of registered listeners, no exception is thrown and no action is performed.

        To reduce latency, updates are delivered to listeners directly on the thread that is receiving packets from the network, so if you want to interact with user interface objects in listener methods, you need to use javax.swing.SwingUtilities.invokeLater(Runnable) to do so on the Event Dispatch Thread.

        Even if you are not interacting with user interface objects, any code in the listener method must finish quickly, or it will add latency for other listeners, and updates will back up. If you want to perform lengthy processing of any sort, do so on another thread.

        Parameters:
        listener - the database update listener to add
      • removeSQLiteListener

        @API(status=STABLE)
        public void removeSQLiteListener​(SQLiteConnectionListener listener)
        Removes the specified database listener so that it no longer receives updates when there are changes to the available set of rekordbox databases. If listener is null or not present in the set of registered listeners, no exception is thrown and no action is performed.
        Parameters:
        listener - the database update listener to remove
      • getSqlLiteListeners

        @API(status=STABLE)
        public Set<SQLiteConnectionListener> getSqlLiteListeners()
        Get the list of registered listeners for connections to SQLite databases.
        Returns:
        an immutable copy of the list of currently-registered listeners.