diff options
Diffstat (limited to 'org.fox.ttrss/src/main/java/org/fox/ttrss/types/Article.java')
-rwxr-xr-x | org.fox.ttrss/src/main/java/org/fox/ttrss/types/Article.java | 94 |
1 files changed, 56 insertions, 38 deletions
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/types/Article.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/types/Article.java index ae28bb1d..3b2f8e6f 100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/types/Article.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/types/Article.java @@ -67,67 +67,85 @@ public class Article implements Parcelable { } public void collectMediaInfo() { - articleDoc = Jsoup.parse(content); - if (articleDoc != null) { - mediaList = articleDoc.select("img,video,iframe[src*=youtube.com/embed/]"); + // consider attachments first + if (attachments != null) { + for (Attachment a : attachments) { + if (a.content_type != null && a.content_type.contains("image/")) { + flavorImageUri = a.content_url; + + if (flavorImageUri != null && flavorImageUri.startsWith("//")) { + flavorImageUri = "https:" + flavorImageUri; + } - for (Element e : mediaList) { - if ("iframe".equals(e.tagName().toLowerCase())) { - flavorImage = e; - break; - } /*else if ("video".equals(e.tagName().toLowerCase())) { - flavorImage = e; break; - }*/ + } } + } + + // doing this the hard way then + if (flavorImageUri == null) { + articleDoc = Jsoup.parse(content); + + if (articleDoc != null) { + mediaList = articleDoc.select("img,video,iframe[src*=youtube.com/embed/]"); - if (flavorImage == null) { for (Element e : mediaList) { + if ("iframe".equals(e.tagName().toLowerCase())) { + flavorImage = e; + break; + } /*else if ("video".equals(e.tagName().toLowerCase())) { flavorImage = e; break; + }*/ } - } - if (flavorImage != null) { + if (flavorImage == null) { + for (Element e : mediaList) { + flavorImage = e; + break; + } + } - try { + if (flavorImage != null) { + try { - if ("video".equals(flavorImage.tagName().toLowerCase())) { - Element source = flavorImage.select("source").first(); - flavorStreamUri = source.attr("src"); + if ("video".equals(flavorImage.tagName().toLowerCase())) { + Element source = flavorImage.select("source").first(); + flavorStreamUri = source.attr("src"); - flavorImageUri = flavorImage.attr("poster"); - } else if ("iframe".equals(flavorImage.tagName().toLowerCase())) { + flavorImageUri = flavorImage.attr("poster"); + } else if ("iframe".equals(flavorImage.tagName().toLowerCase())) { - String srcEmbed = flavorImage.attr("src"); + String srcEmbed = flavorImage.attr("src"); - if (srcEmbed.length() > 0) { - Pattern pattern = Pattern.compile("/embed/([\\w-]+)"); - Matcher matcher = pattern.matcher(srcEmbed); + if (srcEmbed.length() > 0) { + Pattern pattern = Pattern.compile("/embed/([\\w-]+)"); + Matcher matcher = pattern.matcher(srcEmbed); - if (matcher.find()) { - youtubeVid = matcher.group(1); + if (matcher.find()) { + youtubeVid = matcher.group(1); - flavorImageUri = "https://img.youtube.com/vi/" + youtubeVid + "/hqdefault.jpg"; - flavorStreamUri = "https://youtu.be/" + youtubeVid; + flavorImageUri = "https://img.youtube.com/vi/" + youtubeVid + "/hqdefault.jpg"; + flavorStreamUri = "https://youtu.be/" + youtubeVid; + } + } + } else { + flavorImageUri = flavorImage.attr("src"); + + if (flavorImageUri != null && flavorImageUri.startsWith("//")) { + flavorImageUri = "https:" + flavorImageUri; } - } - } else { - flavorImageUri = flavorImage.attr("src"); - if (flavorImageUri != null && flavorImageUri.startsWith("//")) { - flavorImageUri = "https:" + flavorImageUri; + flavorStreamUri = null; } + } catch (Exception e) { + e.printStackTrace(); + flavorImage = null; + flavorImageUri = null; flavorStreamUri = null; } - } catch (Exception e) { - e.printStackTrace(); - - flavorImage = null; - flavorImageUri = null; - flavorStreamUri = null; } } } |