}
hashes.add( hash_str );
}
SearchResult search_result =
new SearchResult()
{
public Object
getProperty(
int property_name )
{
return( result_properties.get( property_name ));
}
};
try{
observer.resultReceived( si, search_result );
}catch( Throwable e ){
Debug.out( e );
}
}
Map<String,Object[]> template_matches = new HashMap<String, Object[]>();
Engine[] engines = MetaSearchManagerFactory.getSingleton().getMetaSearch().getEngines( false, false );
Map<Subscription,List<String>> sub_dl_name_map = null;
for ( Subscription sub: getSubscriptions( false )){
if ( !sub.isSearchTemplate()){
continue;
}
String sub_name = sub.getName();
Engine sub_engine = sub.getEngine();
if ( sub_engine.isActive() || !(sub_engine instanceof RSSEngine )){
continue;
}
int pos = sub_name.indexOf( ":" );
String t_name = sub_name.substring( pos+1 );
pos = t_name.indexOf( "(v" );
int t_ver;
if ( pos == -1 ){
t_ver = 1;
}else{
String s = t_name.substring( pos+2, t_name.length()-1);
t_name = t_name.substring( 0, pos );
try{
t_ver = Integer.parseInt(s);
}catch( Throwable e ){
t_ver = 1;
}
}
t_name = t_name.trim();
boolean skip = false;
for ( Engine e: engines ){
if ( e != sub_engine && e.sameLogicAs( sub_engine )){
skip = true;
break;
}
if ( e.getName().equalsIgnoreCase( t_name )){
if ( e.getVersion() >= t_ver ){
skip = true;
}
}
}
if ( skip ){
continue;
}
if ( sub_dl_name_map == null ){
sub_dl_name_map = new HashMap<Subscription, List<String>>();
SubscriptionDownloadDetails[] sdds = SubscriptionUtils.getAllCachedDownloadDetails( azureus_core );
for ( SubscriptionDownloadDetails sdd: sdds ){
String name = sdd.getDownload().getDisplayName();
if ( matcher.matches( name )){
Subscription[] x = sdd.getSubscriptions();
for ( Subscription s: x ){
List<String> g = sub_dl_name_map.get( s );
if ( g == null ){
g = new ArrayList<String>();
sub_dl_name_map.put( s, g );
}
g.add( name );
}
}
}
}
List<String> names = sub_dl_name_map.get( sub );
if ( names == null ){
continue;
}
String key = t_name.toLowerCase();
Object[] entry = template_matches.get( key );
if ( entry == null ){
entry = new Object[]{ sub, t_ver };
template_matches.put( key, entry );
}else{
if ( t_ver > (Integer)entry[1]){
entry[0] = sub;
entry[1] = t_ver;
}
}
}
List<Subscription> interesting = new ArrayList<Subscription>();
for ( Object[] entry: template_matches.values()){
interesting.add((Subscription)entry[0]);
}
Collections.sort(
interesting,
new Comparator<Subscription>()
{
public int
compare(
Subscription o1,
Subscription o2)
{
long res = o2.getCachedPopularity() - o1.getCachedPopularity();
if ( res < 0 ){
return( -1 );
}else if ( res > 0 ){
return( 1 );
}else{
return( 0 );
}
}
});
int added = 0;
for ( final Subscription sub: interesting ){
if ( added >= 3 ){
break;
}
try{
String subs_url_str = ((RSSEngine)sub.getEngine()).getSearchUrl( true );
URL subs_url = new URL( subs_url_str );
final byte[] vf_bytes = FileUtil.readInputStreamAsByteArray(subs_url.openConnection().getInputStream());
VuzeFile vf = VuzeFileHandler.getSingleton().loadVuzeFile( vf_bytes );
if ( MetaSearchManagerFactory.getSingleton().isImportable( vf )){
final URL url =
MagnetURIHandler.getSingleton().registerResource(
new MagnetURIHandler.ResourceProvider()
{
public String
getUID()
{
return( SubscriptionManager.class.getName() + ".sid." + sub.getID() );
}
public String
getFileType()
{
return( "vuze" );
}
public byte[]
getData()
{
return( vf_bytes );
}
});
SearchResult search_result =
new SearchResult()
{
public Object
getProperty(
int property_name )
{