use of com.biglybt.core.torrent.TOTorrent in project BiglyBT by BiglySoftware.
the class TorrentUIUtilsV3 method releaseContentImage.
public static void releaseContentImage(Object datasource) {
if (imageLoaderThumb == null) {
return;
}
TOTorrent torrent = DataSourceUtils.getTorrent(datasource);
if (torrent == null) {
return;
}
String thumbnailUrl = PlatformTorrentUtils.getContentThumbnailUrl(torrent);
if (thumbnailUrl != null) {
imageLoaderThumb.releaseImage(thumbnailUrl);
} else {
String hash = null;
try {
hash = torrent.getHashWrapper().toBase32String();
} catch (TOTorrentException e) {
}
if (hash == null) {
return;
}
String id = "Thumbnail." + hash + "." + torrent.getSize();
imageLoaderThumb.releaseImage(id);
}
}
use of com.biglybt.core.torrent.TOTorrent in project BiglyBT by BiglySoftware.
the class RelatedContentManager method getKeys.
private byte[][] getKeys(Download download) {
byte[] tracker_keys = null;
byte[] ws_keys = null;
try {
Torrent torrent = download.getTorrent();
if (torrent != null) {
TOTorrent to_torrent = PluginCoreUtils.unwrap(torrent);
Set<String> tracker_domains = new HashSet<>();
addURLToDomainKeySet(tracker_domains, to_torrent.getAnnounceURL());
TOTorrentAnnounceURLGroup group = to_torrent.getAnnounceURLGroup();
TOTorrentAnnounceURLSet[] sets = group.getAnnounceURLSets();
for (TOTorrentAnnounceURLSet set : sets) {
URL[] urls = set.getAnnounceURLs();
for (URL u : urls) {
addURLToDomainKeySet(tracker_domains, u);
}
}
tracker_keys = domainsToArray(tracker_domains, 8);
Set<String> ws_domains = new HashSet<>();
List getright = BDecoder.decodeStrings(getURLList(to_torrent, "url-list"));
List webseeds = BDecoder.decodeStrings(getURLList(to_torrent, "httpseeds"));
for (List l : new List[] { getright, webseeds }) {
for (Object o : l) {
if (o instanceof String) {
try {
addURLToDomainKeySet(ws_domains, new URL((String) o));
} catch (Throwable e) {
}
}
}
}
ws_keys = domainsToArray(ws_domains, 3);
}
} catch (Throwable e) {
}
return (new byte[][] { tracker_keys, ws_keys });
}
use of com.biglybt.core.torrent.TOTorrent in project BiglyBT by BiglySoftware.
the class RelatedContentManager method addDownloads.
protected void addDownloads(Download[] downloads, boolean initialising) {
synchronized (rcm_lock) {
List<DownloadInfo> new_info = new ArrayList<>(downloads.length);
for (Download download : downloads) {
try {
if (!download.isPersistent()) {
continue;
}
Torrent torrent = download.getTorrent();
if (torrent == null) {
continue;
}
byte[] hash = torrent.getHash();
if (download_info_map.containsKey(hash)) {
continue;
}
byte nets = getNetworks(download);
if (nets == NET_NONE) {
continue;
}
TOTorrent to_torrent = PluginCoreUtils.unwrap(torrent);
if (!(TorrentUtils.isReallyPrivate(to_torrent) || TorrentUtils.getFlag(to_torrent, TorrentUtils.TORRENT_FLAG_DISABLE_RCM))) {
DownloadManagerState state = PluginCoreUtils.unwrap(download).getDownloadState();
if (state.getFlag(DownloadManagerState.FLAG_LOW_NOISE) || state.getFlag(DownloadManagerState.FLAG_METADATA_DOWNLOAD)) {
continue;
}
LinkedList<DownloadInfo> download_infos1;
LinkedList<DownloadInfo> download_infos2;
if ((nets & NET_PUBLIC) != 0) {
download_infos1 = pub_download_infos1;
download_infos2 = pub_download_infos2;
} else {
download_infos1 = non_pub_download_infos1;
download_infos2 = non_pub_download_infos2;
}
int version = RelatedContent.VERSION_INITIAL;
long rand = global_random_id ^ state.getLongParameter(DownloadManagerState.PARAM_RANDOM_SEED);
int seeds_leechers;
int[] aggregate_seeds_leechers = getAggregateSeedsLeechers(state);
if (aggregate_seeds_leechers == null) {
long cache = state.getLongAttribute(DownloadManagerState.AT_SCRAPE_CACHE);
if (cache == -1) {
seeds_leechers = -1;
} else {
int seeds = (int) ((cache >> 32) & 0x00ffffff);
int leechers = (int) (cache & 0x00ffffff);
seeds_leechers = (int) ((seeds << 16) | (leechers & 0xffff));
}
} else {
version = RelatedContent.VERSION_BETTER_SCRAPE;
int seeds = aggregate_seeds_leechers[0];
int leechers = aggregate_seeds_leechers[1];
seeds_leechers = (int) ((seeds << 16) | (leechers & 0xffff));
}
byte[][] keys = getKeys(download);
int first_seen = (int) (state.getLongParameter(DownloadManagerState.PARAM_DOWNLOAD_ADDED_TIME) / 1000);
DownloadInfo info = new DownloadInfo(version, hash, hash, download.getName(), (int) rand, torrent.isPrivate() ? StringInterner.intern(torrent.getAnnounceURL().getHost()) : null, keys[0], keys[1], getTags(download), nets, first_seen, 0, false, torrent.getSize(), (int) (to_torrent.getCreationDate() / (60 * 60)), seeds_leechers);
new_info.add(info);
if (initialising || download_infos1.size() == 0) {
download_infos1.add(info);
} else {
download_infos1.add(RandomUtils.nextInt(download_infos1.size()), info);
}
download_infos2.add(info);
download_info_map.put(hash, info);
if (info.getTracker() != null) {
download_priv_set.add(getPrivateInfoKey(info));
}
}
} catch (Throwable e) {
Debug.out(e);
}
}
List<Map<String, Object>> history = (List<Map<String, Object>>) COConfigurationManager.getListParameter("rcm.dlinfo.history.privx", new ArrayList<Map<String, Object>>());
if (initialising) {
int padd = MAX_HISTORY - download_info_map.size();
for (int i = 0; i < history.size() && padd > 0; i++) {
try {
DownloadInfo info = deserialiseDI((Map<String, Object>) history.get(i), null);
if (info != null && !download_info_map.containsKey(info.getHash())) {
download_info_map.put(info.getHash(), info);
if (info.getTracker() != null) {
download_priv_set.add(getPrivateInfoKey(info));
}
byte nets = info.getNetworksInternal();
if (nets != NET_NONE) {
if ((nets & NET_PUBLIC) != 0) {
pub_download_infos1.add(info);
pub_download_infos2.add(info);
} else {
non_pub_download_infos1.add(info);
non_pub_download_infos2.add(info);
}
padd--;
}
}
} catch (Throwable e) {
}
}
Collections.shuffle(pub_download_infos1);
Collections.shuffle(non_pub_download_infos1);
} else {
if (new_info.size() > 0) {
final List<String> base32_hashes = new ArrayList<>();
for (DownloadInfo info : new_info) {
byte[] hash = info.getHash();
if (hash != null) {
base32_hashes.add(Base32.encode(hash));
}
Map<String, Object> map = serialiseDI(info, null);
if (map != null) {
history.add(map);
}
}
while (history.size() > MAX_HISTORY) {
history.remove(0);
}
COConfigurationManager.setParameter("rcm.dlinfo.history.privx", history);
if (base32_hashes.size() > 0) {
content_change_dispatcher.dispatch(new AERunnable() {
@Override
public void runSupport() {
List<RelatedContent> to_remove = new ArrayList<>();
synchronized (rcm_lock) {
ContentCache content_cache = loadRelatedContent();
for (String h : base32_hashes) {
DownloadInfo di = content_cache.related_content.get(h);
if (di != null) {
to_remove.add(di);
}
}
}
if (to_remove.size() > 0) {
delete(to_remove.toArray(new RelatedContent[to_remove.size()]));
}
}
});
}
}
}
}
}
use of com.biglybt.core.torrent.TOTorrent in project BiglyBT by BiglySoftware.
the class CategoryManagerImpl method generate.
@Override
public boolean generate(TrackerWebPageRequest request, TrackerWebPageResponse response) throws IOException {
URL url = request.getAbsoluteURL();
String path = url.getPath();
int pos = path.indexOf('?');
if (pos != -1) {
path = path.substring(0, pos);
}
path = path.substring(PROVIDER.length() + 1);
XMLEscapeWriter pw = new XMLEscapeWriter(new PrintWriter(new OutputStreamWriter(response.getOutputStream(), "UTF-8")));
pw.setEnabled(false);
if (path.length() <= 1) {
response.setContentType("text/html; charset=UTF-8");
pw.println("<HTML><HEAD><TITLE>" + Constants.APP_NAME + " Category Feeds</TITLE></HEAD><BODY>");
Map<String, String> lines = new TreeMap<>();
List<CategoryImpl> cats;
try {
categories_mon.enter();
cats = new ArrayList<>(categories.values());
} finally {
categories_mon.exit();
}
for (CategoryImpl c : cats) {
if (c.getBooleanAttribute(Category.AT_RSS_GEN)) {
String name = getDisplayName(c);
String cat_url = PROVIDER + "/" + URLEncoder.encode(c.getName(), "UTF-8");
lines.put(name, "<LI><A href=\"" + cat_url + "\">" + name + "</A></LI>");
}
}
for (String line : lines.values()) {
pw.println(line);
}
pw.println("</BODY></HTML>");
} else {
String cat_name = URLDecoder.decode(path.substring(1), "UTF-8");
CategoryImpl cat;
try {
categories_mon.enter();
cat = categories.get(cat_name);
} finally {
categories_mon.exit();
}
if (cat == null) {
response.setReplyStatus(404);
return (true);
}
List<DownloadManager> dms = cat.getDownloadManagers(CoreFactory.getSingleton().getGlobalManager().getDownloadManagers());
List<Download> downloads = new ArrayList<>(dms.size());
long dl_marker = 0;
for (DownloadManager dm : dms) {
TOTorrent torrent = dm.getTorrent();
if (torrent == null) {
continue;
}
if (!TorrentUtils.isReallyPrivate(torrent)) {
dl_marker += dm.getDownloadState().getLongParameter(DownloadManagerState.PARAM_DOWNLOAD_ADDED_TIME);
downloads.add(PluginCoreUtils.wrap(dm));
}
}
String config_key = "cat.rss.config." + Base32.encode(cat.getName().getBytes("UTF-8"));
long old_marker = COConfigurationManager.getLongParameter(config_key + ".marker", 0);
long last_modified = COConfigurationManager.getLongParameter(config_key + ".last_mod", 0);
long now = SystemTime.getCurrentTime();
if (old_marker == dl_marker) {
if (last_modified == 0) {
last_modified = now;
}
} else {
COConfigurationManager.setParameter(config_key + ".marker", dl_marker);
last_modified = now;
}
if (last_modified == now) {
COConfigurationManager.setParameter(config_key + ".last_mod", last_modified);
}
response.setContentType("application/xml; charset=UTF-8");
pw.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
pw.println("<rss version=\"2.0\" xmlns:vuze=\"http://www.vuze.com\">");
pw.println("<channel>");
pw.println("<title>" + escape(getDisplayName(cat)) + "</title>");
Collections.sort(downloads, new Comparator<Download>() {
@Override
public int compare(Download d1, Download d2) {
long added1 = getAddedTime(d1) / 1000;
long added2 = getAddedTime(d2) / 1000;
return ((int) (added2 - added1));
}
});
pw.println("<pubDate>" + TimeFormatter.getHTTPDate(last_modified) + "</pubDate>");
for (int i = 0; i < downloads.size(); i++) {
Download download = downloads.get(i);
DownloadManager core_download = PluginCoreUtils.unwrap(download);
Torrent torrent = download.getTorrent();
byte[] hash = torrent.getHash();
String hash_str = Base32.encode(hash);
pw.println("<item>");
pw.println("<title>" + escape(download.getName()) + "</title>");
pw.println("<guid>" + hash_str + "</guid>");
String magnet_url = escape(UrlUtils.getMagnetURI(download));
pw.println("<link>" + magnet_url + "</link>");
long added = core_download.getDownloadState().getLongParameter(DownloadManagerState.PARAM_DOWNLOAD_ADDED_TIME);
pw.println("<pubDate>" + TimeFormatter.getHTTPDate(added) + "</pubDate>");
pw.println("<vuze:size>" + torrent.getSize() + "</vuze:size>");
pw.println("<vuze:assethash>" + hash_str + "</vuze:assethash>");
pw.println("<vuze:downloadurl>" + magnet_url + "</vuze:downloadurl>");
DownloadScrapeResult scrape = download.getLastScrapeResult();
if (scrape != null && scrape.getResponseType() == DownloadScrapeResult.RT_SUCCESS) {
pw.println("<vuze:seeds>" + scrape.getSeedCount() + "</vuze:seeds>");
pw.println("<vuze:peers>" + scrape.getNonSeedCount() + "</vuze:peers>");
}
pw.println("</item>");
}
pw.println("</channel>");
pw.println("</rss>");
}
pw.flush();
return (true);
}
use of com.biglybt.core.torrent.TOTorrent in project BiglyBT by BiglySoftware.
the class ActivitiesEntry method createSelectedContentObject.
public SelectedContent createSelectedContentObject() throws Exception {
SelectedContent sc = new SelectedContent();
if (assetHash == null) {
// Contains no content
return sc;
}
dm = getDownloadManger();
if (dm != null) {
sc.setDisplayName(PlatformTorrentUtils.getContentTitle2(dm));
sc.setDownloadManager(dm);
return sc;
} else {
if (torrent != null) {
sc.setTorrent(torrent);
}
}
sc.setDisplayName(getTorrentName());
if (sc.getDisplayName() == null) {
TOTorrent torrent = getTorrent();
if (torrent != null) {
sc.setDisplayName(TorrentUtils.getLocalisedName(torrent));
sc.setHash(torrent.getHashWrapper().toBase32String());
}
}
if (sc.getHash() == null) {
if (assetHash != null) {
sc.setHash(assetHash);
}
}
return sc;
}
Aggregations