Exemplo n.º 1
0
 public AvailableStatus requestFileInformation(DownloadLink downloadLink)
     throws IOException, InterruptedException, PluginException {
   this.setBrowserExclusive();
   br.setCustomCharset("UTF-8");
   br.setFollowRedirects(true);
   URLConnectionAdapter con = br.openGetConnection(downloadLink.getDownloadURL());
   if (con.isContentDisposition()) {
     downloadLink.setFinalFileName(Plugin.getFileNameFromHeader(con));
     downloadLink.setDownloadSize(con.getLongContentLength());
     con.disconnect();
     return AvailableStatus.TRUE;
   } else {
     return AvailableStatus.FALSE;
   }
 }
 /**
  * Startet den Download. Nach dem Aufruf dieser Funktion koennen keine Downlaodparameter mehr gesetzt werden bzw bleiben wirkungslos.
  * 
  * @return
  * @throws Exception
  */
 public boolean startDownload() throws Exception {
     try {
         startTimeStamp = System.currentTimeMillis();
         sizeBefore = downloadLink.getDownloadCurrent();
         linkStatus.addStatus(LinkStatus.DOWNLOADINTERFACE_IN_PROGRESS);
         try {
             downloadLink.getDownloadLinkController().getConnectionHandler().addConnectionHandler(this.getManagedConnetionHandler());
         } catch (final Throwable e) {
         }
         /*if (this.dlAlreadyFinished == false) {
             try {
                 boolean watchAsYouDownloadTypeLink = (Boolean) downloadLink.getFilePackage().getProperty(org.jdownloader.extensions.neembuu.NeembuuExtension.WATCH_AS_YOU_DOWNLOAD_KEY, false);
                 boolean initiatedByWatchAsYouDownloadAction = (Boolean) downloadLink.getFilePackage().getProperty(org.jdownloader.extensions.neembuu.NeembuuExtension.INITIATED_BY_WATCH_ACTION, false);
                 if (watchAsYouDownloadTypeLink && initiatedByWatchAsYouDownloadAction) {
                     org.jdownloader.extensions.neembuu.DownloadSession downloadSession = new org.jdownloader.extensions.neembuu.DownloadSession(downloadLink, this, this.plugin, this.getConnection(), this.browser.cloneBrowser());
                     if (org.jdownloader.extensions.neembuu.NeembuuExtension.tryHandle(downloadSession)) {
                         org.jdownloader.extensions.neembuu.WatchAsYouDownloadSession watchAsYouDownloadSession = downloadSession.getWatchAsYouDownloadSession();
                         try {
                             watchAsYouDownloadSession.waitForDownloadToFinish();
                         } catch (Exception a) {
                             logger.log(Level.SEVERE, "Exception in waiting for neembuu watch as you download", a);
                             // if we do not return, normal download would start.
                             return false;
                         }
                         return true;
                     }
                     int o = 0;
                     try {
                         o = Dialog.I().showConfirmDialog(Dialog.LOGIC_COUNTDOWN, org.jdownloader.extensions.neembuu.translate._NT._.neembuu_could_not_handle_title(), org.jdownloader.extensions.neembuu.translate._NT._.neembuu_could_not_handle_message());
                     } catch (Exception a) {
                         o = Dialog.RETURN_CANCEL;
                     }
                     if (o == Dialog.RETURN_CANCEL) return false;
                     logger.severe("Neembuu could not handle this link/filehost. Using default download system.");
                 } else if (watchAsYouDownloadTypeLink && !initiatedByWatchAsYouDownloadAction) {
                     // Neembuu downloads should start if and only if user clicks
                     // watch as you download
                     // action in the context menu. We don't want neembuu to
                     // start when user pressed
                     // forced download, or simple download button.
                     // We shall skip this link and disable all in this
                     // filepackage
                     for (DownloadLink dl : downloadLink.getFilePackage().getChildren()) {
                         dl.setEnabled(false);
                     }
                     // TODO: change me 
                     throw new PluginException(LinkStatus.ERROR_FATAL);
                 }
             } catch (final Throwable e) {
                 logger.severe("Exception in neembuu watch as you download");
                 LogSource.exception(logger, e);
             }
         }*/
         logger.finer("Start Download");
         if (this.dlAlreadyFinished == true) {
             downloadLink.setAvailable(true);
             logger.finer("DownloadAlreadyFinished workaround");
             linkStatus.setStatus(LinkStatus.FINISHED);
             return true;
         }
         if (!connected) connect();
         if (connection != null && connection.getHeaderField("Content-Encoding") != null && connection.getHeaderField("Content-Encoding").equalsIgnoreCase("gzip")) {
             /* GZIP Encoding kann weder chunk noch resume */
             setResume(false);
             setChunkNum(1);
         }
         // Erst hier Dateinamen holen, somit umgeht man das Problem das bei
         // mehrfachAufruf von connect entstehen kann
         if (this.downloadLink.getFinalFileName() == null && ((connection != null && connection.isContentDisposition()) || this.allowFilenameFromURL)) {
             String name = Plugin.getFileNameFromHeader(connection);
             if (this.fixWrongContentDispositionHeader) {
                 this.downloadLink.setFinalFileName(Encoding.htmlDecode(name));
             } else {
                 this.downloadLink.setFinalFileName(name);
             }
         }
         downloadLink.getLinkStatus().setStatusText(null);
         if (connection == null || !connection.isOK()) {
             if (connection != null) logger.finest(connection.toString());
             try {
                 connection.disconnect();
             } catch (final Throwable e) {
             }
             throw new PluginException(LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, 10 * 60 * 1000l);
         }
         if (connection.getHeaderField("Location") != null) {
             error(LinkStatus.ERROR_PLUGIN_DEFECT, "Sent a redirect to Downloadinterface");
             return false;
         }
         if (downloadLink.getVerifiedFileSize() < 0) {
             /* we don't have a verified filesize yet, let's check if we have it now! */
             if (connection.getRange() != null) {
                 if (connection.getRange()[2] > 0) {
                     downloadLink.setVerifiedFileSize(connection.getRange()[2]);
                 }
             } else if (connection.getRequestProperty("Range") == null && connection.getLongContentLength() > 0 && connection.isOK()) {
                 downloadLink.setVerifiedFileSize(connection.getLongContentLength());
             }
         }
         //if (DownloadWatchDog.preDownloadCheckFailed(downloadLink)) return false;
         setupChunks();
         /* download in progress so file should be online ;) */
         downloadLink.setAvailable(true);
         waitForChunks();
         onChunksReady();
         return handleErrors();
     } catch (Exception e) {
         if (e instanceof FileNotFoundException) {
             this.error(LinkStatus.ERROR_LOCAL_IO, _JDT._.download_error_message_localio(e.getMessage()));
         } else {
             LogSource.exception(logger, e);
         }
         handleErrors();
         return false;
     } finally {
         try {
             downloadLink.getDownloadLinkController().getConnectionHandler().removeConnectionHandler(this.getManagedConnetionHandler());
         } catch (final Throwable e) {
         }
         linkStatus.removeStatus(LinkStatus.DOWNLOADINTERFACE_IN_PROGRESS);
         try {
             this.connection.disconnect();
         } catch (Throwable e) {
         }
         /* make sure file is really closed */
         cleanupDownladInterface();
     }
 }