-Connections are now closed correctly

git-svn-id: svn://svn.jdownloader.org/jdownloader/trunk@13296 ebf7c1c2-ba36-0410-9fe8-c592906822b4
This commit is contained in:
psp 2011-01-11 14:27:23 +00:00
parent 5ca30453d2
commit 3e862d51d4

View File

@ -52,22 +52,25 @@ public class EasyShareCom extends PluginForHost {
return "http://www.easy-share.com/tos.html"; return "http://www.easy-share.com/tos.html";
} }
private static final String MAINPAGE = "http://www.easy-share.com/";
private static final String FILENOTFOUND = "Requested file is deleted";
private void login(Account account) throws Exception { private void login(Account account) throws Exception {
this.setBrowserExclusive(); this.setBrowserExclusive();
br.setFollowRedirects(true); br.setFollowRedirects(true);
br.setCookie("http://www.easy-share.com", "language", "en"); br.setCookie(MAINPAGE, "language", "en");
br.getPage("http://www.easy-share.com/"); br.getPage(MAINPAGE);
br.setDebug(true); br.setDebug(true);
br.postPage("http://www.easy-share.com/accounts/login", "login=" + Encoding.urlEncode(account.getUser()) + "&password=" + Encoding.urlEncode(account.getPass()) + "&remember=1"); br.postPage("http://www.easy-share.com/accounts/login", "login=" + Encoding.urlEncode(account.getUser()) + "&password=" + Encoding.urlEncode(account.getPass()) + "&remember=1");
String acc = br.getCookie("http://www.easy-share.com/", "ACCOUNT"); String acc = br.getCookie(MAINPAGE, "ACCOUNT");
String prem = br.getCookie("http://www.easy-share.com/", "PREMIUM"); String prem = br.getCookie(MAINPAGE, "PREMIUM");
if (acc == null && prem == null) throw new PluginException(LinkStatus.ERROR_PREMIUM, PluginException.VALUE_ID_PREMIUM_DISABLE); if (acc == null && prem == null) throw new PluginException(LinkStatus.ERROR_PREMIUM, PluginException.VALUE_ID_PREMIUM_DISABLE);
if (acc != null && prem == null) { if (acc != null && prem == null) {
/* /*
* buggy easyshare server, login does not work always, it needs * buggy easyshare server, login does not work always, it needs
* PREMIUM cookie * PREMIUM cookie
*/ */
br.setCookie("http://www.easy-share.com/", "PREMIUM", acc); br.setCookie(MAINPAGE, "PREMIUM", acc);
} }
} }
@ -107,7 +110,7 @@ public class EasyShareCom extends PluginForHost {
public AvailableStatus requestFileInformation(DownloadLink downloadLink) throws IOException, PluginException { public AvailableStatus requestFileInformation(DownloadLink downloadLink) throws IOException, PluginException {
this.setBrowserExclusive(); this.setBrowserExclusive();
br.getHeaders().put("User-Agent", RandomUserAgent.generate()); br.getHeaders().put("User-Agent", RandomUserAgent.generate());
br.setCookie("http://www.easy-share.com", "language", "en"); br.setCookie(MAINPAGE, "language", "en");
String fileID = new Regex(downloadLink.getDownloadURL(), "easy-share\\.com/(\\d+)/").getMatch(0); String fileID = new Regex(downloadLink.getDownloadURL(), "easy-share\\.com/(\\d+)/").getMatch(0);
br.getPage("http://api.easy-share.com/files/" + fileID); br.getPage("http://api.easy-share.com/files/" + fileID);
if (br.containsHTML("(>errorFileNotFound<|>File Not Found<)")) throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND); if (br.containsHTML("(>errorFileNotFound<|>File Not Found<)")) throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND);
@ -123,11 +126,19 @@ public class EasyShareCom extends PluginForHost {
public void handleFree(DownloadLink downloadLink) throws Exception { public void handleFree(DownloadLink downloadLink) throws Exception {
/* Nochmals das File überprüfen */ /* Nochmals das File überprüfen */
requestFileInformation(downloadLink); requestFileInformation(downloadLink);
URLConnectionAdapter con = br.openGetConnection(downloadLink.getDownloadURL()); URLConnectionAdapter con = null;
br.setCookie("http://www.easy-share.com", "language", "en"); try {
if (con.getResponseCode() == 503) throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND); con = br.openGetConnection(downloadLink.getDownloadURL());
br.followConnection(); br.setCookie(MAINPAGE, "language", "en");
if (br.containsHTML("Requested file is deleted")) throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND); if (con.getResponseCode() == 503) throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND);
br.followConnection();
} finally {
try {
con.disconnect();
} catch (Throwable e) {
}
}
if (br.containsHTML(FILENOTFOUND)) throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND);
if (br.containsHTML("There is another download in progress from your IP")) throw new PluginException(LinkStatus.ERROR_IP_BLOCKED, 15 * 60 * 1000l); if (br.containsHTML("There is another download in progress from your IP")) throw new PluginException(LinkStatus.ERROR_IP_BLOCKED, 15 * 60 * 1000l);
if (br.containsHTML("You need a premium membership to download this file")) throw new PluginException(LinkStatus.ERROR_FATAL, JDL.L("plugins.host.errormsg.only4premium", "Only downloadable for premium users!")); if (br.containsHTML("You need a premium membership to download this file")) throw new PluginException(LinkStatus.ERROR_FATAL, JDL.L("plugins.host.errormsg.only4premium", "Only downloadable for premium users!"));
String wait = br.getRegex("w='(\\d+)'").getMatch(0); String wait = br.getRegex("w='(\\d+)'").getMatch(0);
@ -214,13 +225,21 @@ public class EasyShareCom extends PluginForHost {
public void handlePremium(DownloadLink downloadLink, Account account) throws Exception { public void handlePremium(DownloadLink downloadLink, Account account) throws Exception {
requestFileInformation(downloadLink); requestFileInformation(downloadLink);
login(account); login(account);
br.getPage("http://www.easy-share.com"); br.getPage(MAINPAGE);
br.setFollowRedirects(false); br.setFollowRedirects(false);
URLConnectionAdapter con = br.openGetConnection(downloadLink.getDownloadURL()); URLConnectionAdapter con = null;
br.setCookie("http://www.easy-share.com", "language", "en"); try {
if (con.getResponseCode() == 503) throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND); con = br.openGetConnection(downloadLink.getDownloadURL());
br.followConnection(); br.setCookie(MAINPAGE, "language", "en");
if (br.containsHTML("Requested file is deleted")) throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND); if (con.getResponseCode() == 503) throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND);
br.followConnection();
} finally {
try {
con.disconnect();
} catch (Throwable e) {
}
}
if (br.containsHTML(FILENOTFOUND)) throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND);
String url = null; String url = null;
if (br.getRedirectLocation() == null) { if (br.getRedirectLocation() == null) {
throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT); throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);