Ejemplo n.º 1
0
 /**
  * Returns the number of items in the download queue. Does NOT include the currently downloading
  * item, if any.
  *
  * <p>
  *
  * @return The number of items in the download queue.
  */
 public Integer getNumberOfQueuedItems() {
   Log.getInstance().write(Log.LOGLEVEL_TRACE, "DT: getNumberOfItems.");
   return RecordingMaps.size();
 }
Ejemplo n.º 2
0
  /** The main thread that does all of the downloading. */
  @Override
  public void run() {
    Log.getInstance().write(Log.LOGLEVEL_TRACE, "DT: Starting.");

    Thread.currentThread().setName("DownloadThread");

    while (!stop) {

      // Get the first item in the queue and then remove it from the queue.
      try {
        CurrentlyRecording = RecordingMaps.take();
      } catch (InterruptedException e) {
        Log.getInstance().write(Log.LOGLEVEL_WARN, "DT: Interrupted.  Terminating.");
        return;
      }

      Log.getInstance().write(Log.LOGLEVEL_TRACE, "DT: Have work to do.");

      showCurrentlyRecording(CurrentlyRecording);

      // Make sure we have enough parameters.
      if (!CurrentlyRecording.isComplete()) {
        Log.getInstance().write(Log.LOGLEVEL_ERROR, "DT: Not enough parameters.");
        CurrentlyRecording.failed();
        continue;
      }

      DownloadManager.getInstance().setCurrentlyRecordingID(CurrentlyRecording.getRequestID());

      // Get all of the RSSItems for the Feed Context.
      List<RSSItem> RSSItems = CurrentlyRecording.getRSSItems();
      if (RSSItems == null) {
        Log.getInstance().write(Log.LOGLEVEL_ERROR, "DT: null RSSItems.");
        CurrentlyRecording.failed();
        continue;
      }

      Log.getInstance()
          .write(Log.LOGLEVEL_TRACE, "DT: Found episodes for podcast = " + RSSItems.size());

      if (RSSItems.isEmpty()) {
        Log.getInstance().write(Log.LOGLEVEL_ERROR, "DT: No RSSItems.");
        CurrentlyRecording.failed();
        continue;
      }

      // Get the one ChanItem (RSSItem) we are interested in.
      RSSItem ChanItem =
          CurrentlyRecording.getItemForID(RSSItems, CurrentlyRecording.getEpisodeID());
      if (ChanItem == null) {
        Log.getInstance().write(Log.LOGLEVEL_ERROR, "DT: null ChanItem.");
        CurrentlyRecording.failed();
        continue;
      }

      // Set the ChanItem.
      CurrentlyRecording.setChanItem(ChanItem);

      // Set the fileExt instance variable.
      CurrentlyRecording.setFileExt();

      // Create the tempfile where the episode will be downloaded to.
      if (!CurrentlyRecording.setTempFile()) {
        Log.getInstance().write(Log.LOGLEVEL_ERROR, "DT: Failed to setTempFile.");
        CurrentlyRecording.failed();
        continue;
      }

      // Download the episode to the tempfile.
      if (!CurrentlyRecording.download()) {
        Log.getInstance().write(Log.LOGLEVEL_ERROR, "DT: download failed.");
        CurrentlyRecording.failed();
        continue;
      }

      // Check for 0 size download.
      if (CurrentlyRecording.isZeroSizeDownload()) {
        Log.getInstance().write(Log.LOGLEVEL_WARN, "DT: File is 0 bytes long.");
        CurrentlyRecording.failed();
        continue;
      }

      // Move the tempfile to the final location and rename it to the final name.
      if (!CurrentlyRecording.moveToFinalLocation()) {
        Log.getInstance().write(Log.LOGLEVEL_ERROR, "DT: moveToFinalLocation failed.");
        CurrentlyRecording.failed();
        continue;
      }

      // Import the episode into the Sage database as an imported media file.
      if (CurrentlyRecording.importAsAiring() == null) {
        Log.getInstance().write(Log.LOGLEVEL_ERROR, "DT: importAsMediaFile failed.");
        CurrentlyRecording.failed();
        continue;
      }

      // Force Episode to update it's Airing information.
      int AiringID = CurrentlyRecording.getAiringID();

      // It worked.
      Log.getInstance().write(Log.LOGLEVEL_TRACE, "DT: Completed successfully.");
      CurrentlyRecording.completed();
      CurrentlyRecording = null;
    } // While !stop

    Log.getInstance().write(Log.LOGLEVEL_TRACE, "DT: Fatal error. Ending.");
  } // Run
Ejemplo n.º 3
0
 /**
  * Add an item to be downloaded. Details to follow....
  *
  * <p>
  *
  * @param info an array of strings ....
  * @return true if it succeeded, false otherwise.
  */
 public boolean addItem(RecordingEpisode episode) {
   Log.getInstance().write(Log.LOGLEVEL_TRACE, "DT: addItem.");
   return RecordingMaps.add(episode);
 }
Ejemplo n.º 4
0
 public void removeItem(RecordingEpisode episode) {
   if (!RecordingMaps.remove(episode)) {
     Log.getInstance()
         .write(Log.LOGLEVEL_ERROR, "DT: Failed to remove episode from RecordingMaps.");
   }
 }