From: <ar...@us...> - 2007-03-06 19:10:37
|
Revision: 3748 http://svn.sourceforge.net/phex/?rev=3748&view=rev Author: arnebab Date: 2007-03-06 11:10:33 -0800 (Tue, 06 Mar 2007) Log Message: ----------- Added metalink import. Thanks to lokad! Modified Paths: -------------- phex/trunk/changelog.txt phex/trunk/src/phex/download/swarming/SWDownloadFile.java phex/trunk/src/phex/download/swarming/SwarmingManager.java phex/trunk/src/phex/gui/dialogs/NewDownloadDialog.java phex/trunk/src/phex/gui/dialogs/options/DownloadPane.java phex/trunk/src/phex/metalink/DMetalink.java phex/trunk/src/phex/metalink/MetalinkSAXHandler.java phex/trunk/src/phex/metalink/MetalinkUtils.java phex/trunk/src/phex/prefs/OldCfg.java phex/trunk/src/phex/prefs/core/DownloadPrefs.java phex/trunk/src/phex/prefs/core/PhexCorePrefs.java phex/trunk/src/phex/resources/Lang.properties phex/trunk/src/phex/resources/Lang_de_DE.properties phex/trunk/src/phex/resources/metalinkSharedFilesXMLExport.xsl phex/trunk/src/phex/utils/InternalFileHandler.java Modified: phex/trunk/changelog.txt =================================================================== --- phex/trunk/changelog.txt 2007-03-06 18:42:33 UTC (rev 3747) +++ phex/trunk/changelog.txt 2007-03-06 19:10:33 UTC (rev 3748) @@ -1,3 +1,4 @@ +- CORE: Added metalink import. Thanks to lokad! - GUI: User can select to include a freebase url in Exported file-lists (magma, rss, metalink). Modified: phex/trunk/src/phex/download/swarming/SWDownloadFile.java =================================================================== --- phex/trunk/src/phex/download/swarming/SWDownloadFile.java 2007-03-06 18:42:33 UTC (rev 3747) +++ phex/trunk/src/phex/download/swarming/SWDownloadFile.java 2007-03-06 19:10:33 UTC (rev 3748) @@ -1696,6 +1696,12 @@ InternalFileHandler.magmaReadout( destFile ); } + if ( DownloadPrefs.AutoReadoutMetalinkFiles.get().booleanValue() + && destFile.getName().endsWith(".metalink") ) + { + InternalFileHandler.metalinkReadout( destFile ); + } + // Interprets a downloaded rss-feed in Phex automatically. // TODO should we honor the content type? if ( DownloadPrefs.AutoReadoutRSSFiles.get().booleanValue() Modified: phex/trunk/src/phex/download/swarming/SwarmingManager.java =================================================================== --- phex/trunk/src/phex/download/swarming/SwarmingManager.java 2007-03-06 18:42:33 UTC (rev 3747) +++ phex/trunk/src/phex/download/swarming/SwarmingManager.java 2007-03-06 19:10:33 UTC (rev 3748) @@ -368,24 +368,7 @@ return downloadFile; } - public synchronized void addMagmaToDownload( File magmaFile ) //Is this still used anywhere? - throws URIException, IOException - { - BufferedInputStream inStream = new BufferedInputStream( - new FileInputStream( magmaFile ) ); - MagmaParser parser = new MagmaParser( inStream ); - parser.start(); - List magnetList = parser.getMagnets(); - Iterator iter = magnetList.iterator(); - while (iter.hasNext()) - { - String magnet = (String) iter.next(); - URI uri = new URI( magnet, true ); - addFileToDownload( uri, true ); - } - } - /** * Removes the download file from the download list. Stops all running downlads * and deletes all incomplete download files. Modified: phex/trunk/src/phex/gui/dialogs/NewDownloadDialog.java =================================================================== --- phex/trunk/src/phex/gui/dialogs/NewDownloadDialog.java 2007-03-06 18:42:33 UTC (rev 3747) +++ phex/trunk/src/phex/gui/dialogs/NewDownloadDialog.java 2007-03-06 19:10:33 UTC (rev 3748) @@ -354,17 +354,7 @@ { return; } - try - { - SwarmingManager.getInstance().addMagmaToDownload( file ); - } - catch (IOException exp) - { - NLogger.error(NLoggerNames.MAGMA, exp.getMessage(), exp); - GUIUtils.showErrorMessage( - Localizer.getString( "NewDownload_FailedToParseMagmaMessage" ), - Localizer.getString( "NewDownload_FailedToParseMagmaTitle" ) ); - } + InternalFileHandler.magmaReadout( file ); } private void createNewRSSDownload() Modified: phex/trunk/src/phex/gui/dialogs/options/DownloadPane.java =================================================================== --- phex/trunk/src/phex/gui/dialogs/options/DownloadPane.java 2007-03-06 18:42:33 UTC (rev 3747) +++ phex/trunk/src/phex/gui/dialogs/options/DownloadPane.java 2007-03-06 19:10:33 UTC (rev 3748) @@ -49,7 +49,9 @@ private IntegerTextField pushTimeoutTF; private IntegerTextField initialSegmentSizeTF; private IntegerTextField segmentTransferTimeTF; - private JCheckBox readoutMagmasChkbx; + private JCheckBox readoutMagmaChkbx; + private JCheckBox readoutMetalinkChkbx; + private JCheckBox readoutRSSChkbx; private JCheckBox silentSubscriptionsChkbx; private JCheckBox removeCompletedDownloadsChkbx; private JCheckBox enableHitSnoopingChkbx; @@ -68,8 +70,8 @@ { FormLayout layout = new FormLayout( "10dlu, right:d, 2dlu, d, 2dlu:grow", // columns - "p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p"); // rows - layout.setRowGroups( new int[][]{{3, 5, 7, 9, 11, 13, 15, 17, 19}} ); + "p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p"); // rows + layout.setRowGroups( new int[][]{{3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23}} ); setLayout( layout ); PanelBuilder builder = new PanelBuilder( layout, this ); @@ -125,33 +127,47 @@ String.valueOf( DownloadPrefs.PushRequestTimeout.get().intValue() / 1000 ), 6, 3 ); builder.add( pushTimeoutTF, cc.xy( 4, 11 ) ); - readoutMagmasChkbx = new JCheckBox( + readoutMagmaChkbx = new JCheckBox( Localizer.getString( "DownloadSettings_ReadoutDownloadedMagmas" ), DownloadPrefs.AutoReadoutMagmaFiles.get().booleanValue() ); - readoutMagmasChkbx.setToolTipText( + readoutMagmaChkbx.setToolTipText( Localizer.getString("DownloadSettings_TTTReadoutDownloadedMagmas") ); - builder.add( readoutMagmasChkbx, cc.xywh( 2, 13, 4, 1 ) ); + builder.add( readoutMagmaChkbx, cc.xywh( 2, 13, 4, 1 ) ); + + readoutMetalinkChkbx = new JCheckBox( + Localizer.getString( "DownloadSettings_ReadoutDownloadedMetalink" ), + DownloadPrefs.AutoReadoutMetalinkFiles.get().booleanValue() ); + readoutMetalinkChkbx.setToolTipText( + Localizer.getString("DownloadSettings_TTTReadoutDownloadedMetalink") ); + builder.add( readoutMetalinkChkbx, cc.xywh( 2, 15, 4, 1 ) ); + + readoutRSSChkbx = new JCheckBox( + Localizer.getString( "DownloadSettings_ReadoutDownloadedRSS" ), + DownloadPrefs.AutoReadoutRSSFiles.get().booleanValue() ); + readoutRSSChkbx.setToolTipText( + Localizer.getString("DownloadSettings_TTTReadoutDownloadedRSS") ); + builder.add( readoutRSSChkbx, cc.xywh( 2, 17, 4, 1 ) ); silentSubscriptionsChkbx = new JCheckBox( Localizer.getString("DownloadSettings_DownloadSubscriptionsSilently" ), SubscriptionPrefs.DownloadSilently.get().booleanValue() ); silentSubscriptionsChkbx.setToolTipText( Localizer.getString("DownloadSettings_TTTDownloadSubscriptionsSilently") ); - builder.add( silentSubscriptionsChkbx, cc.xywh(2, 15, 4, 1) ); + builder.add( silentSubscriptionsChkbx, cc.xywh(2, 19, 4, 1) ); removeCompletedDownloadsChkbx = new JCheckBox( Localizer.getString( "DownloadSettings_AutoRemoveCompletedDownloads" ), DownloadPrefs.AutoRemoveCompleted.get().booleanValue() ); removeCompletedDownloadsChkbx.setToolTipText( Localizer.getString("DownloadSettings_TTTAutoRemoveCompletedDownloads") ); - builder.add( removeCompletedDownloadsChkbx, cc.xywh( 2, 17, 4, 1 ) ); + builder.add( removeCompletedDownloadsChkbx, cc.xywh( 2, 21, 4, 1 ) ); enableHitSnoopingChkbx = new JCheckBox( Localizer.getString( "DownloadSettings_EnableHitSnooping" ), ConnectionPrefs.EnableQueryHitSnooping.get().booleanValue() ); enableHitSnoopingChkbx.setToolTipText( Localizer.getString("DownloadSettings_TTTEnableHitSnooping") ); - builder.add( enableHitSnoopingChkbx, cc.xywh( 2, 19, 4, 1 ) ); + builder.add( enableHitSnoopingChkbx, cc.xywh( 2, 23, 4, 1 ) ); initConfigValues(); refreshEnableState(); @@ -287,9 +303,15 @@ int pushTimeout = pushTimeoutInt.intValue(); DownloadPrefs.PushRequestTimeout.set( new Integer( pushTimeout * 1000 ) ); - boolean readoutMagmas = readoutMagmasChkbx.isSelected(); + boolean readoutMagmas = readoutMagmaChkbx.isSelected(); DownloadPrefs.AutoReadoutMagmaFiles.set( new Boolean( readoutMagmas ) ); + boolean readoutMetalinks = readoutMetalinkChkbx.isSelected(); + DownloadPrefs.AutoReadoutMetalinkFiles.set( new Boolean( readoutMetalinks ) ); + + boolean readoutRSS = readoutRSSChkbx.isSelected(); + DownloadPrefs.AutoReadoutRSSFiles.set( new Boolean( readoutRSS ) ); + boolean silentSubscriptions = silentSubscriptionsChkbx.isSelected(); SubscriptionPrefs.DownloadSilently.set( new Boolean( silentSubscriptions ) ); Modified: phex/trunk/src/phex/metalink/DMetalink.java =================================================================== --- phex/trunk/src/phex/metalink/DMetalink.java 2007-03-06 18:42:33 UTC (rev 3747) +++ phex/trunk/src/phex/metalink/DMetalink.java 2007-03-06 19:10:33 UTC (rev 3748) @@ -1,3 +1,28 @@ +/* + This file is part of the saxparser for Java from the Metalinks tools project + Copyright (C) 2007 A. Bram Neijt <bn...@gm...> + + 06 Mar 2007 René Kraneis <ren...@we...> + mostly whitespace (astyle --style=ansi) + cleanup and modifications regarding hashmaps + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + package phex.metalink; import java.util.ArrayList; @@ -5,94 +30,90 @@ import java.util.Iterator; import java.util.Map; -/** + + +/** * Metalink data container class - */ +*/ + public class DMetalink { - public ArrayList files; + /** + * The workhorse of the system + */ + public class FileEntry + { + public HashMap<String, String> hashes; + public ArrayList<UrlEntry> urls; + public String filename; + public FileEntry(String name) + { + filename = name; + hashes = new HashMap<String, String> (); + urls = new ArrayList<UrlEntry> (); + } + } + + public class UrlEntry + { + public String type; + public String url; + + public UrlEntry ( String type, String url ) + { + this.type = type; this.url = url; + } + } + + public ArrayList<FileEntry> files; + public DMetalink() { - files = new ArrayList(); + files = new ArrayList<FileEntry> (); } - /** + /** * Start a new file, with a given filename */ - public void newFile(String filename) + public void newFile ( String filename ) { - files.add(new FileEntry(filename)); - System.out.println(this.files.size()); + files.add ( new FileEntry (filename) ); } - // Add a link to the last started file - public void addLink(String uri) + //Add a link to the last started file + public void addURL ( String proto, String url ) { - // TODO allow for type, preference etc. - FileEntry f = (FileEntry) files.get(files.size() - 1); - f.uris.add(uri); - System.out.println(uri); + //TODO allow for type, preference etc. + FileEntry f = files.get (files.size() - 1); + f.urls.add (new UrlEntry(proto, url)); } - public void addHash(String type, String value) + public void addHash (String type, String value) { - FileEntry f = (FileEntry) files.get(files.size() - 1); - f.hashlist.put(type, value); - System.out.println("Adding hash: " + value); + FileEntry f = files.get (files.size() - 1); + f.hashes.put (type, value); } public String toString() { String s = new String(); s += files.size() + " files known\n"; - for ( int i = 0; i < files.size(); ++i ) + + for (FileEntry f : files) { - FileEntry f = (FileEntry) files.get(i); - s += "FileEntry(" + i + "): " + f.filename + "\n"; - ArrayList uris = f.uris; - for ( int e = 0; e < uris.size(); ++e ) - s += " url(" + e + ")= " + uris.get(e).toString() + "\n"; - Iterator hi = f.hashlist.entrySet().iterator(); - while ( hi.hasNext() ) + s += "filename=" + f.filename + "\n"; + for(UrlEntry u : f.urls) { - Map.Entry hash = (Map.Entry) hi.next(); + s += " url= " + u.url + "\n"; + } + + for(Iterator<Map.Entry<String, String>> hi = f.hashes.entrySet().iterator(); hi.hasNext();) + { + Map.Entry hash = hi.next(); s += " hash(" + hash.getKey() + ")= " + hash.getValue() + "\n"; } } return s; } - - /** - * The workhorse of the system - */ - public class FileEntry - { - public HashMap hashlist; - - public ArrayList uris; - - public String filename; - - public FileEntry(String name) - { - filename = name; - hashlist = new HashMap(); - uris = new ArrayList(); - } - - public String sha1() - { - return (String) hashlist.get("sha1"); - } - - // magnet:?xt=urn:sha1:YNCKHTQCWBTRNJIV4WNAE52SJUQCZO5C&dn=Great+Speeches+-+Martin+Luther+King+Jr.+-+I+Have+A+Dream.mp3 - public String magnet() - { - String dn = filename.replaceAll(" ", "+").replaceAll("&", "&"); - if ( this.sha1() != null ) - return "magnet:?xt=urn:sha1:" + this.sha1() + "&dn=" + dn; - return null; - } - } -} \ No newline at end of file +} Modified: phex/trunk/src/phex/metalink/MetalinkSAXHandler.java =================================================================== --- phex/trunk/src/phex/metalink/MetalinkSAXHandler.java 2007-03-06 18:42:33 UTC (rev 3747) +++ phex/trunk/src/phex/metalink/MetalinkSAXHandler.java 2007-03-06 19:10:33 UTC (rev 3748) @@ -1,3 +1,27 @@ +/* + This file is part of the saxparser for Java from the Metalinks tools project + Copyright (C) 2007 A. Bram Neijt <bn...@gm...> + + 06 Mar 2007 René Kraneis <ren...@we...> + mostly whitespace (astyle --style=ansi -j) + some improvements (only work inside "files") + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + package phex.metalink; /* @@ -12,54 +36,66 @@ /** * */ + public class MetalinkSAXHandler extends DefaultHandler { private CharArrayWriter text = new CharArrayWriter(); private DMetalink dMetalink; -// public enum ElementType { FILE, HASH} - Attributes atr; - + private Attributes atr; + private Boolean inFiles=false; + /** @param dMetalink The metalink data container */ - MetalinkSAXHandler( DMetalink dMetalink) + MetalinkSAXHandler(DMetalink dMetalink) { this.dMetalink = dMetalink; } - - public void startElement( - String uri, - String localName, - String qName, - Attributes attributes) throws SAXException + + public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { - //Set current name and copy attributes - if(qName.equals("file")) + if ( qName.equals("files") ) { - this.dMetalink.newFile(attributes.getValue("name")); + inFiles = true; } - System.out.println(qName); - //copy attributes - this.atr = attributes; - + if ( inFiles ) + { + //Set current name and copy attributes + if ( qName.equals("file") ) + { + this.dMetalink.newFile(attributes.getValue("name")); + } + + //copy attributes + this.atr = attributes; + } } - - public void endElement(String uri, String localName, String qName) - throws SAXException + + public void endElement(String uri, String localName, String qName) throws SAXException { - if(qName.equals("hash")) + if (qName.equals("files")) { - dMetalink.addHash(atr.getValue("type"), text.toString().trim()); + inFiles = false; } - if(qName.equals("url")) + + if ( inFiles ) { - dMetalink.addLink(text.toString().trim());//TODO, atr.getValue("type")); + if(qName.equals("hash")) + { + dMetalink.addHash(atr.getValue("type"), text.toString().trim()); + } + + if(qName.equals("url")) + { + + dMetalink.addURL(atr.getValue("type"), text.toString().trim()); + } + text.reset(); } - text.reset(); } - - public void characters(char[] ch, int start, int length) - { - text.write(ch,start,length ); - } + + public void characters(char[] ch, int start, int length) + { + text.write(ch,start,length ); + } } Modified: phex/trunk/src/phex/metalink/MetalinkUtils.java =================================================================== --- phex/trunk/src/phex/metalink/MetalinkUtils.java 2007-03-06 18:42:33 UTC (rev 3747) +++ phex/trunk/src/phex/metalink/MetalinkUtils.java 2007-03-06 19:10:33 UTC (rev 3748) @@ -2,6 +2,10 @@ import java.io.IOException; import java.io.InputStream; +import java.io.PushbackReader; +import java.io.Reader; +import java.util.ArrayList; +import java.util.List; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; @@ -10,24 +14,42 @@ import org.xml.sax.SAXException; import phex.utils.NLogger; +import com.bitzi.util.Base32; - public class MetalinkUtils { - public static DMetalink parseMetalink( InputStream inStream ) + private List<String> magnets; + private InputStream inStream; + + public MetalinkUtils( InputStream inStream ) + { + magnets = new ArrayList<String>(); + this.inStream = inStream; + } + + + public void start( ) throws IOException { - // Use an instance of ourselves as the SAX event handler + // Use an instance of DMetalink as the SAX event handler DMetalink metalink = new DMetalink(); MetalinkSAXHandler handler = new MetalinkSAXHandler(metalink); // Use the default (non-validating) parser SAXParserFactory factory = SAXParserFactory.newInstance(); // Parse the input SAXParser saxParser; + try { saxParser = factory.newSAXParser(); + saxParser.parse( inStream, handler); + + int i = 0; + for(DMetalink.FileEntry f : metalink.files) + { + magnets.add(magnet(f)); + } } catch ( ParserConfigurationException exp ) { @@ -39,9 +61,64 @@ NLogger.error( MetalinkUtils.class, exp, exp ); throw new IOException( "Parsing Metalink XML failed." ); } + } + + public List getMagnets () + { + return magnets; + } + + //magnet:?xt=urn:sha1:YNCKHTQCWBTRNJIV4WNAE52SJUQCZO5C&dn=Great+Speeches+-+Martin+Luther+King+Jr.+-+I+Have+A+Dream.mp3 + //bitte erläutern: &xs= , &as= , ... -> ok hab ich von de.wikipedia.org (auf en.... stands nicht) + //Warum steht davon nichts auf magnet-uri.sf.net? Der erste Link zeigt auf ein (veraltetes?) draft von 2002. + private String magnet(DMetalink.FileEntry f) + { - System.out.println(metalink.toString()); + String sha1 = null; + if (f.hashes.containsKey("sha1")) + { + sha1 = f.hashes.get("sha1"); + if ( sha1.length() == 40 ) + { + sha1 = encodeSha1(sha1); + } + else + { + if ( sha1.length() != 32 ) { + sha1 = null; + } + } + + } + String dn = magnetify(f.filename); + String magnet = "magnet:?" + (sha1 == null ? "" : "xt=urn:sha1:" + sha1 + "&") + "dn=" + dn; - return metalink; + for ( DMetalink.UrlEntry u : f.urls ) + { + if ( u.type.equals("http") ) + { + magnet += "&as=" + magnetify(u.url); + } + } + return magnet; } + + private String magnetify ( String s ) + { + return s.replaceAll(" ", "+").replaceAll("&", "&"); + } + + /* can this be improved?? */ + private String encodeSha1 (String digest) + { + byte[] chars = new byte[20]; + for ( int i = 0; i < digest.length(); i+=2 ) + { + int hn = Byte.parseByte (digest.substring(i, i+1), 16) << 4; + int ln = Byte.parseByte (digest.substring(i+1, i+2), 16); + int b = hn + ln; + chars[i/2] = (new Integer(b)).byteValue(); + } + return Base32.encode(chars); + } } Modified: phex/trunk/src/phex/prefs/OldCfg.java =================================================================== --- phex/trunk/src/phex/prefs/OldCfg.java 2007-03-06 18:42:33 UTC (rev 3747) +++ phex/trunk/src/phex/prefs/OldCfg.java 2007-03-06 19:10:33 UTC (rev 3748) @@ -211,6 +211,7 @@ public static final int DEFAULT_MAX_TOTAL_DOWNLOAD_WRITE_BUFFER = 1 * 1024 * 1024; public static final boolean DEFAULT_AUTO_READOUT_DOWNLOADED_MAGMA = true; + public static final boolean DEFAULT_AUTO_READOUT_DOWNLOADED_METALINK = true; public static final boolean DEFAULT_AUTO_READOUT_DOWNLOADED_RSS = true; /** @@ -295,6 +296,7 @@ public int mDownloadMaxBandwidth = 102400; public boolean mDownloadAutoRemoveCompleted = false; public boolean autoReadoutDownloadedMagma = true; + public boolean autoReadoutDownloadedMetalink = true; public boolean autoReadoutDownloadedRSS = true; public boolean downloadSubscriptionsSilently = false; public String mDownloadDir = "."; @@ -955,6 +957,7 @@ maxWriteBufferPerDownload = DEFAULT_MAX_WRITE_BUFFER_PER_DOWNLOAD; maxTotalDownloadWriteBuffer = DEFAULT_MAX_TOTAL_DOWNLOAD_WRITE_BUFFER; autoReadoutDownloadedMagma = DEFAULT_AUTO_READOUT_DOWNLOADED_MAGMA; + autoReadoutDownloadedMetalink = DEFAULT_AUTO_READOUT_DOWNLOADED_METALINK; autoReadoutDownloadedRSS = DEFAULT_AUTO_READOUT_DOWNLOADED_RSS; maxConnectToHistorySize = DEFAULT_MAX_CONNECTTO_HISTORY_SIZE; Modified: phex/trunk/src/phex/prefs/core/DownloadPrefs.java =================================================================== --- phex/trunk/src/phex/prefs/core/DownloadPrefs.java 2007-03-06 18:42:33 UTC (rev 3747) +++ phex/trunk/src/phex/prefs/core/DownloadPrefs.java 2007-03-06 19:10:33 UTC (rev 3748) @@ -124,6 +124,12 @@ public static final Setting<Boolean> AutoReadoutMagmaFiles; /** + * Indicates if downloaded metalink files should be parsed and its + * reference sources further downloaded. + */ + public static final Setting<Boolean> AutoReadoutMetalinkFiles; + + /** * Indicates if downloaded rss files should be parsed and its referenced * sources further downloaded. */ @@ -166,6 +172,8 @@ "Download.AutoRemoveCompleted", false, instance ); AutoReadoutMagmaFiles = PreferencesFactory.createBoolSetting( "Download.AutoReadoutMagmaFiles", true, instance ); + AutoReadoutMetalinkFiles = PreferencesFactory.createBoolSetting( + "Download.AutoReadoutMetalinkFiles", true, instance ); AutoReadoutRSSFiles = PreferencesFactory.createBoolSetting( "Download.AutoReadoutRSSFiles", true, instance ); } Modified: phex/trunk/src/phex/prefs/core/PhexCorePrefs.java =================================================================== --- phex/trunk/src/phex/prefs/core/PhexCorePrefs.java 2007-03-06 18:42:33 UTC (rev 3747) +++ phex/trunk/src/phex/prefs/core/PhexCorePrefs.java 2007-03-06 19:10:33 UTC (rev 3748) @@ -120,6 +120,7 @@ DownloadPrefs.CandidateLogBufferSize.set( new Integer( (int)cfg.downloadCandidateLogBufferSize ) ); DownloadPrefs.PushRequestTimeout.set( new Integer( cfg.mPushTransferTimeout ) ); DownloadPrefs.AutoReadoutMagmaFiles.set( Boolean.valueOf( cfg.autoReadoutDownloadedMagma ) ); + DownloadPrefs.AutoReadoutMetalinkFiles.set( Boolean.valueOf( cfg.autoReadoutDownloadedMetalink ) ); DownloadPrefs.AutoReadoutRSSFiles.set( Boolean.valueOf( cfg.autoReadoutDownloadedRSS ) ); DownloadPrefs.AutoRemoveCompleted.set( Boolean.valueOf( cfg.mDownloadAutoRemoveCompleted) ); Modified: phex/trunk/src/phex/resources/Lang.properties =================================================================== --- phex/trunk/src/phex/resources/Lang.properties 2007-03-06 18:42:33 UTC (rev 3747) +++ phex/trunk/src/phex/resources/Lang.properties 2007-03-06 19:10:33 UTC (rev 3748) @@ -1125,6 +1125,10 @@ DownloadSettings_TTTSegmentTransferTimeSec =<html>Used together with the "Initial download segment size" to dynamicaly<br>adjust the segment size to try to fit the specified target time.</html> DownloadSettings_ReadoutDownloadedMagmas = Auto readout downloaded magma files. DownloadSettings_TTTReadoutDownloadedMagmas = <html>When active downloaded magma files are parsed and contained magnet<br>links are added for download.</html> +DownloadSettings_ReadoutDownloadedMetalink = Auto readout downloaded metalink files. +DownloadSettings_TTTReadoutDownloadedMetalink = <html>When active downloaded metalink files are parsed and contained magnet<br>links are added for download.</html> +DownloadSettings_ReadoutDownloadedRSS = Auto readout downloaded RSS files. +DownloadSettings_TTTReadoutDownloadedRSS = <html>When active downloaded RSS files (ending in ".rss.xml") are parsed and contained magnet<br>links are added for download.</html> DownloadSettings_AutoRemoveCompletedDownloads = Auto remove completed downloads. DownloadSettings_TTTAutoRemoveCompletedDownloads = Downloads are removed from the download list once completed. DownloadSettings_DownloadSubscriptionsSilently = Download subscriptions without message. Modified: phex/trunk/src/phex/resources/Lang_de_DE.properties =================================================================== --- phex/trunk/src/phex/resources/Lang_de_DE.properties 2007-03-06 18:42:33 UTC (rev 3747) +++ phex/trunk/src/phex/resources/Lang_de_DE.properties 2007-03-06 19:10:33 UTC (rev 3748) @@ -1204,8 +1204,12 @@ DownloadSettings_SegmentTransferTimeSec = Zielzeit f\xFCr Downloadsegmente (Sekunden) PushTimeout = Push timeout DownloadSettings_TTTSegmentTransferTimeSec =<html>Wird zusammen mir der anf\xE4nglichen Gr\xF6\xDFe der Downloadsegmente genutzt, <br>um die Segmentgr\xF6\xDFe an die angegebene Zielzeit anzupassen.</html> -DownloadSettings_ReadoutDownloadedMagmas = Heruntergeladene Magma-Dateien automatisch intern auslesen. +DownloadSettings_ReadoutDownloadedMagmas = Magma-Dateien automatisch intern auslesen. DownloadSettings_TTTReadoutDownloadedMagmas = <html>Bei Aktivierung werden heruntergeladene Magma-Dateien automatisch intern ausgelesen und <br>darin enthaltene magnet-Links zu den Downloads hinzugef\xFCgt.</html> +DownloadSettings_ReadoutDownloadedMetalink = Metalink-Dateien automatisch intern auslesen. +DownloadSettings_TTTReadoutDownloadedMetalink = <html>Bei Aktivierung werden heruntergeladene Metalink-Dateien automatisch intern ausgelesen und <br>darin enthaltene magnet-Links zu den Downloads hinzugef\xFCgt.</html> +DownloadSettings_ReadoutDownloadedRSS = RSS-Dateien automatisch intern auslesen. +DownloadSettings_TTTReadoutDownloadedRSS = <html>Bei Aktivierung werden heruntergeladene RSS-Dateien (mit Endung ".rss.xml") automatisch intern ausgelesen und <br>darin enthaltene magnet-Links zu den Downloads hinzugef\xFCgt.</html> DownloadSettings_AutoRemoveCompletedDownloads = Abgeschlossene Downloads automatisch entfernen. DownloadSettings_TTTAutoRemoveCompletedDownloads = Hiermit werden Downloads automatisch aus der Downloadliste entfernt, sobald sie abgeschlossen sind DownloadSettings_DownloadSubscriptionsSilently = Beim Herunterladen von Abonnements keine Meldung zeigen. Modified: phex/trunk/src/phex/resources/metalinkSharedFilesXMLExport.xsl =================================================================== --- phex/trunk/src/phex/resources/metalinkSharedFilesXMLExport.xsl 2007-03-06 18:42:33 UTC (rev 3747) +++ phex/trunk/src/phex/resources/metalinkSharedFilesXMLExport.xsl 2007-03-06 19:10:33 UTC (rev 3748) @@ -28,7 +28,7 @@ <files> <xsl:for-each select="shared-file-list/shared-file"> - <file> + <file name="{name}"> <verification> <hash type="sha1"><xsl:apply-templates select="sha1"/></hash> </verification> @@ -37,17 +37,20 @@ <url type="magnet" preference="100"> <xsl:apply-templates select="magnet-url"/><xsl:if test="/shared-file-export/export-options/option[@name='UseMagnetURLWithFreeBase'] = 'true'">&as=http://www.freebase.be/g2/dlcount.php?sha1=<xsl:apply-templates select="sha1"/></xsl:if> </url> -<!-- <xsl:if test="/shared-file-export/export-options/option[@name='UseMagnetURLWithXS'] = 'true'"> <url type="http"> <xsl:value-of select="name2res-url"/> </url> + <xsl:if test="/shared-file-export/export-options/option[@name='UseMagnetURLWithFreeBase'] = 'true'"> + <url type="http"> + http://www.freebase.be/g2/dlcount.php?sha1=<xsl:apply-templates select="sha1"/> + </url> </xsl:if> ---> + </xsl:if> </resources> </file> </xsl:for-each> </files> </metalink> </xsl:template> -</xsl:stylesheet> +</xsl:stylesheet> \ No newline at end of file Modified: phex/trunk/src/phex/utils/InternalFileHandler.java =================================================================== --- phex/trunk/src/phex/utils/InternalFileHandler.java 2007-03-06 18:42:33 UTC (rev 3747) +++ phex/trunk/src/phex/utils/InternalFileHandler.java 2007-03-06 19:10:33 UTC (rev 3748) @@ -30,6 +30,7 @@ import phex.download.swarming.SwarmingManager; import phex.share.FileRescanRunner; +import phex.metalink.*; /** * Offers internal handling for files like magma-lists, rss-feeds, podcasts and similar. @@ -106,7 +107,40 @@ NLogger.error(NLoggerNames.RSS, exp.getMessage(), exp); } } + + public static void metalinkReadout( File file ) + { + if (!file.exists()) + { + return; + } + try + { + BufferedInputStream inStream = new BufferedInputStream( new FileInputStream( file ) ); + MetalinkUtils parser = new MetalinkUtils(inStream); + parser.start(); + List magnetList = parser.getMagnets(); + Iterator iter = magnetList.iterator(); + + // Sync subscription operation with a possible rescan process, this + // prevents downloads of files already existing but not yet scanned. + FileRescanRunner.sync(); + + while (iter.hasNext()) + { + String magnet = (String) iter.next(); + URI uri = new URI( magnet, true ); + downloadUri( uri ); + } + + } + catch (IOException exp) + { + NLogger.error(NLoggerNames.RSS, exp.getMessage(), exp); + } + } + public static void sheduledReadout( URI uri, long time ) { // this should download again after a certain time. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |