fix youtube icons (#658)

This commit is contained in:
Athou
2014-10-27 05:23:36 +01:00
parent 165f3ed25a
commit 19964d253e
4 changed files with 12 additions and 5 deletions

View File

@@ -7,6 +7,8 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import com.commafeed.backend.model.Feed;
@Slf4j
public abstract class AbstractFaviconFetcher {
@@ -16,7 +18,7 @@ public abstract class AbstractFaviconFetcher {
protected static int TIMEOUT = 4000;
public abstract byte[] fetch(String url);
public abstract byte[] fetch(Feed feed);
protected boolean isValidIconResponse(byte[] content, String contentType) {
if (content == null) {

View File

@@ -14,6 +14,7 @@ import org.jsoup.select.Elements;
import com.commafeed.backend.HttpGetter;
import com.commafeed.backend.HttpGetter.HttpResult;
import com.commafeed.backend.feed.FeedUtils;
import com.commafeed.backend.model.Feed;
/**
* Inspired/Ported from https://github.com/potatolondon/getfavicon
@@ -27,7 +28,9 @@ public class DefaultFaviconFetcher extends AbstractFaviconFetcher {
private final HttpGetter getter;
@Override
public byte[] fetch(String url) {
public byte[] fetch(Feed feed) {
String url = feed.getLink() != null ? feed.getLink() : feed.getUrl();
if (url == null) {
log.debug("url is null");
return null;

View File

@@ -12,6 +12,7 @@ import org.jsoup.select.Elements;
import com.commafeed.backend.HttpGetter;
import com.commafeed.backend.HttpGetter.HttpResult;
import com.commafeed.backend.model.Feed;
@Slf4j
@RequiredArgsConstructor(onConstructor = @__({ @Inject }))
@@ -21,7 +22,9 @@ public class YoutubeFaviconFetcher extends AbstractFaviconFetcher {
private final HttpGetter getter;
@Override
public byte[] fetch(String url) {
public byte[] fetch(Feed feed) {
String url = feed.getUrl();
if (!url.toLowerCase().contains("://gdata.youtube.com/")) {
return null;
}

View File

@@ -50,11 +50,10 @@ public class FeedService {
}
public byte[] fetchFavicon(Feed feed) {
String url = feed.getLink() != null ? feed.getLink() : feed.getUrl();
byte[] icon = null;
for (AbstractFaviconFetcher faviconFetcher : faviconFetchers) {
icon = faviconFetcher.fetch(url);
icon = faviconFetcher.fetch(feed);
if (icon != null) {
break;
}