From dfe11166d7e182d835278984518885c5c436a33a Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 14 Aug 2019 15:52:34 +0300 Subject: collectMediaInfo: prefer article content to enclosures --- .../src/main/java/org/fox/ttrss/types/Article.java | 122 ++++++++++----------- 1 file changed, 60 insertions(+), 62 deletions(-) (limited to 'org.fox.ttrss/src/main/java') 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 da58dabe..070ddcc0 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,89 +67,87 @@ public class Article implements Parcelable { } public void collectMediaInfo() { + articleDoc = Jsoup.parse(content); - // 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; - } - - // this is needed for the gallery view - flavorImage = new Element("img") - .attr("src", flavorImageUri); + if (articleDoc != null) { + mediaList = articleDoc.select("img,video,iframe[src*=youtube.com/embed/]"); + 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) { - for (Element e : mediaList) { - flavorImage = e; - break; - } - } - - if (flavorImage != null) { - try { - - if ("video".equals(flavorImage.tagName().toLowerCase())) { - Element source = flavorImage.select("source").first(); - flavorStreamUri = source.attr("src"); + if (flavorImage != null) { + try { - flavorImageUri = flavorImage.attr("poster"); - } else if ("iframe".equals(flavorImage.tagName().toLowerCase())) { + if ("video".equals(flavorImage.tagName().toLowerCase())) { + Element source = flavorImage.select("source").first(); + flavorStreamUri = source.attr("src"); - String srcEmbed = flavorImage.attr("src"); + flavorImageUri = flavorImage.attr("poster"); + } else if ("iframe".equals(flavorImage.tagName().toLowerCase())) { - if (srcEmbed.length() > 0) { - Pattern pattern = Pattern.compile("/embed/([\\w-]+)"); - Matcher matcher = pattern.matcher(srcEmbed); + String srcEmbed = flavorImage.attr("src"); - if (matcher.find()) { - youtubeVid = matcher.group(1); + if (srcEmbed.length() > 0) { + Pattern pattern = Pattern.compile("/embed/([\\w-]+)"); + Matcher matcher = pattern.matcher(srcEmbed); - flavorImageUri = "https://img.youtube.com/vi/" + youtubeVid + "/hqdefault.jpg"; - flavorStreamUri = "https://youtu.be/" + youtubeVid; - } - } - } else { - flavorImageUri = flavorImage.attr("src"); + if (matcher.find()) { + youtubeVid = matcher.group(1); - if (flavorImageUri != null && flavorImageUri.startsWith("//")) { - flavorImageUri = "https:" + flavorImageUri; + flavorImageUri = "https://img.youtube.com/vi/" + youtubeVid + "/hqdefault.jpg"; + flavorStreamUri = "https://youtu.be/" + youtubeVid; } + } + } else { + flavorImageUri = flavorImage.attr("src"); - flavorStreamUri = null; + if (flavorImageUri != null && flavorImageUri.startsWith("//")) { + flavorImageUri = "https:" + flavorImageUri; } - } catch (Exception e) { - e.printStackTrace(); - flavorImage = null; - flavorImageUri = null; flavorStreamUri = null; } + } catch (Exception e) { + e.printStackTrace(); + + flavorImage = null; + flavorImageUri = null; + flavorStreamUri = null; + } + } + } + + if (flavorImageUri == null) { + // consider attachments + 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; + } + + // this is needed for the gallery view + flavorImage = new Element("img") + .attr("src", flavorImageUri); + + break; + } } } } @@ -159,7 +157,7 @@ public class Article implements Parcelable { public Article(int id) { this.id = id; - this.title = "ID:" + String.valueOf(id); + this.title = "ID:" + id; this.link = ""; this.tags = new ArrayList(); } -- cgit v1.2.3