long fingerprint = 0;
for (int i=0;i<downloads.length;i++){
Download download = downloads[i];
Torrent torrent = download.getTorrent();
if ( torrent == null ){
continue;
}
String dl_cat = download.getAttribute( ta_category );
if ( category.equalsIgnoreCase( "all" ) ||
( dl_cat != null && dl_cat.equals( category ))){
if ( !TorrentUtils.isReallyPrivate( PluginCoreUtils.unwrap( torrent ))){
selected_dls.add( download );
byte[] hash = torrent.getHash();
int num = (hash[0]<<24)&0xff000000 | (hash[1] << 16)&0x00ff0000 | (hash[2] << 8)&0x0000ff00 | hash[3]&0x000000ff;
fingerprint += num;
}
}
}
PluginConfig pc = plugin_interface.getPluginconfig();
String feed_finger_key = "feed_finger.category." + category;
String feed_date_key = "feed_date.category." + category;
long existing_fingerprint = pc.getPluginLongParameter( feed_finger_key, 0 );
long feed_date = pc.getPluginLongParameter( feed_date_key, 0 );
long now = SystemTime.getCurrentTime();
if ( existing_fingerprint == fingerprint ){
// update every now and then to pick up new peer/seed values
if ( selected_dls.size() > 0 ){
if ( now < feed_date ||
now - feed_date > FEED_UPDATE_MIN_MILLIS ){
feed_date = now;
pc.setPluginParameter( feed_date_key, feed_date );
}
}
}else{
pc.setPluginParameter( feed_finger_key, fingerprint );
// ensure feed date goes up
if ( now <= feed_date ){
feed_date++;
}else{
feed_date = now;
}
pc.setPluginParameter( feed_date_key, feed_date );
}
String last_modified = TimeFormatter.getHTTPDate( feed_date );
if ( if_mod != null && if_mod.equals( last_modified )){
return( new feedDetails( new byte[0], last_modified ));
}
ByteArrayOutputStream os = new ByteArrayOutputStream();
try{
PrintWriter pw = new PrintWriter(new OutputStreamWriter( os, "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( category ) + "</title>" );
Collections.sort(
selected_dls,
new Comparator<Download>()
{
public int
compare(
Download d1,
Download d2)
{
long added1 = getAddedTime( d1 )/1000;
long added2 = getAddedTime( d2 )/1000;
return((int)(added2 - added1 ));
}
});
pw.println( "<pubDate>" + last_modified + "</pubDate>" );
for (int i=0;i<selected_dls.size();i++){
Download download = (Download)selected_dls.get( i );
DownloadManager core_download = PluginCoreUtils.unwrap( download );
Torrent torrent = download.getTorrent();
String hash_str = Base32.encode( torrent.getHash());
pw.println( "<item>" );
pw.println( "<title>" + escape( download.getName()) + "</title>" );
pw.println( "<guid>" + hash_str + "</guid>" );
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>" );
String url = "azplug:?id=azbuddy&name=Friends&arg=";
String arg = "pk=" + getPublicKey() + "&cat=" + category + "&hash=" + Base32.encode(torrent.getHash());
url += URLEncoder.encode( arg, "UTF-8" );
pw.println( "<vuze:downloadurl>" + escape( 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>" );