mirror of
https://github.com/mirror/jdownloader.git
synced 2024-11-23 20:19:50 +00:00
Plugins besitzen nun einen Status
git-svn-id: svn://svn.jdownloader.org/jdownloader/trunk@26 ebf7c1c2-ba36-0410-9fe8-c592906822b4
This commit is contained in:
parent
1ef6d38f90
commit
64946fd217
@ -3,12 +3,14 @@ package jd.gui;
|
||||
import java.awt.Frame;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Image;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
@ -16,7 +18,7 @@ import javax.swing.JLabel;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import jd.captcha.JAntiCaptcha;
|
||||
import jd.captcha.UTILITIES;
|
||||
import jd.plugins.Plugin;
|
||||
|
||||
/**
|
||||
* Mit dieser Klasse wird ein Captcha Bild angezeigt
|
||||
@ -53,33 +55,31 @@ public class CaptchaDialog extends JDialog implements ActionListener {
|
||||
* @param imageAddress
|
||||
* Die Adresse des Bildes, das angezeigt werden soll
|
||||
*/
|
||||
public CaptchaDialog(Frame owner, String imageAddress) {
|
||||
public CaptchaDialog(Frame owner, Plugin plugin, String imageAddress) {
|
||||
super(owner);
|
||||
setModal(true);
|
||||
setLayout(new GridBagLayout());
|
||||
ImageIcon imageIcon = null;
|
||||
Image img;
|
||||
BufferedImage image;
|
||||
String code = "";
|
||||
try {
|
||||
img = UTILITIES.loadImage(new URL(imageAddress));
|
||||
imageIcon = new ImageIcon(img);
|
||||
code = JAntiCaptcha.getCaptchaCode(img, "rapidshare.com");
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
image = ImageIO.read(new URL(imageAddress));
|
||||
imageIcon = new ImageIcon(image);
|
||||
code = JAntiCaptcha.getCaptchaCode(image, "rapidshare.com");
|
||||
}
|
||||
catch (MalformedURLException e) { e.printStackTrace(); }
|
||||
catch (IOException e) { e.printStackTrace(); }
|
||||
JLabel label = new JLabel(imageIcon);
|
||||
textField = new JTextField(10);
|
||||
btnOK = new JButton("OK");
|
||||
btnOK = new JButton("OK");
|
||||
textField.setText(code);
|
||||
textField.selectAll();
|
||||
btnOK.addActionListener(this);
|
||||
getRootPane().setDefaultButton(btnOK);
|
||||
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
Utilities.addToGridBag(this, label, 0, 0, 2, 1, 0, 0, null,
|
||||
GridBagConstraints.NONE, GridBagConstraints.CENTER);
|
||||
Utilities.addToGridBag(this, textField, 0, 1, 1, 1, 1, 1, null,
|
||||
GridBagConstraints.NONE, GridBagConstraints.EAST);
|
||||
Utilities.addToGridBag(this, btnOK, 1, 1, 1, 1, 1, 1, null,
|
||||
GridBagConstraints.NONE, GridBagConstraints.WEST);
|
||||
Utilities.addToGridBag(this, label, 0, 0, 2, 1, 0, 0, null, GridBagConstraints.NONE, GridBagConstraints.CENTER);
|
||||
Utilities.addToGridBag(this, textField, 0, 1, 1, 1, 1, 1, null, GridBagConstraints.NONE, GridBagConstraints.EAST);
|
||||
Utilities.addToGridBag(this, btnOK, 1, 1, 1, 1, 1, 1, null, GridBagConstraints.NONE, GridBagConstraints.WEST);
|
||||
|
||||
pack();
|
||||
setLocation(Utilities.getCenterOfComponent(null, this));
|
||||
|
@ -89,7 +89,7 @@ public class MainWindow extends JFrame implements ClipboardOwner{
|
||||
/**
|
||||
* Der Thread, der das Downloaden realisiert
|
||||
*/
|
||||
private StartDownload download = null;
|
||||
private StartDownloads download = null;
|
||||
private Speedometer speedoMeter = new Speedometer();
|
||||
private StatusBar statusBar;
|
||||
/**
|
||||
@ -243,7 +243,7 @@ public class MainWindow extends JFrame implements ClipboardOwner{
|
||||
}
|
||||
}
|
||||
else{
|
||||
CaptchaDialog captchaDialog = new CaptchaDialog(this,captchaAddress);
|
||||
CaptchaDialog captchaDialog = new CaptchaDialog(this,plugin,captchaAddress);
|
||||
MainWindow.this.toFront();
|
||||
captchaDialog.setVisible(true);
|
||||
return captchaDialog.getCaptchaText();
|
||||
@ -267,7 +267,7 @@ public class MainWindow extends JFrame implements ClipboardOwner{
|
||||
break;
|
||||
case JDAction.APP_START_STOP_DOWNLOADS:
|
||||
if(download == null){
|
||||
download = new StartDownload();
|
||||
download = new StartDownloads();
|
||||
download.start();
|
||||
}
|
||||
else{
|
||||
@ -429,16 +429,16 @@ public class MainWindow extends JFrame implements ClipboardOwner{
|
||||
*
|
||||
* @author astaldo
|
||||
*/
|
||||
private class StartDownload extends Thread{
|
||||
private class StartDownloads extends Thread{
|
||||
/**
|
||||
* Der DownloadLink
|
||||
*/
|
||||
private DownloadLink downloadLink;
|
||||
private Plugin plugin;
|
||||
private PluginForHost plugin;
|
||||
private boolean aborted=false;
|
||||
|
||||
public StartDownload(){
|
||||
super("JD-StartDownload");
|
||||
public StartDownloads(){
|
||||
super("JD-StartDownloads");
|
||||
}
|
||||
public void abortDownload(){
|
||||
aborted=true;
|
||||
@ -480,6 +480,7 @@ public class MainWindow extends JFrame implements ClipboardOwner{
|
||||
if(step != null && step.getStatus() == PluginStep.STATUS_ERROR){
|
||||
logger.severe("Error occurred while downloading file");
|
||||
}
|
||||
|
||||
// }
|
||||
btnStartStop.setSelected(false);
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public class DownloadLink{
|
||||
/**
|
||||
* Das Plugin, das für diesen Download zuständig ist
|
||||
*/
|
||||
private Plugin plugin;
|
||||
private PluginForHost plugin;
|
||||
/**
|
||||
* Die Fortschrittsanzeige
|
||||
*/
|
||||
@ -94,7 +94,7 @@ public class DownloadLink{
|
||||
*
|
||||
* @return Das Plugin
|
||||
*/
|
||||
public Plugin getPlugin() { return plugin; }
|
||||
public PluginForHost getPlugin() { return plugin; }
|
||||
/**
|
||||
* Liefert die Datei zurück, in die dieser Download gespeichert werden soll
|
||||
*
|
||||
|
@ -39,6 +39,11 @@ import jd.plugins.event.PluginListener;
|
||||
* @author astaldo
|
||||
*/
|
||||
public abstract class Plugin{
|
||||
public final int STATUS_OK = 0;
|
||||
public final int STATUS_ERROR = 1;
|
||||
public final int STATUS_CAPTCHA_WRONG = 2;
|
||||
public final int STATUS_FILE_NOT_FOUND = 4;
|
||||
public final int STATUS_DOWNLOAD_LIMIT = 5;
|
||||
/**
|
||||
* Puffer für Lesevorgänge
|
||||
*/
|
||||
@ -51,6 +56,7 @@ public abstract class Plugin{
|
||||
* Zeigt an, ob das Plugin abgebrochen werden soll
|
||||
*/
|
||||
protected boolean aborted = false;
|
||||
private int status;
|
||||
/**
|
||||
* Liefert den Namen des Plugins zurück
|
||||
* @return Der Name des Plugins
|
||||
@ -100,6 +106,12 @@ public abstract class Plugin{
|
||||
public void abort(){
|
||||
aborted = true;
|
||||
}
|
||||
public int getStatus(){
|
||||
return status;
|
||||
}
|
||||
protected void setStatus(int status){
|
||||
this.status = status;
|
||||
}
|
||||
/**
|
||||
* Hiermit wird der Eventmechanismus realisiert. Alle hier eingetragenen Listener
|
||||
* werden benachrichtigt, wenn mittels {@link #firePluginEvent(PluginEvent)} ein
|
||||
@ -340,6 +352,7 @@ public abstract class Plugin{
|
||||
bis = new BufferedInputStream(urlConnection.getInputStream());
|
||||
FileOutputStream fos = new FileOutputStream(fileOutput);
|
||||
downloadLink.setInProgress(true);
|
||||
logger.info("starting download");
|
||||
do{
|
||||
count = bis.read(buffer);
|
||||
if (count != -1){
|
||||
@ -354,6 +367,7 @@ public abstract class Plugin{
|
||||
fos.close();
|
||||
bis.close();
|
||||
firePluginEvent(new PluginEvent(this,PluginEvent.PLUGIN_PROGRESS_FINISH,null));
|
||||
logger.info("download finished");
|
||||
return true;
|
||||
}
|
||||
catch (FileNotFoundException e){
|
||||
|
@ -18,7 +18,7 @@ public class Rapidshare extends PluginForHost{
|
||||
private String host = "rapidshare.com";
|
||||
private String version = "1.0.0.0";
|
||||
// http://(?:[^.]*\.)*rapidshare\.com/files/[0-9]*/[^\s"]+
|
||||
private Pattern patternSupported = Pattern.compile("http://(?:[^.]*\\.)*rapidshare\\.com/files/[0-9]*/[^\\s\"]+");
|
||||
private Pattern patternSupported = Pattern.compile("http://(?:[^.]*\\.)*rapidshare\\.com/files/[0-9]+/[^\\s\"]+");
|
||||
/**
|
||||
* Das findet die Ziel URL für den Post
|
||||
*/
|
||||
@ -37,7 +37,8 @@ public class Rapidshare extends PluginForHost{
|
||||
* Das DownloadLimit wurde erreicht
|
||||
* (?s)Downloadlimit.*Oder warte ([0-9]*)
|
||||
*/
|
||||
private Pattern patternDownloadLimitReached = Pattern.compile("(?s)Downloadlimit.*Oder warte ([0-9]*) ");
|
||||
private Pattern patternDownloadLimitReached = Pattern.compile("(?s)download-*limit.*([0-9]+) minute");
|
||||
private Pattern patternCaptchaWrong = Pattern.compile("zugriffscode falsch");
|
||||
|
||||
private int waitTime = 500;
|
||||
private String captchaAddress;
|
||||
@ -83,12 +84,22 @@ public class Rapidshare extends PluginForHost{
|
||||
//post daten lesen
|
||||
postTarget = getFirstMatch(requestInfo.getHtmlCode(), patternForFormData, 1);
|
||||
actionString = getFirstMatch(requestInfo.getHtmlCode(), patternForFormData, 2);
|
||||
currentStep = steps.firstElement();
|
||||
}
|
||||
else{
|
||||
logger.warning("file deleted?");
|
||||
}
|
||||
if(captchaAddress == null || postTarget == null || actionString == null){
|
||||
currentStep = steps.firstElement();
|
||||
if(newURL == null || captchaAddress == null || postTarget == null || actionString == null){
|
||||
if(newURL == null){
|
||||
logger.severe("file not found");
|
||||
setStatus(STATUS_FILE_NOT_FOUND);
|
||||
currentStep.setStatus(PluginStep.STATUS_ERROR);
|
||||
return currentStep;
|
||||
}
|
||||
String strWaitTime = getFirstMatch(requestInfo.getHtmlCode(), patternDownloadLimitReached, 1);
|
||||
if(strWaitTime != null){
|
||||
logger.severe("wait "+strWaitTime+" minutes");
|
||||
setStatus(STATUS_DOWNLOAD_LIMIT);
|
||||
currentStep.setStatus(PluginStep.STATUS_ERROR);
|
||||
return currentStep;
|
||||
}
|
||||
currentStep.setStatus(PluginStep.STATUS_ERROR);
|
||||
logger.warning("could not get downloadInfo");
|
||||
return currentStep;
|
||||
@ -116,10 +127,15 @@ public class Rapidshare extends PluginForHost{
|
||||
postParameter.put("accesscode", (String)steps.elementAt(1).getParameter());
|
||||
postParameter.put("actionString",actionString);
|
||||
boolean success = prepareDownload(downloadLink);
|
||||
if(success)
|
||||
if(success){
|
||||
todo.setStatus(PluginStep.STATUS_DONE);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
else{
|
||||
logger.severe("captcha wrong");
|
||||
setStatus(STATUS_CAPTCHA_WRONG);
|
||||
todo.setStatus(PluginStep.STATUS_ERROR);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return todo;
|
||||
@ -138,7 +154,6 @@ public class Rapidshare extends PluginForHost{
|
||||
int length = urlConnection.getContentLength();
|
||||
File fileOutput = downloadLink.getFileOutput();
|
||||
downloadLink.setDownloadLength(length);
|
||||
logger.info("starting download");
|
||||
return download(downloadLink, urlConnection);
|
||||
}
|
||||
catch (IOException e) { logger.severe("URL could not be opened. "+e.toString());}
|
||||
|
Loading…
Reference in New Issue
Block a user