From 9e0c94f1a4d85bbde6806dc33248ccafc4d35f63 Mon Sep 17 00:00:00 2001 From: Tyler Gebhard Date: Sun, 26 Oct 2014 03:03:02 -0400 Subject: [PATCH] changes to the way favicons are retrieved for YouTube feeds. Now instead of fetching the YouTube logo, it fetches the YouTube user's custom thumbnail. --- .../backend/feed/FaviconFetcher.java | 59 +++++++++++++++++++ .../com/commafeed/backend/feed/FeedUtils.java | 14 +++++ .../commafeed/frontend/resource/FeedREST.java | 2 +- 3 files changed, 74 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/commafeed/backend/feed/FaviconFetcher.java b/src/main/java/com/commafeed/backend/feed/FaviconFetcher.java index a7349422..aeeec33e 100644 --- a/src/main/java/com/commafeed/backend/feed/FaviconFetcher.java +++ b/src/main/java/com/commafeed/backend/feed/FaviconFetcher.java @@ -39,6 +39,12 @@ public class FaviconFetcher { log.debug("url is null"); return null; } + + // Get YouTube Icon here + if (url.toLowerCase().contains("://gdata.youtube.com/")) { + byte[] icon = getYouTubeIcon(url); + return icon; + } int doubleSlash = url.indexOf("//"); if (doubleSlash == -1) { @@ -154,4 +160,57 @@ public class FaviconFetcher { return bytes; } + /* + * Instead of grabbing the actual favicon, grab the user's icon + * This prevents a whole bunch of repeated YouTube icons, replacing + * each with identifiable user icons. + */ + private byte[] getYouTubeIcon(String url) { + byte[] bytes = null; + String contentType = null; + String username = null; + String imageUrl = null; + String thumbnailUrl = null; + try { + int apiOrBase = url.indexOf("/users/"); + int userEndSlash = url.indexOf('/', apiOrBase + "/users/".length()); + if (userEndSlash != -1) { + username = url.substring(apiOrBase + "/users/".length(), userEndSlash); + } + imageUrl = "https://gdata.youtube.com/feeds/users/" + username; + log.debug("Getting YouTube user's icon, {}", url); + + //initial get to translate username to obscure user thumbnail URL + HttpResult result = getter.getBinary(imageUrl, TIMEOUT); + bytes = result.getContent(); + contentType = result.getContentType(); + thumbnailUrl = FeedUtils.parseForImageUrl(bytes); + + int thumbnailStart = thumbnailUrl.indexOf("", thumbnailStart); + if (thumbnailStart != -1) { + thumbnailUrl = thumbnailUrl.substring(thumbnailStart+"