}
*/
try{
TimeLimitedTask task = new TimeLimitedTask(
"MetaSearch:regexpr",
30*1000,
Thread.NORM_PRIORITY - 1,
new TimeLimitedTask.task()
{
public Object
run()
throws Exception
{
int max_matches = o_absolute_max_matches;
if ( max_matches < 0 || max_matches > 1024 ){
max_matches = 1024;
}
String searchQuery = null;
for(int i = 0 ; i < searchParameters.length ; i++) {
if(searchParameters[i].getMatchPattern().equals("s")) {
searchQuery = searchParameters[i].getValue();
}
}
FieldMapping[] mappings = getMappings();
try{
List results = new ArrayList();
Matcher m = pattern.matcher( page );
while( m.find()){
if ( max_matches >= 0 ){
if ( --max_matches < 0 ){
break;
}
}
if ( listener != null ){
String[] groups = new String[m.groupCount()];
for (int i=0;i<groups.length;i++){
groups[i] = m.group(i+1);
}
listener.matchFound( RegexEngine.this, groups );
}
debugLog( "Found match:" );
WebResult result = new WebResult(RegexEngine.this,getRootPage(),getBasePage(),getDateParser(),searchQuery);
int fields_matched = 0;
for(int i = 0 ; i < mappings.length ; i++) {
int group = -1;
try {
group = Integer.parseInt(mappings[i].getName());
} catch(Exception e) {
//In "Debug/Test" mode, we should fire an exception / notification
}
if (group > 0 && group <= m.groupCount()) {
int field = mappings[i].getField();
String groupContent = m.group(group);
debugLog( " " + field + "=" + groupContent );
fields_matched++;
switch(field) {
case FIELD_NAME :
result.setNameFromHTML(groupContent);
break;
case FIELD_SIZE :
result.setSizeFromHTML(groupContent);
break;
case FIELD_PEERS :
result.setNbPeersFromHTML(groupContent);
break;
case FIELD_SEEDS :
result.setNbSeedsFromHTML(groupContent);
break;
case FIELD_CATEGORY :
result.setCategoryFromHTML(groupContent);
break;
case FIELD_DATE :
result.setPublishedDateFromHTML(groupContent);
break;
case FIELD_CDPLINK :
result.setCDPLink(groupContent);
break;
case FIELD_TORRENTLINK :
result.setTorrentLink(groupContent);
break;
case FIELD_PLAYLINK :
result.setPlayLink(groupContent);
break;
case FIELD_DOWNLOADBTNLINK :
result.setDownloadButtonLink(groupContent);
break;
case FIELD_COMMENTS :
result.setCommentsFromHTML(groupContent);
break;
case FIELD_VOTES :
result.setVotesFromHTML(groupContent);
break;
case FIELD_SUPERSEEDS :
result.setNbSuperSeedsFromHTML(groupContent);
break;
case FIELD_PRIVATE :
result.setPrivateFromHTML(groupContent);
break;
case FIELD_DRMKEY :
result.setDrmKey(groupContent);
break;
case FIELD_VOTES_DOWN :
result.setVotesDownFromHTML(groupContent);
break;
case FIELD_HASH :
result.setHash(groupContent);
break;
default:
fields_matched--;
break;
}
}
}
// ignore "matches" that don't actually populate any fields
if ( fields_matched > 0 ){
results.add(result);
}
}
// hack - if no results and redirected to https and auth required then
// assume we need to log in...
if ( results.size() == 0 && isNeedsAuth()){
if ( page_details.getInitialURL().getProtocol().equalsIgnoreCase( "http" ) &&
page_details.getFinalURL().getProtocol().equalsIgnoreCase( "https" )){
throw new SearchLoginException("login possibly required");
}
}
return (Result[]) results.toArray(new Result[results.size()]);
}catch (Throwable e){
log( "Failed process result", e );
if ( e instanceof SearchException ){
throw((SearchException)e );
}
throw new SearchException(e);
}
}
});
Result[] res = (Result[])task.run();
debugLog( "success: found " + res.length + " results" );
return( res );