Ejemplo n.º 1
0
  @Override
  public void handleFree(final DownloadLink downloadLink) throws Exception {
    final LinkStatus linkStatus = downloadLink.getLinkStatus();

    this.dl =
        jd.plugins.BrowserAdapter.openDownload(
            this.br, downloadLink, downloadLink.getDownloadURL());
    URLConnectionAdapter urlConnection = this.dl.connect();
    if (urlConnection.getLongContentLength() == 0) {
      this.br.followConnection();
      linkStatus.addStatus(LinkStatus.ERROR_PLUGIN_DEFECT);
      return;
    }

    if (this.dl.startDownload()) {
      if (downloadLink.getProperty("convertto") != null) {
        final DestinationFormat convertTo =
            DestinationFormat.valueOf(downloadLink.getProperty("convertto").toString());
        final DestinationFormat inType = DestinationFormat.VIDEOFLV;
        /* to load the TbCm plugin */
        JDUtilities.getPluginForDecrypt("youtube.com");
        if (!TbCm.ConvertFile(downloadLink, inType, convertTo)) {
          Plugin.logger.severe("Video-Convert failed!");
        }
      }
    }
  }
    /**
     * ueber error() kann ein fehler gemeldet werden. DIe Methode entscheided dann ob dieser fehler zu einem Abbruch fuehren muss
     */
    protected synchronized void error(int id, String string) {
        /* if we recieved external stop, then we dont have to handle errors */
        if (externalDownloadStop()) return;

        logger.severe("Error occured (" + id + "): ");

        if (errors.indexOf(id) < 0) errors.add(id);
        if (fatalErrorOccured) return;

        linkStatus.addStatus(id);

        linkStatus.setErrorMessage(string);
        switch (id) {
        case LinkStatus.ERROR_RETRY:
        case LinkStatus.ERROR_FATAL:
        case LinkStatus.ERROR_TIMEOUT_REACHED:
        case LinkStatus.ERROR_FILE_NOT_FOUND:
        case LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE:
        case LinkStatus.ERROR_LOCAL_IO:
        case LinkStatus.ERROR_NO_CONNECTION:
        case LinkStatus.ERROR_ALREADYEXISTS:
        case LinkStatus.ERROR_DOWNLOAD_FAILED:
            fatalErrorOccured = true;
            terminate();
        }
    }
 /**
  * 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();
     }
 }