Ejemplo n.º 1
0
  public void downloadPost(JDFeedMeFeed feed, JDFeedMePost post, String post_description) {
    String link_list_to_download = null;

    // check if we have a valid files field
    if ((link_list_to_download == null) && (post.hasValidFiles())) {
      // just take the files field
      link_list_to_download =
          extractLinksFromHtml(post.getFiles(), feed.getHoster(), JDFeedMeFeed.HOSTER_EXCLUDE);
    }

    // no file fields, maybe we have a good link
    if ((link_list_to_download == null) && (post.hasValidLink())) {
      // try to follow this link
      try {
        Browser browser = new Browser();
        browser.setFollowRedirects(true); // support redirects since some feeds have them
        String response = browser.getPage(post.getLink());
        link_list_to_download =
            extractLinksFromHtml(response, feed.getHoster(), JDFeedMeFeed.HOSTER_EXCLUDE);
      } catch (Exception e) {
        logger.severe("JDFeedMe could not follow feed item link: " + post.getLink());
      }
    }

    // no good link, try the description
    if ((link_list_to_download == null)
        && (post_description != null)
        && (post_description.trim().length() > 0)) {
      link_list_to_download =
          extractLinksFromHtml(post_description, feed.getHoster(), JDFeedMeFeed.HOSTER_EXCLUDE);
    }

    // nothing, exit
    if (link_list_to_download == null) {
      post.setAdded(JDFeedMePost.ADDED_YES_NO_FILES);
      return;
    }

    // JOptionPane.showMessageDialog(new JFrame(), "JDFeedMe says we need to download link:
    // "+rssitem.link);
    logger.info("JDFeedMe attempting to download: " + link_list_to_download);

    // let's download the links.. finally..
    boolean anything_downloaded = downloadLinks(link_list_to_download, feed, post);
    if (anything_downloaded) {
      post.setAdded(JDFeedMePost.ADDED_YES);
      gui.notifyPostAddedInOtherFeed(post, feed);
    } else post.setAdded(JDFeedMePost.ADDED_YES_NO_FILES);
  }
Ejemplo n.º 2
0
  // return true if the post is new, false if old
  private boolean handlePost(
      JDFeedMeFeed feed, JDFeedMePost post, String post_description, String timestamp) {
    // make sure this rss item is indeed newer than what we have
    if (post.isTimestampNewer(timestamp)) {
      if (JDFeedMe.VERBOSE)
        logger.info("JDFeedMe found new item with timestamp: [" + post.getTimestamp() + "]");
      post.setNewpost(true);

      // check for filters on this item (see if it passes download filters)
      boolean need_to_add = runFilterOnPost(feed, post, post_description);

      // if we don't need to add, we can return now
      if (!need_to_add) {
        if (JDFeedMe.VERBOSE)
          logger.info(
              "JDFeedMe new item title: ["
                  + post.getTitle()
                  + "] description: ["
                  + post_description
                  + "] did not pass filters");
        post.setAdded(JDFeedMePost.ADDED_NO);
      } else {
        // start processing this rss item - we're going to download it
        downloadPost(feed, post, post_description);
      }

      // update the post history
      gui.addPostToFeed(post, feed);

      return true;
    } else {
      if (JDFeedMe.VERBOSE)
        logger.info("JDFeedMe ignoring item with old timestamp: [" + post.getTimestamp() + "]");
      return false;
    }
  }