示例#1
0
  public static boolean canProgressiveOrIsComplete(TOTorrent torrent) {
    if (torrent == null) {
      return false;
    }
    try {
      DownloadManagerEnhancer enhancer = DownloadManagerEnhancer.getSingleton();
      EnhancedDownloadManager edm =
          DownloadManagerEnhancer.getSingleton().getEnhancedDownload(torrent.getHash());

      if (edm == null) {
        return enhancer.isProgressiveAvailable()
            && PlatformTorrentUtils.isContentProgressive(torrent);
      }

      boolean complete = edm.getDownloadManager().isDownloadComplete(false);
      if (complete) {
        return true;
      }

      // not complete
      if (!edm.supportsProgressiveMode()) {
        return false;
      }
    } catch (TOTorrentException e) {
      return false;
    }

    return true;
  }
示例#2
0
  public static boolean isContent(TOTorrent torrent, boolean requirePlatformTracker) {
    if (torrent == null) {
      return false;
    }
    boolean bContent = PlatformTorrentUtils.getContentHash(torrent) != null;
    if (!bContent || (bContent && !requirePlatformTracker)) {
      return bContent;
    }

    return isPlatformTracker(torrent);
  }
示例#3
0
 /**
  * @param torrent
  * @since 3.0.4.3
  */
 public static String getContentTitle2(DownloadManager dm) {
   if (dm == null) {
     return null;
   }
   // DM state's display name can be set by user, so show that if we have it
   String name = dm.getDownloadState().getDisplayName();
   if (name == null || name.length() == 0) {
     name = PlatformTorrentUtils.getContentTitle(dm.getTorrent());
     if (name == null) {
       name = dm.getDisplayName();
     }
   }
   return name;
 }
示例#4
0
  private static boolean canPlay(TOTorrent torrent, int file_index) {
    if (!PlatformTorrentUtils.isContent(torrent, false)) {
      return false;
    }

    if (!AzureusCoreFactory.isCoreRunning()) {
      return false;
    }

    GlobalManager gm = AzureusCoreFactory.getSingleton().getGlobalManager();
    DownloadManager dm = gm.getDownloadManager(torrent);

    if (dm != null) {
      return dm.getAssumedComplete() || canUseEMP(torrent, file_index);
    }
    return canUseEMP(torrent, file_index);
  }
示例#5
0
  private static void updateMetaData_handleReply(
      TOTorrent torrent, String hash, String replyType, Map mapHashes) {
    if (hash == null && torrent != null) {
      try {
        hash = torrent.getHashWrapper().toBase32String();
      } catch (Exception e) {
      }
    }

    GlobalManager gm = AzureusCoreFactory.getSingleton().getGlobalManager();
    DownloadManager dm = gm.getDownloadManager(new HashWrapper(Base32.decode(hash)));

    if (torrent == null && dm != null) {
      torrent = dm.getTorrent();
    }
    Map contentMap = PlatformTorrentUtils.getContentMap(torrent);

    final TOTorrent torrentFinal = torrent;

    if (replyType.equals(PlatformMessenger.REPLY_EXCEPTION)) {
      if (torrent != null) {
        // try again in a bit
        log(torrent, "Exception, retrying later");
        SimpleTimer.addEvent(
            "Update MD Retry",
            SystemTime.getCurrentTime() + RETRY_METADATA,
            new TimerEventPerformer() {
              public void perform(TimerEvent event) {
                log(torrentFinal, "retry time");
                PlatformTorrentUtils.updateMetaData(torrentFinal, 15000);
              }
            });
      }
    } else {
      Map jsonMapMetaData = hash == null ? null : (Map) mapHashes.get(hash);
      if (jsonMapMetaData != null) {
        long oldLastUpdated = getContentLastUpdated(torrent);
        long expireyMins = 0;

        for (Iterator iter = jsonMapMetaData.keySet().iterator(); iter.hasNext(); ) {
          String key = (String) iter.next();
          Object value = jsonMapMetaData.get(key);

          if (value == null || value.equals(null)) {
            contentMap.remove(key);
          } else if ((key.equals("Thumbnail") || key.endsWith(".B64")) && value instanceof String) {
            contentMap.put(key, Base64.decode((String) value));
          } else if (key.equals("expires-in-mins") && value instanceof Long) {
            expireyMins = ((Long) value).longValue();
          } else {
            contentMap.put(key, value);
          }
          writeTorrentIfExists(torrent);
        }

        // crappy way of updating the display name
        if (dm != null) {
          String title = PlatformTorrentUtils.getContentTitle(torrent);
          if (title != null
              && title.length() > 0
              && dm.getDownloadState().getDisplayName() == null) {
            dm.getDownloadState().setDisplayName(title);
          }
        }
        triggerMetaDataUpdateListeners(torrent);

        if (torrent != null) {
          // setup next refresh

          long refreshOn;
          if (expireyMins > 0) {
            refreshOn = SystemTime.getCurrentTime() + (expireyMins * 60 * 1000L);
          } else {
            long newLastUpdated = getContentLastUpdated(torrent);

            long diff = newLastUpdated - oldLastUpdated;
            log(
                torrent,
                "Last Updated: new "
                    + new Date(newLastUpdated)
                    + ";old "
                    + new Date(oldLastUpdated)
                    + ";diff="
                    + diff);
            if (diff > 0 && oldLastUpdated != 0) {
              diff *= 2;
              if (diff < MIN_MD_REFRESH_MS) {
                diff = MIN_MD_REFRESH_MS;
              } else if (diff > MAX_MD_REFRESH_MS) {
                diff = MAX_MD_REFRESH_MS;
              }
              refreshOn = SystemTime.getOffsetTime(diff);
            } else {
              refreshOn = SystemTime.getCurrentTime() + (7 * 24 * 60 * 60 * 1000L);
            }
          }

          log(torrent, "got MD. Next refresh in " + (refreshOn - SystemTime.getCurrentTime()));
          setMetaDataRefreshOn(torrent, refreshOn);
          SimpleTimer.addEvent(
              "Update MD",
              refreshOn,
              new TimerEventPerformer() {
                public void perform(TimerEvent event) {
                  PlatformTorrentUtils.updateMetaData(torrentFinal, 15000);
                }
              });
        }
      } else if (torrent != null) {
        long refreshOn = SystemTime.getCurrentTime() + (30 * 24 * 60 * 60 * 1000L);
        setMetaDataRefreshOn(torrent, refreshOn);
        log(torrent, "no hash in reply. Next refresh on " + new Date(refreshOn));
      }
    }
  }