1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-13 21:05:01 -05:00

* updated AnidbClient (due to changes of the website)

* not logging exception stacktraces anymore
This commit is contained in:
Reinhard Pointner 2008-02-26 20:45:28 +00:00
parent bc9eb0a267
commit 0d90d19d05
20 changed files with 88 additions and 59 deletions

View File

@ -13,13 +13,12 @@ public class Main {
* @param args * @param args
*/ */
public static void main(String[] args) { public static void main(String[] args) {
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).setLevel(Level.ALL);
try { try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) { } catch (Exception e) {
// should not happen // should not happen
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.getMessage(), e); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString());
} }
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {

View File

@ -135,7 +135,7 @@ public class FileBotList extends JPanel implements Saveable, TransferablePolicyS
out.close(); out.close();
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
// should not happen // should not happen
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.getMessage(), e); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString());
} }
} }

View File

@ -193,7 +193,7 @@ public class FileBotTree extends JTree implements TransferablePolicySupport {
Desktop.getDesktop().open(file); Desktop.getDesktop().open(file);
} catch (Exception e) { } catch (Exception e) {
MessageManager.showWarning(e.getMessage()); MessageManager.showWarning(e.getMessage());
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.getMessage(), e); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString());
} }
} }
} }

View File

@ -2,10 +2,6 @@
package net.sourceforge.filebot.ui; package net.sourceforge.filebot.ui;
import java.awt.datatransfer.DataFlavor;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.Action; import javax.swing.Action;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.KeyStroke; import javax.swing.KeyStroke;
@ -36,20 +32,6 @@ public class FileBotUtil {
return filename.replaceAll("[\\\\/:*?\"<>|]", ""); return filename.replaceAll("[\\\\/:*?\"<>|]", "");
} }
public static final DataFlavor uriListFlavor = createUriListFlavor();
private static DataFlavor createUriListFlavor() {
try {
return new DataFlavor("text/uri-list;class=java.lang.String");
} catch (ClassNotFoundException e) {
// will never happen
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.getMessage(), e);
}
return null;
}
public static Throwable getRootCause(Throwable t) { public static Throwable getRootCause(Throwable t) {
while (t.getCause() != null) { while (t.getCause() != null) {

View File

@ -183,7 +183,7 @@ public class SplitPanel extends ToolPanel implements ChangeListener {
tree.setModel(model); tree.setModel(model);
} catch (Exception e) { } catch (Exception e) {
// should not happen // should not happen
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.getMessage(), e); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString());
} }
SplitPanel.this.firePropertyChange(LOADING_PROPERTY, null, false); SplitPanel.this.firePropertyChange(LOADING_PROPERTY, null, false);

View File

@ -131,7 +131,7 @@ public class TypePanel extends ToolPanel {
tree.setModel(model); tree.setModel(model);
} catch (Exception e) { } catch (Exception e) {
// should not happen // should not happen
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.getMessage(), e); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString());
} }
TypePanel.this.firePropertyChange(LOADING_PROPERTY, null, false); TypePanel.this.firePropertyChange(LOADING_PROPERTY, null, false);

View File

@ -52,7 +52,7 @@ public class FileListTransferablePolicy extends FileTransferablePolicy {
} }
} catch (IOException e) { } catch (IOException e) {
// should not happen // should not happen
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.getMessage(), e); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString());
} }
} }
} }

View File

@ -72,7 +72,7 @@ public class NamesRenameListTransferablePolicy extends MultiTransferablePolicy {
} }
} catch (Exception e) { } catch (Exception e) {
// should not happen // should not happen
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.getMessage(), e); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString());
} }
} }

View File

@ -38,7 +38,7 @@ public class HyperlinkLabel extends JLabel {
Desktop.getDesktop().browse(url.toURI()); Desktop.getDesktop().browse(url.toURI());
} catch (Exception e) { } catch (Exception e) {
// should not happen // should not happen
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.getMessage(), e); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString());
} }
} }

View File

@ -326,7 +326,7 @@ public class SearchPanel extends FileBotPanel {
tabbedPane.remove(episodeList); tabbedPane.remove(episodeList);
MessageManager.showWarning(FileBotUtil.getRootCause(e).getMessage()); MessageManager.showWarning(FileBotUtil.getRootCause(e).getMessage());
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.getMessage(), e); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString());
return; return;
} }
@ -407,7 +407,7 @@ public class SearchPanel extends FileBotPanel {
tabbedPane.remove(episodeList); tabbedPane.remove(episodeList);
MessageManager.showWarning(FileBotUtil.getRootCause(e).getMessage()); MessageManager.showWarning(FileBotUtil.getRootCause(e).getMessage());
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.getMessage(), e); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString());
} }
} }

View File

@ -165,7 +165,7 @@ public class SfvTable extends JTable implements TransferablePolicySupport, Savea
out.close(); out.close();
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
// should not happen // should not happen
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.getMessage(), e); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString());
} }
} }

View File

@ -100,7 +100,7 @@ public class SfvTransferablePolicy extends MultiTransferablePolicy {
in.close(); in.close();
} catch (IOException e) { } catch (IOException e) {
// should not happen // should not happen
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.getMessage(), e); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString());
} }
} }

View File

@ -9,15 +9,29 @@ import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.logging.Level;
import net.sourceforge.filebot.ui.FileBotUtil; import java.util.logging.Logger;
public class FileTransferable implements Transferable { public class FileTransferable implements Transferable {
public static final DataFlavor uriListFlavor = createUriListFlavor();
private static DataFlavor createUriListFlavor() {
try {
return new DataFlavor("text/uri-list;class=java.lang.String");
} catch (ClassNotFoundException e) {
// will never happen
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString());
}
return null;
}
private List<File> files; private List<File> files;
private DataFlavor[] supportedFlavors = { DataFlavor.javaFileListFlavor, FileBotUtil.uriListFlavor }; private DataFlavor[] supportedFlavors = { DataFlavor.javaFileListFlavor, uriListFlavor };
public FileTransferable(File... fileArray) { public FileTransferable(File... fileArray) {
@ -38,7 +52,7 @@ public class FileTransferable implements Transferable {
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException { public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
if (flavor.isFlavorJavaFileListType()) if (flavor.isFlavorJavaFileListType())
return files; return files;
else if (flavor.equals(FileBotUtil.uriListFlavor)) else if (flavor.equals(uriListFlavor))
return getUriList(); return getUriList();
else else
throw new UnsupportedFlavorException(flavor); throw new UnsupportedFlavorException(flavor);
@ -74,4 +88,5 @@ public class FileTransferable implements Transferable {
return false; return false;
} }
} }

View File

@ -40,7 +40,7 @@ public class SaveableExportHandler implements ExportHandler {
} }
} catch (Exception e) { } catch (Exception e) {
// should not happen // should not happen
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.getMessage(), e); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString());
} }
} }
@ -64,7 +64,7 @@ public class SaveableExportHandler implements ExportHandler {
return new FileTransferable(temporaryFile); return new FileTransferable(temporaryFile);
} catch (IOException e) { } catch (IOException e) {
// should not happen // should not happen
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.getMessage(), e); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString());
} }
return null; return null;

View File

@ -4,7 +4,9 @@ package net.sourceforge.filebot.ui.transferablepolicies;
import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable; import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -12,7 +14,7 @@ import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.sourceforge.filebot.ui.FileBotUtil; import net.sourceforge.filebot.ui.transfer.FileTransferable;
public abstract class FileTransferablePolicy extends TransferablePolicy { public abstract class FileTransferablePolicy extends TransferablePolicy {
@ -36,8 +38,8 @@ public abstract class FileTransferablePolicy extends TransferablePolicy {
try { try {
if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
return (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor); return (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor);
} else if (tr.isDataFlavorSupported(FileBotUtil.uriListFlavor)) { } else if (tr.isDataFlavorSupported(FileTransferable.uriListFlavor)) {
String transferString = (String) tr.getTransferData(FileBotUtil.uriListFlavor); String transferString = (String) tr.getTransferData(FileTransferable.uriListFlavor);
String lines[] = transferString.split("\r?\n"); String lines[] = transferString.split("\r?\n");
ArrayList<File> files = new ArrayList<File>(lines.length); ArrayList<File> files = new ArrayList<File>(lines.length);
@ -61,9 +63,12 @@ public abstract class FileTransferablePolicy extends TransferablePolicy {
return files; return files;
} }
} catch (Exception e) { } catch (UnsupportedFlavorException e) {
// should not happen // should not happen
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.getMessage(), e); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString());
} catch (IOException e) {
// should not happen
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString());
} }
return null; return null;

View File

@ -31,7 +31,7 @@ public abstract class TextTransferablePolicy extends TransferablePolicy {
load(string); load(string);
} catch (Exception e) { } catch (Exception e) {
// should not happen // should not happen
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.getMessage(), e); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString());
} }
} }

View File

@ -48,11 +48,11 @@ public class AnidbClient extends EpisodeListClient {
if (!nodes.isEmpty()) if (!nodes.isEmpty())
for (Node node : nodes) { for (Node node : nodes) {
String type = XPathUtil.selectString("./TD[2]/text()", node); String type = XPathUtil.selectString("./TD[3]/text()", node);
// we only want shows // we only want shows
if (type.equalsIgnoreCase("tv series")) { if (type.equalsIgnoreCase("tv series")) {
Node titleNode = XPathUtil.selectNode("./TD[1]/A", node); Node titleNode = XPathUtil.selectNode("./TD[2]/A", node);
String title = XPathUtil.selectString("text()", titleNode); String title = XPathUtil.selectString("text()", titleNode);
String href = XPathUtil.selectString("@href", titleNode); String href = XPathUtil.selectString("@href", titleNode);
@ -103,7 +103,7 @@ public class AnidbClient extends EpisodeListClient {
for (Node node : nodes) { for (Node node : nodes) {
String number = XPathUtil.selectString("./TD[1]/A/text()", node); String number = XPathUtil.selectString("./TD[1]/A/text()", node);
String title = XPathUtil.selectString("./TD[2]/SPAN/text()", node); String title = XPathUtil.selectString("./TD[2]/LABEL/text()", node);
if (title.startsWith("recap")) if (title.startsWith("recap"))
title = title.replaceFirst("recap", ""); title = title.replaceFirst("recap", "");

View File

@ -147,7 +147,7 @@ public class DownloadTask extends SwingWorker<ByteBuffer, Object> {
sb.append(URLEncoder.encode(parameters.get(key), "UTF-8")); sb.append(URLEncoder.encode(parameters.get(key), "UTF-8"));
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
// will never happen // will never happen
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.getMessage(), e); Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.toString());
} }
i++; i++;

View File

@ -8,12 +8,18 @@ import java.net.URL;
public class MovieDescriptor { public class MovieDescriptor {
private String title; private String title;
private int year; private Integer imdbId;
private int imdbId;
private Integer year;
private URL imdbUrl; private URL imdbUrl;
public MovieDescriptor(String title, int year, int imdbId, URL imdbUrl) { public MovieDescriptor(String description, Integer imdbId) {
this(description, imdbId, null, null);
}
public MovieDescriptor(String title, Integer imdbId, Integer year, URL imdbUrl) {
this.title = title; this.title = title;
this.imdbId = imdbId; this.imdbId = imdbId;
this.year = year; this.year = year;
@ -26,13 +32,13 @@ public class MovieDescriptor {
} }
public int getYear() { public Integer getImdbId() {
return year; return imdbId;
} }
public int getImdbId() { public Integer getYear() {
return imdbId; return year;
} }
@ -43,6 +49,9 @@ public class MovieDescriptor {
@Override @Override
public String toString() { public String toString() {
if (year == null)
return title;
return String.format("%s (%d)", title, year); return String.format("%s (%d)", title, year);
} }
} }

View File

@ -37,7 +37,7 @@ public class OpenSubtitlesClient {
* </tr> * </tr>
* </table> * </table>
*/ */
private String url = "http://dev.opensubtitles.org/xml-rpc"; private String url = "http://www.opensubtitles.org/xml-rpc";
private String username; private String username;
private String password; private String password;
@ -52,7 +52,7 @@ public class OpenSubtitlesClient {
/** /**
* Interval to call NoOperation to keep the session from expiring * Interval to call NoOperation to keep the session from expiring
*/ */
public static final int KEEP_ALIVE_INTERVAL = 12 * 60 * 1000; // 12 minutes private static final int KEEP_ALIVE_INTERVAL = 12 * 60 * 1000; // 12 minutes
public OpenSubtitlesClient(String useragent) { public OpenSubtitlesClient(String useragent) {
@ -93,8 +93,6 @@ public class OpenSubtitlesClient {
this.username = username; this.username = username;
this.password = password; this.password = password;
this.language = language; this.language = language;
activate();
} }
@ -216,13 +214,34 @@ public class OpenSubtitlesClient {
ArrayList<OpenSubtitleDescriptor> subs = new ArrayList<OpenSubtitleDescriptor>(); ArrayList<OpenSubtitleDescriptor> subs = new ArrayList<OpenSubtitleDescriptor>();
for (Map<String, String> subtitle : response.get("data")) if (!(response.get("data") instanceof List))
throw new XmlRpcException("Illegal response: " + response.toString());
// if there was an error data may not be a list
for (Map<String, String> subtitle : response.get("data")) {
subs.add(new OpenSubtitleDescriptor(subtitle)); subs.add(new OpenSubtitleDescriptor(subtitle));
}
return subs; return subs;
} }
@SuppressWarnings("unchecked")
public List<MovieDescriptor> searchMoviesOnIMDB(String query) throws XmlRpcFault {
activate();
Map<String, List<Map<String, String>>> response = (Map<String, List<Map<String, String>>>) invoke("SearchMoviesOnIMDB", token, query);
ArrayList<MovieDescriptor> movies = new ArrayList<MovieDescriptor>();
for (Map<String, String> movie : response.get("data")) {
movies.add(new MovieDescriptor(movie.get("title"), new Integer(movie.get("id"))));
}
return movies;
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public boolean noOperation() { public boolean noOperation() {
try { try {