Code: Alles auswählen
ProgramInfoHelper.bitSet(program.getInfo(),Program.INFO_CATEGORIE_SERIES)
Code: Alles auswählen
ProgramInfoHelper.bitSet(program.getInfo(),Program.INFO_CATEGORIE_SERIES)
Code: Alles auswählen
/* CSVFilerFilterComponent
*
* 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 csvfilefiltercomponent;
import java.awt.BorderLayout;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.HashMap;
import java.util.HashSet;
import java.lang.util.io.IOUtilities;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import devplugin.PluginsFilterComponent;
import devplugin.Program;
import devplugin.ProgramFieldType;
import devplugin.ProgramInfoHelper;
/**
* FilterComponent class to build a filter based on information from a CSV file.
*
* @author RenAŠ Mach
*/
public class CSVFileFilterComp extends PluginsFilterComponent {
private String mFile;
private JTextField mPath;
private HashMap<String, Boolean> mPogramStatusMap;
private BufferedReader br;
private static final String SEPARATOR = ";";
private HashMap<String, HashSet<String>> mCSVData;
@Override
public int getVersion() {
return 1;
}
@Override
public boolean accept(Program program) {
if(program != null) {
// Check program status map
if (mPogramStatusMap.containsKey(program.getUniqueID())) {
return mPogramStatusMap.get(program.getUniqueID());
}
// Reading program data
String title = program.getTextField(ProgramFieldType.TITLE_TYPE);
String episode = program.getTextField(ProgramFieldType.EPISODE_TYPE);
if (ProgramInfoHelper.bitSet(program.getInfo(),Program.INFO_CATEGORIE_SERIES)){
if ((title != null) && (title.trim().length() > 0)){
if ((episode == null) || (episode.trim().length() == 0)){
episode = program.getTextField(ProgramFieldType.ORIGINAL_EPISODE_TYPE);
}
}else{
title = program.getTextField(ProgramFieldType.ORIGINAL_TITLE_TYPE);
episode = program.getTextField(ProgramFieldType.ORIGINAL_EPISODE_TYPE);
if ((episode == null) || (episode.trim().length() == 0)){
episode = program.getTextField(ProgramFieldType.EPISODE_TYPE);
}
}
} else {
/*
!!! IMPORTANT !!!
If the program is no series the episode is set equal to title. The program is handled like a special series with one episode.
This enables you to handle programs like movies, documentations etc. with this approach.
This needs to be taken into cosideration at CSV file creation time to guarantee proper matching.
*/
if ((title != null) && (title.trim().length() > 0)){
episode = title;
}
}
// Program data comparison preparation
title = prepareForComparison(title);
episode = prepareForComparison(episode);
boolean result = false;
// Program data check
result = (title != null) && (title.length() > 0) && (episode != null) && (episode.length() > 0) ;
if (result){
// Data comparison
HashSet<String> episodeSet = mCSVData.get(title);
result = (episodeSet != null) && (episodeSet.contains(episode));
}
// Update program status map
mPogramStatusMap.put(program.getUniqueID(), result);
return result;
}
// Program check failed
return false;
}
@Override
public void read(ObjectInputStream in, int version) throws IOException, ClassNotFoundException {
mFile = in.readUTF();
mFile = translateRelativePath(mFile);
if(mPogramStatusMap == null) {
mPogramStatusMap = new HashMap<String, Boolean>();
}
if(mFile != null){
readFile();
}
}
@Override
public void write(ObjectOutputStream out) throws IOException {
out.writeUTF(checkForRelativePath(mFile));
}
@Override
public String getUserPresentableClassName() {
return CSVFileFilterComponent.LOCALIZER.msg("compName", "CSV file");
}
@Override
public JPanel getSettingsPanel() {
JPanel global = new JPanel(new BorderLayout());
JPanel settings = new JPanel(new BorderLayout(5,5));
JLabel info = new JLabel(CSVFileFilterComponent.LOCALIZER.msg("settings.info", "Enter path to CSV file:"));
info.setAlignmentX(JLabel.LEFT_ALIGNMENT);
settings.add(info, BorderLayout.NORTH);
mPath = new JTextField();
mPath.setAlignmentX(JTextField.LEFT_ALIGNMENT);
mPath.setEditable(true);
if(mFile != null) {
mPath.setText(mFile);
}
JPanel center = new JPanel(new BorderLayout());
center.add(mPath, BorderLayout.NORTH);
settings.add(center, BorderLayout.CENTER);
global.add(settings, BorderLayout.WEST);
return global;
}
@Override
public void saveSettings() {
if((mPath.getText() != null) && (mPath.getText().length() > 0)){
mFile = mPath.getText();
}
if(mFile != null){
readFile();
}
if(mPogramStatusMap == null) {
mPogramStatusMap = new HashMap<String, Boolean>();
}
}
private void processLine(String line) {
if(line != null) {
if(mCSVData == null) {
mCSVData = new HashMap<String, HashSet<String>>();
}
String[] parts = line.split(SEPARATOR);
String part_0 = prepareForComparison(parts[0]);
String part_1 = prepareForComparison(parts[1]);
HashSet<String> episodeSet = mCSVData.get(part_0);
if(episodeSet == null) {
episodeSet = new HashSet<String>();
mCSVData.put(part_0, episodeSet);
}
episodeSet.add(part_1);
}
}
private void readFile() {
String line = "";
if (mFile != null){
File data = new File(mFile);
if(data.isFile()) {
try{
// Read CSV file
br = new BufferedReader(new FileReader(mFile));
// Clear the map
if (mCSVData != null){
mCSVData.clear();
}
line = br.readLine();
while (line != null){
processLine(line);
line = br.readLine();
}
closeReader(br);
}catch (IOException ioe) {
closeReader(br);
ioe.printStackTrace();
}
}
}
}
private String prepareForComparison(String unpreparedString){
String preparedString = "";
if(unpreparedString != null) {
preparedString = unpreparedString;
// Set to lower case
preparedString = preparedString.toLowerCase();
// Special alphabetic character handling
preparedString = preparedString.replaceAll("\00df", "ss"); // replace ß by ss
preparedString = preparedString.replaceAll("\00e4", "ae"); // replace ä by ae
preparedString = preparedString.replaceAll("\00f6", "oe"); // replace ö by oe
preparedString = preparedString.replaceAll("\00fc", "ue"); // replace ü by ue
// Non-numeric and non-alphabetic character handling
preparedString = preparedString.replaceAll("[^0-9a-z]", "");
// Trim the string
preparedString = preparedString.trim();
}
return preparedString;
}
private void closeReader (BufferedReader br) {
try {
if (br != null) {
br.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Nicht ganz, richtig ist: csvfilefiltercomponent.CSVFileFilterComponentSheldon2012 hat geschrieben:csvfilefiltercomponent.CSVFileFilterComponent.class Richtig?
Bietet das Plugin Programmdaten an? Wohl nicht, folglich ist es Andere.Sheldon2012 hat geschrieben:Datenquelle Software oder Andere? Welches Schweinl hättens denn gern?
Kannst du auch später noch nachreichen.Sheldon2012 hat geschrieben:Die gibt es noch nicht. Kann man das später machen ode wie regelt ihr das?
Sieh einfach in der Plugin-Liste in TV-Browser nach, dort steht die Version. Auf der Plugin-Seite muss es die gleiche sein.Sheldon2012 hat geschrieben:Mein Vorschlag
1.0.0.0 (wie bei Filter-Filterkomponente)
Beta ja oder nein? Ich denke eher nein, oder?
Okay.Sheldon2012 hat geschrieben:Alle Betriebssysteme (checked)
Dieses Plugin auf der Webseite anzeigen. (checked)
Dieses Plugin innerhalb des TV-Browser zum Download anbieten. (checked)
In der Plugin-Liste steht es doch noch nicht. Oder meinst Du eine andere als unter Downloads?ds10 hat geschrieben:Sieh einfach in der Plugin-Liste in TV-Browser nach, dort steht die Version. Auf der Plugin-Seite muss es die gleiche sein.Sheldon2012 hat geschrieben:Mein Vorschlag
1.0.0.0 (wie bei Filter-Filterkomponente)
Beta ja oder nein? Ich denke eher nein, oder?