コード例 #1
0
  public String getFormattedFilename(final DownloadLink downloadLink) throws ParseException {
    String songTitle = downloadLink.getStringProperty("plainfilename", null);
    final SubConfiguration cfg = SubConfiguration.getConfig("soundcloud.com");
    String formattedFilename = cfg.getStringProperty(CUSTOM_FILENAME, defaultCustomFilename);
    if (formattedFilename == null || formattedFilename.equals(""))
      formattedFilename = defaultCustomFilename;
    if (!formattedFilename.contains("*songtitle*") || !formattedFilename.contains("*ext*"))
      formattedFilename = defaultCustomFilename;
    String ext = downloadLink.getStringProperty("type", null);
    if (ext != null) ext = "." + ext;
    else ext = ".mp3";

    String date = downloadLink.getStringProperty("originaldate", null);
    final String channelName = downloadLink.getStringProperty("channel", null);

    String formattedDate = null;
    if (date != null && formattedFilename.contains("*date*")) {
      // 2011-08-10T22:50:49Z
      date = date.replace("T", ":");
      final String userDefinedDateFormat =
          cfg.getStringProperty(CUSTOM_DATE, "dd.MM.yyyy_HH-mm-ss");
      SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd:HH:mm");
      Date dateStr = formatter.parse(date);

      formattedDate = formatter.format(dateStr);
      Date theDate = formatter.parse(formattedDate);

      if (userDefinedDateFormat != null) {
        try {
          formatter = new SimpleDateFormat(userDefinedDateFormat);
          formattedDate = formatter.format(theDate);
        } catch (Exception e) {
          // prevent user error killing plugin.
          formattedDate = "";
        }
      }
      if (formattedDate != null)
        formattedFilename = formattedFilename.replace("*date*", formattedDate);
      else formattedFilename = formattedFilename.replace("*date*", "");
    }
    if (formattedFilename.contains("*channelname*") && channelName != null) {
      formattedFilename = formattedFilename.replace("*channelname*", channelName);
    }
    formattedFilename = formattedFilename.replace("*ext*", ext);
    // Insert filename at the end to prevent errors with tags
    formattedFilename = formattedFilename.replace("*songtitle*", songTitle);

    return formattedFilename;
  }
コード例 #2
0
  public JDSimpleWebserver() {
    SubConfiguration subConfig = SubConfiguration.getConfig("WEBINTERFACE");
    Boolean https = subConfig.getBooleanProperty(JDWebinterface.PROPERTY_HTTPS, false);
    AuthUser =
        "******"
            + Encoding.Base64Encode(
                subConfig.getStringProperty(JDWebinterface.PROPERTY_USER, "JD")
                    + ":"
                    + subConfig.getStringProperty(JDWebinterface.PROPERTY_PASS, "JD"));
    NeedAuth = subConfig.getBooleanProperty(JDWebinterface.PROPERTY_LOGIN, true);
    boolean localhostonly =
        subConfig.getBooleanProperty(JDWebinterface.PROPERTY_LOCALHOST_ONLY, false);
    int port = subConfig.getIntegerProperty(JDWebinterface.PROPERTY_PORT, 8765);
    try {
      if (!https) {
        if (localhostonly) {
          Server_Socket = new ServerSocket(port, -1, HttpServer.getLocalHost());
        } else {
          Server_Socket = new ServerSocket(port);
        }
      } else {
        try {
          ServerSocketFactory ssocketFactory = setupSSL();

          if (localhostonly) {
            Server_Socket = ssocketFactory.createServerSocket(port, -1, HttpServer.getLocalHost());
          } else {
            Server_Socket = ssocketFactory.createServerSocket(port);
          }
        } catch (Exception e) {
          logger.severe("WebInterface: Server failed to start (SSL Setup Failed)!");
          return;
        }
      }
      logger.info("Webinterface: Server started");
      start();
    } catch (IOException e) {
      logger.severe("WebInterface: Server failed to start!");
    }
  }