From: <Dam...@us...> - 2007-07-29 19:58:11
|
Revision: 1478 http://azsmrc.svn.sourceforge.net/azsmrc/?rev=1478&view=rev Author: Damokles Date: 2007-07-29 12:58:11 -0700 (Sun, 29 Jul 2007) Log Message: ----------- Added Scraper and ScrapeResult, updated ITorrent with getAnnounceURL() and getInfoHash() added minSeeds and minLeecher requirements to filter modified the filterListener to respect them Not Tested TODO: Marc update the gui with the new filter options Modified Paths: -------------- azsmrcplugins/trunk/lbms/plugins/scanerss/azsmrc/TorrentAdapter.java azsmrcplugins/trunk/lbms/plugins/scanerss/azureus/ScanerssAzPlugin.java azsmrcplugins/trunk/lbms/plugins/scanerss/azureus/TorrentAdapter.java azsmrcplugins/trunk/lbms/plugins/scanerss/main/Filter.java azsmrcplugins/trunk/lbms/plugins/scanerss/main/GUI.java azsmrcplugins/trunk/lbms/plugins/scanerss/main/ITorrent.java azsmrcplugins/trunk/lbms/plugins/scanerss/main/TestRss.java Added Paths: ----------- azsmrcplugins/trunk/lbms/plugins/scanerss/main/ScrapeResult.java azsmrcplugins/trunk/lbms/plugins/scanerss/main/Scraper.java Modified: azsmrcplugins/trunk/lbms/plugins/scanerss/azsmrc/TorrentAdapter.java =================================================================== --- azsmrcplugins/trunk/lbms/plugins/scanerss/azsmrc/TorrentAdapter.java 2007-07-29 15:24:34 UTC (rev 1477) +++ azsmrcplugins/trunk/lbms/plugins/scanerss/azsmrc/TorrentAdapter.java 2007-07-29 19:58:11 UTC (rev 1478) @@ -1,8 +1,10 @@ package lbms.plugins.scanerss.azsmrc; import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import lbms.azsmrc.remote.client.torrent.TOTorrent; +import lbms.azsmrc.remote.client.torrent.TOTorrentException; import lbms.azsmrc.remote.client.torrent.TOTorrentFile; import lbms.plugins.scanerss.main.ITorrent; import lbms.plugins.scanerss.main.ITorrentFile; @@ -57,4 +59,27 @@ return torrent; } + /* (non-Javadoc) + * @see lbms.plugins.scanerss.main.ITorrent#getAnnounceUrl() + */ + public String getAnnounceUrl() { + return torrent.getAnnounceURL().toExternalForm(); + } + + /* (non-Javadoc) + * @see lbms.plugins.scanerss.main.ITorrent#getInfoHash() + */ + public String getInfoHash() { + try { + return URLEncoder.encode( + new String(torrent.getHash(), "ISO-8859-1"), + "ISO-8859-1").replaceAll("\\+", "%20"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } catch (TOTorrentException e) { + e.printStackTrace(); + } + return ""; + } + } Modified: azsmrcplugins/trunk/lbms/plugins/scanerss/azureus/ScanerssAzPlugin.java =================================================================== --- azsmrcplugins/trunk/lbms/plugins/scanerss/azureus/ScanerssAzPlugin.java 2007-07-29 15:24:34 UTC (rev 1477) +++ azsmrcplugins/trunk/lbms/plugins/scanerss/azureus/ScanerssAzPlugin.java 2007-07-29 19:58:11 UTC (rev 1478) @@ -52,7 +52,7 @@ private View myView = null; private Logger logger; private LoggerChannel logChannel; - ScheduledExecutorService scheduler = + private ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1,new ThreadFactory() { public Thread newThread(Runnable r) { Thread t = new Thread(r); Modified: azsmrcplugins/trunk/lbms/plugins/scanerss/azureus/TorrentAdapter.java =================================================================== --- azsmrcplugins/trunk/lbms/plugins/scanerss/azureus/TorrentAdapter.java 2007-07-29 15:24:34 UTC (rev 1477) +++ azsmrcplugins/trunk/lbms/plugins/scanerss/azureus/TorrentAdapter.java 2007-07-29 19:58:11 UTC (rev 1478) @@ -1,11 +1,14 @@ package lbms.plugins.scanerss.azureus; -import org.gudy.azureus2.plugins.torrent.Torrent; -import org.gudy.azureus2.plugins.torrent.TorrentFile; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import lbms.plugins.scanerss.main.ITorrent; import lbms.plugins.scanerss.main.ITorrentFile; +import org.gudy.azureus2.plugins.torrent.Torrent; +import org.gudy.azureus2.plugins.torrent.TorrentFile; + /** * @author Damokles * @@ -50,4 +53,24 @@ public Torrent getTorrent() { return torrent; } + + /* (non-Javadoc) + * @see lbms.plugins.scanerss.main.ITorrent#getAnnounceUrl() + */ + public String getAnnounceUrl() { + return torrent.getAnnounceURL().toExternalForm(); + } + + /* (non-Javadoc) + * @see lbms.plugins.scanerss.main.ITorrent#getInfoHash() + */ + public String getInfoHash() { + try { + return URLEncoder.encode( + new String(torrent.getHash(), "ISO-8859-1"), + "ISO-8859-1").replaceAll("\\+", "%20"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } return ""; + } } Modified: azsmrcplugins/trunk/lbms/plugins/scanerss/main/Filter.java =================================================================== --- azsmrcplugins/trunk/lbms/plugins/scanerss/main/Filter.java 2007-07-29 15:24:34 UTC (rev 1477) +++ azsmrcplugins/trunk/lbms/plugins/scanerss/main/Filter.java 2007-07-29 19:58:11 UTC (rev 1478) @@ -31,6 +31,8 @@ private boolean runOnce; private long minSize = -1; private long maxSize = -1; + private int minSeeds = -1; + private int minLeecher = -1; private String category; private String outputDir; private DownloadState initialState = DownloadState.DEFAULT; @@ -90,6 +92,12 @@ if (e.getAttribute("maxSize") != null) { maxSize = Long.parseLong(e.getAttributeValue("maxSize")); } + if (e.getAttribute("minSeeds") != null) { + minSeeds = Integer.parseInt(e.getAttributeValue("minSeeds")); + } + if (e.getAttribute("minLeecher") != null) { + minLeecher = Integer.parseInt(e.getAttributeValue("minLeecher")); + } } /** @@ -194,8 +202,14 @@ e.setAttribute("pattern", getPatternString()); e.setAttribute("active", Boolean.toString(active)); e.setAttribute("runOnce", Boolean.toString(runOnce)); - e.setAttribute("minSize", Long.toString(minSize)); - e.setAttribute("maxSize", Long.toString(maxSize)); + if (minSize > 0) + e.setAttribute("minSize", Long.toString(minSize)); + if (maxSize > 0) + e.setAttribute("maxSize", Long.toString(maxSize)); + if (minSeeds > 0) + e.setAttribute("minSeeds", Integer.toString(minSeeds)); + if (minLeecher > 0) + e.setAttribute("minLeecher", Integer.toString(minLeecher)); if (denyPattern != null) e.setAttribute("denyPattern", getDenyPatternString()); e.setAttribute("id",Integer.toString(getId())); @@ -477,6 +491,35 @@ this.maxSize = maxSize; } + /** + * @return the minSeeds + */ + public int getMinSeeds() { + return minSeeds; + } + + /** + * @param minSeeds the minSeeds to set + */ + public void setMinSeeds(int minSeeds) { + this.minSeeds = minSeeds; + } + + /** + * @return the minLeecher + */ + public int getMinLeecher() { + return minLeecher; + } + + /** + * @param minLeecher the minLeecher to set + */ + public void setMinLeecher(int minLeecher) { + this.minLeecher = minLeecher; + } + + public static enum DownloadState { DEFAULT, QUEUED, STOPPED, FORCEDSTART; } Modified: azsmrcplugins/trunk/lbms/plugins/scanerss/main/GUI.java =================================================================== --- azsmrcplugins/trunk/lbms/plugins/scanerss/main/GUI.java 2007-07-29 15:24:34 UTC (rev 1477) +++ azsmrcplugins/trunk/lbms/plugins/scanerss/main/GUI.java 2007-07-29 19:58:11 UTC (rev 1478) @@ -147,22 +147,42 @@ if (actionProvider.isAddTorrentSupported()) { try { ITorrent torrent = actionProvider.getTorrent (item); + boolean addOK = true; if (item.getParentFilter().getMinSize() == -1 || item.getParentFilter().getMinSize() <= torrent.getSize()) { - if (item.getParentFilter().getMaxSize() == -1 - || item.getParentFilter().getMaxSize() >= torrent.getSize()) { - - actionProvider.addTorrent(item, torrent); - - } else { + if (item.getParentFilter().getMaxSize() > 0 + && item.getParentFilter().getMaxSize() < torrent.getSize()) { actionProvider.log(ActionProvider.LOG_DEBUG, item.getTitle()+" failed maxSize restriction "+torrent.getSize()+" > "+item.getParentFilter().getMaxSize()); + addOK = false; } - } else { actionProvider.log(ActionProvider.LOG_DEBUG, item.getTitle()+" failed minSize requirement "+torrent.getSize()+" < "+item.getParentFilter().getMinSize()); + addOK = false; } + if (addOK && (item.getParentFilter().getMinSeeds() > 0 || item.getParentFilter().getMinLeecher() > 0)) { + ScrapeResult sr = Scraper.scrapeTorrent(torrent); + if (sr != null) { + if (sr.hasFailed()) { + actionProvider.log(ActionProvider.LOG_DEBUG, "Couldn't Scrape "+item.getTitle() + ", ignoring Seed/Leecher rules. ["+sr.getFailureReason()+"]"); + } else { + if (item.getParentFilter().getMinSeeds() > 0 && sr.getSeeds() < item.getParentFilter().getMinSeeds()) { + actionProvider.log(ActionProvider.LOG_DEBUG, item.getTitle()+" failed minSeeds requirement "+sr.getSeeds()+" < "+item.getParentFilter().getMinSeeds()); + addOK = false; + } else if (item.getParentFilter().getMinLeecher() > 0 && sr.getLeechers() < item.getParentFilter().getMinLeecher()) { + actionProvider.log(ActionProvider.LOG_DEBUG, item.getTitle()+" failed minLeecher requirement "+sr.getLeechers()+" < "+item.getParentFilter().getMinLeecher()); + } + } + } else { + actionProvider.log(ActionProvider.LOG_DEBUG, "Couldn't Scrape "+item.getTitle() + ", ignoring Seed/Leecher rules."); + } + } + + if (addOK) { + actionProvider.addTorrent(item, torrent); + } + } catch (IOException e) { e.printStackTrace(); } Modified: azsmrcplugins/trunk/lbms/plugins/scanerss/main/ITorrent.java =================================================================== --- azsmrcplugins/trunk/lbms/plugins/scanerss/main/ITorrent.java 2007-07-29 15:24:34 UTC (rev 1477) +++ azsmrcplugins/trunk/lbms/plugins/scanerss/main/ITorrent.java 2007-07-29 19:58:11 UTC (rev 1478) @@ -8,5 +8,7 @@ public long getSize(); public String getName(); + public String getAnnounceUrl(); + public String getInfoHash(); public ITorrentFile[] getFiles(); } Added: azsmrcplugins/trunk/lbms/plugins/scanerss/main/ScrapeResult.java =================================================================== --- azsmrcplugins/trunk/lbms/plugins/scanerss/main/ScrapeResult.java (rev 0) +++ azsmrcplugins/trunk/lbms/plugins/scanerss/main/ScrapeResult.java 2007-07-29 19:58:11 UTC (rev 1478) @@ -0,0 +1,86 @@ +package lbms.plugins.scanerss.main; + +import java.io.UnsupportedEncodingException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * @author Damokles + * + */ +public class ScrapeResult { + private String scrapeUrl = ""; + private long seeds, leechers; + + private boolean failure = false; + + private String failureReason = ""; + + public ScrapeResult (byte[] scrapeData) { + try { + String data = new String (scrapeData, "ISO-8859-1"); + if (data.contains("failure reason")) { + failure = true; + Pattern fr = Pattern.compile("14:failure reason\\d+:(.*?)\\d+:", Pattern.CASE_INSENSITIVE); + Matcher m = fr.matcher(data); + if (m.find()) { + failureReason = m.group(1); + } + + } else { + Pattern cp = Pattern.compile(":completei(\\d)+e", Pattern.CASE_INSENSITIVE); + Pattern icp = Pattern.compile(":incompletei(\\d)+e", Pattern.CASE_INSENSITIVE); + Matcher m = cp.matcher(data); + if (m.find()) { + seeds = Long.parseLong(m.group(1)); + } + m = icp.matcher(data); + if (m.find()) { + leechers = Long.parseLong(m.group(1)); + } + } + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + } + + public ScrapeResult (String scrapeURL, byte[] scrapeData) { + this(scrapeData); + this.scrapeUrl = scrapeURL; + } + + /** + * @return Returns the leechers. + */ + public long getLeechers() { + return leechers; + } + + /** + * @return Returns the seeds. + */ + public long getSeeds() { + return seeds; + } + + /** + * @return Returns the failure. + */ + public boolean hasFailed() { + return failure; + } + + /** + * @return Returns the failureReason. + */ + public String getFailureReason() { + return failureReason; + } + + /** + * @return Returns the scrapeUrl. + */ + public String getScrapeUrl() { + return scrapeUrl; + } +} Added: azsmrcplugins/trunk/lbms/plugins/scanerss/main/Scraper.java =================================================================== --- azsmrcplugins/trunk/lbms/plugins/scanerss/main/Scraper.java (rev 0) +++ azsmrcplugins/trunk/lbms/plugins/scanerss/main/Scraper.java 2007-07-29 19:58:11 UTC (rev 1478) @@ -0,0 +1,34 @@ +package lbms.plugins.scanerss.main; + +import java.net.URL; + +import lbms.tools.HTTPDownload; + +/** + * @author Damokles + * + */ +public class Scraper { + public static ScrapeResult scrapeTorrent (ITorrent torrent) { + String scrapeURL = torrent.getAnnounceUrl(); + if (scrapeURL.lastIndexOf('/') != scrapeURL.indexOf("announce")-1 ) return null; + char first_separator = scrapeURL.indexOf('?') == -1 ? '?' : '&'; + scrapeURL = scrapeURL.replace("announce", "scrape"); + scrapeURL += first_separator+"info_hash="+torrent.getInfoHash()+"&peer_id=Scraper_"+Long.toString(System.currentTimeMillis()%1000000000000l); +// System.out.println(scrapeURL); + try { + URL realScrapeURL = new URL (scrapeURL); + HTTPDownload dl = new HTTPDownload(realScrapeURL); + dl.run(); + if (dl.hasFailed()) { + return null; + } else { + byte[] scrapeRes = dl.getBuffer().toString().getBytes("ISO-8859-1"); + return new ScrapeResult(scrapeURL,scrapeRes); + } + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } +} Modified: azsmrcplugins/trunk/lbms/plugins/scanerss/main/TestRss.java =================================================================== --- azsmrcplugins/trunk/lbms/plugins/scanerss/main/TestRss.java 2007-07-29 15:24:34 UTC (rev 1477) +++ azsmrcplugins/trunk/lbms/plugins/scanerss/main/TestRss.java 2007-07-29 19:58:11 UTC (rev 1478) @@ -1,5 +1,5 @@ /** - * + * */ package lbms.plugins.scanerss.main; @@ -37,6 +37,94 @@ Shell shell = new Shell (display); shell.setLayout(new GridLayout(1,false)); final GUI gui = new GUI(); + gui.actionProvider = new ActionProvider() { + /* (non-Javadoc) + * @see lbms.plugins.scanerss.main.ActionProvider#getConfigValue(java.lang.String) + */ + @Override + public String getConfigValue(String key) { + // TODO Auto-generated method stub + return null; + } + /* (non-Javadoc) + * @see lbms.plugins.scanerss.main.ActionProvider#setConfigValue(java.lang.String, java.lang.String) + */ + @Override + public void setConfigValue(String key, String value) { + // TODO Auto-generated method stub + + } + /* (non-Javadoc) + * @see lbms.plugins.scanerss.main.ActionProvider#saveRSSDataImpl() + */ + @Override + protected void saveRSSDataImpl() { + // TODO Auto-generated method stub + + } + /* (non-Javadoc) + * @see lbms.plugins.scanerss.main.ActionProvider#isAddTorrentSupported() + */ + @Override + public boolean isAddTorrentSupported() { + // TODO Auto-generated method stub + return true; + } + /* (non-Javadoc) + * @see lbms.plugins.scanerss.main.ActionProvider#getTorrent(lbms.plugins.scanerss.main.RSSItem) + */ + @Override + public ITorrent getTorrent(RSSItem item) throws IOException { + // TODO Auto-generated method stub + return new ITorrent() { + /* (non-Javadoc) + * @see lbms.plugins.scanerss.main.ITorrent#getFiles() + */ + public ITorrentFile[] getFiles() { + // TODO Auto-generated method stub + return null; + } + /* (non-Javadoc) + * @see lbms.plugins.scanerss.main.ITorrent#getName() + */ + public String getName() { + // TODO Auto-generated method stub + return null; + } + /* (non-Javadoc) + * @see lbms.plugins.scanerss.main.ITorrent#getSize() + */ + public long getSize() { + // TODO Auto-generated method stub + return 10485760; + } + /* (non-Javadoc) + * @see lbms.plugins.scanerss.main.ITorrent#getAnnounceUrl() + */ + public String getAnnounceUrl() { + // TODO Auto-generated method stub + return null; + } + /* (non-Javadoc) + * @see lbms.plugins.scanerss.main.ITorrent#getInfoHash() + */ + public String getInfoHash() { + // TODO Auto-generated method stub + return null; + } + }; + } + + /* (non-Javadoc) + * @see lbms.plugins.scanerss.main.ActionProvider#addTorrent(lbms.plugins.scanerss.main.RSSItem, lbms.plugins.scanerss.main.ITorrent) + */ + @Override + public void addTorrent(RSSItem item, ITorrent torrent) { + // TODO Auto-generated method stub + super.addTorrent(item, torrent); + System.out.println(item+" was added"); + } + }; try { File xml = new File("rss.xml"); if (xml.exists()) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |