BeanShell-Filter

Aus TV-Browser Wiki
Version vom 26. Februar 2015, 18:16 Uhr von Sheldon2012⧼word-separator⧽⧼parentheses⧽
⧼revision-nav⧽
Wechseln zu: Navigation⧼comma-separator⧽Suche

Diese Seite enthält einige Beispiele für die Verwendung von BeanShell-Filtern. Der angegebene Code muss jeweils in das Textfeld einer BeanShell-Filterkomponente kopiert werden.

Sendungen mit Bildern

import devplugin.beanshell.BeanShellProgramFilterIf; 
import devplugin.Program; 
import devplugin.ProgramFieldType; 

accept(Program p) { 
  if(p.getBinaryField(ProgramFieldType.PICTURE_TYPE) != null) 
    return true; 
   
  return false; 
} 

return (BeanShellProgramFilterIf) this;

Temporär alle Premiere-Sendungen ausblenden

import devplugin.beanshell.BeanShellProgramFilterIf; 
import devplugin.Program; 

accept(Program p) { 
    String s=p.getChannel().toString(); 
    return (-1==s.indexOf("Premiere"));  
}

return (BeanShellProgramFilterIf) this;

Sendungen, bei denen der Regisseur auch Schauspieler ist

import devplugin.beanshell.BeanShellProgramFilterIf;
import devplugin.Program;
import devplugin.ProgramFieldType;

accept(Program p) {
  String director = p.getTextField(ProgramFieldType.DIRECTOR_TYPE);
  String actors = p.getTextField(ProgramFieldType.ACTOR_LIST_TYPE);
  if (director != null && actors != null) {
    if (actors.indexOf(director) >= 0) {
      return true;
    }
  }
  return false;
}

return (BeanShellProgramFilterIf) this;

Dynamischer BeanShell-File als CSV-File Interface


// Beanshell-Filter: CSV file interface  

import devplugin.beanshell.BeanShellProgramFilterIf;
import devplugin.Program;
import devplugin.ProgramFieldType;

import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;

accept(Program prog) throws IOException {

   // Reading program data 
   String title = prog.getTextField(ProgramFieldType.TITLE_TYPE);
   String episode = prog.getTextField(ProgramFieldType.EPISODE_TYPE);

   // Program data comparison preparation
   title = title.replaceAll("[^0-9a-zA-Z]", "").trim(); 
   episode = episode.replaceAll("[^0-9a-zA-Z]", "").trim();

   // CSV file settings
   String file = "C:\\episodes.csv";
   String separator = ";";
   String line = "";
   
   // Program data check
   if ((title != null) && (title.trim().length() > 0) && (episode != null) && (episode.trim().length() > 0)){

      try{
 
         // Read CSV file
         BufferedReader br = new BufferedReader(new FileReader(file));
         
         line = br.readLine();

         while (line != null){

            line = line.trim();

            String[] lineParts = line.split(separator);

            // CSV data comparison preparation
            String favTitle = lineParts[0].replaceAll("[^0-9a-zA-Z]", "").trim();;
            String favEpisode = lineParts[1].replaceAll("[^0-9a-zA-Z]", "").trim();

            // Data comparison
            if (title.trim().equals(favTitle) && episode.trim().equals(favEpisode)){
     
               // Close reader
               try {
	        if (br != null){
                     br.close();
                  }
               } catch (IOException e) {
                  throw e;
               } 
               
               return true;
            }
         
            line = br.readLine();
         }

         // Close reader
         try {
	   if(br != null){
                 br.close();
             }
         } catch (IOException e) {
            throw e;
         } 

         return false;

      }catch (IOException ioe) {

         // Close reader
         try {
            if (br != null){
               br.close();
            }
         } catch (IOException e) {
              throw e;
         } 

         throw ioe;
      }
   }else{
       
       // Program data check failed
       return false;

   }
}

return (BeanShellProgramFilterIf) this;