Ejemplo n.º 1
0
 public String getTitle() {
   Log.getInstance().write(Log.LOGLEVEL_TRACE, "DT: getTitle.");
   if (CurrentlyRecording == null) {
     return null;
   }
   return CurrentlyRecording.getRSSItemTitle();
 }
Ejemplo n.º 2
0
 public Long getCurrentDownloadSize() {
   Log.getInstance().write(Log.LOGLEVEL_VERBOSE, "DT: getCurrentDownloadSize.");
   if (CurrentlyRecording == null) {
     return 0L;
   } else {
     return CurrentlyRecording.getBlocksRecorded() * RecordingEpisode.BLOCK_SIZE;
   }
 }
Ejemplo n.º 3
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.º 4
0
 void showCurrentlyRecording(RecordingEpisode currentlyRecording) {
   currentlyRecording.show();
 }
Ejemplo n.º 5
0
 public void abortCurrentDownload() {
   Log.getInstance().write(Log.LOGLEVEL_TRACE, "DT: Aborting current download.");
   if (CurrentlyRecording != null) CurrentlyRecording.abortCurrentDownload();
 }