FileDocCategorySizeDatePackage
ExternalSeedReaderFactoryGetRight.javaAPI DocAzureus 3.0.3.44433Tue Aug 14 23:26:42 BST 2007com.aelitis.azureus.plugins.extseed.impl.getright

ExternalSeedReaderFactoryGetRight

public class ExternalSeedReaderFactoryGetRight extends Object implements com.aelitis.azureus.plugins.extseed.ExternalSeedReaderFactory

Fields Summary
Constructors Summary
public ExternalSeedReaderFactoryGetRight()

	
Methods Summary
public com.aelitis.azureus.plugins.extseed.ExternalSeedReader[]getSeedReaders(com.aelitis.azureus.plugins.extseed.ExternalSeedPlugin plugin, org.gudy.azureus2.plugins.download.Download download)

		
  		Torrent	torrent = download.getTorrent();
  		
  		try{
  			Map	config = new HashMap();
  			
  			Object	obj = torrent.getAdditionalProperty( "url-list" );
  			
  			if ( obj != null ){
  				
  				config.put( "url-list", obj );
  			}
  			
  			return( getSeedReaders( plugin, download, config ));
  			
  		}catch( Throwable e ){
			
			e.printStackTrace();
		}
		
		return( new ExternalSeedReader[0] );  	
	
public com.aelitis.azureus.plugins.extseed.ExternalSeedReader[]getSeedReaders(com.aelitis.azureus.plugins.extseed.ExternalSeedPlugin plugin, org.gudy.azureus2.plugins.download.Download download, java.util.Map config)

				
		try{
			Object	obj = config.get( "url-list" );
            
            /* resolve url-list according to specification 
             * (http://www.getright.com/seedtorrent.html)
             */ 
            if ( obj instanceof byte[] ){
                List l = new ArrayList();
                l.add(obj);
                obj = l;
            }
			
			if ( obj instanceof List ){
				
				List	urls = (List)obj;

				List	readers = new ArrayList();
				
				Object	_params = config.get( "url-list-params" );
				
				Map	params = _params instanceof Map?(Map)_params:new HashMap();
				
				for (int i=0;i<urls.size();i++){
					
					try{
						URL	url = new URL(new String((byte[])urls.get(i)));
						
						String	protocol = url.getProtocol().toLowerCase();
																		
						if ( protocol.equals( "http" )){
							
							readers.add( new ExternalSeedReaderGetRight(plugin, download.getTorrent(), url, params ));
							
						}else{
							
							plugin.log( download.getName() + ": GR unsupported protocol: " + url );
						}
					}catch( Throwable e ){
						
						e.printStackTrace();
					}
				}
				
				ExternalSeedReader[]	res = new ExternalSeedReader[ readers.size() ];
				
				readers.toArray( res );
				
				return( res );
			}
		}catch( Throwable e ){
			
			e.printStackTrace();
		}
		
		return( new ExternalSeedReader[0] );
	
public static voidmain(java.lang.String[] args)

		try{
			COConfigurationManager.preInitialise();
			
			File file = new File  ( "C:\\temp\\httpseed.torrent");
			
			TOTorrent	torrent = TOTorrentFactory.deserialiseFromBEncodedFile( file );
			
			Map	map = torrent.serialiseToMap();
			
			List	urls = new ArrayList();
			
			urls.add( "http://127.0.0.1:888/files/%DF%26%5B7w%C9%13I%88%8D%EC%E5b%2C9%0F%8D%0Co%BC/" );
			
			map.put( "url-list", urls);
			
			Map params = new HashMap();
			
			map.put( "url-list-params", params );
			
			torrent = TOTorrentFactory.deserialiseFromMap( map );
			
			torrent.serialiseToBEncodedFile( file );
			
		}catch( Throwable e ){
			
			e.printStackTrace();
		}