mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
check if the feed has changed by using publishDate of the feed or the first entry
This commit is contained in:
@@ -36,16 +36,18 @@ public class FeedFetcher {
|
||||
|
||||
HttpResult result = getter.getBinary(feedUrl, lastModified, eTag);
|
||||
if (extractFeedUrlFromHtml) {
|
||||
String extractedUrl = extractFeedUrl(StringUtils
|
||||
.newStringUtf8(result.getContent()), feedUrl);
|
||||
String extractedUrl = extractFeedUrl(
|
||||
StringUtils.newStringUtf8(result.getContent()), feedUrl);
|
||||
if (org.apache.commons.lang.StringUtils.isNotBlank(extractedUrl)) {
|
||||
result = getter.getBinary(extractedUrl, lastModified, eTag);
|
||||
feedUrl = extractedUrl;
|
||||
}
|
||||
}
|
||||
feed = parser.parse(feedUrl, result.getContent());
|
||||
|
||||
feed.setLastModifiedHeader(result.getLastModifiedSince());
|
||||
feed.setEtagHeader(result.geteTag());
|
||||
feed.setFetchDuration(result.getDuration());
|
||||
return feed;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,8 +39,9 @@ public class FeedParser {
|
||||
|
||||
try {
|
||||
InputSource source = new InputSource(new ByteArrayInputStream(xml));
|
||||
if (new String(ArrayUtils.subarray(xml, 0, 100)).split(SystemUtils.LINE_SEPARATOR)[0]
|
||||
.toUpperCase().contains("ISO-8859-1")) {
|
||||
if (new String(ArrayUtils.subarray(xml, 0, 100))
|
||||
.split(SystemUtils.LINE_SEPARATOR)[0].toUpperCase()
|
||||
.contains("ISO-8859-1")) {
|
||||
// they probably use word, we need to handle curly quotes and
|
||||
// other word special characters
|
||||
source.setEncoding("windows-1252");
|
||||
@@ -70,6 +71,13 @@ public class FeedParser {
|
||||
|
||||
feed.getEntries().add(entry);
|
||||
}
|
||||
Date publishedDate = rss.getPublishedDate();
|
||||
if (publishedDate == null && !feed.getEntries().isEmpty()) {
|
||||
FeedEntry first = feed.getEntries().iterator().next();
|
||||
publishedDate = first.getUpdated();
|
||||
}
|
||||
feed.setPublishedDate(publishedDate);
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new FeedException(String.format(
|
||||
"Could not parse feed from %s : %s", feedUrl,
|
||||
|
||||
@@ -86,6 +86,13 @@ public class FeedRefreshWorker {
|
||||
try {
|
||||
fetchedFeed = fetcher.fetch(feed.getUrl(), false,
|
||||
feed.getLastModifiedHeader(), feed.getEtagHeader());
|
||||
if (fetchedFeed.getPublishedDate() != null
|
||||
&& feed.getLastUpdateSuccess() != null
|
||||
&& fetchedFeed.getPublishedDate().before(
|
||||
feed.getLastUpdateSuccess())) {
|
||||
throw new NotModifiedException();
|
||||
}
|
||||
feed.setLastUpdateSuccess(Calendar.getInstance().getTime());
|
||||
} catch (NotModifiedException e) {
|
||||
modified = false;
|
||||
log.debug("Feed not modified (304) : " + feed.getUrl());
|
||||
|
||||
Reference in New Issue
Block a user