| 1 | package be.nikiroo.gofetch.support; |
| 2 | |
| 3 | import java.io.IOException; |
| 4 | import java.net.URL; |
| 5 | import java.util.AbstractMap; |
| 6 | import java.util.ArrayList; |
| 7 | import java.util.List; |
| 8 | import java.util.Map.Entry; |
| 9 | |
| 10 | import org.jsoup.nodes.Document; |
| 11 | import org.jsoup.nodes.Element; |
| 12 | import org.jsoup.nodes.Node; |
| 13 | |
| 14 | /** |
| 15 | * Support <a href="https://www.7sur7.be/">https://www.7sur7.be/</a>. |
| 16 | * |
| 17 | * @author niki |
| 18 | */ |
| 19 | public class SeptSurSept extends BasicSupport { |
| 20 | @Override |
| 21 | public String getDescription() { |
| 22 | return "7SUR7.be Info, sport et showbiz, 24/24, 7/7"; |
| 23 | } |
| 24 | |
| 25 | @Override |
| 26 | public void login() throws IOException { |
| 27 | addCookie("pwrefr2", ""); |
| 28 | addCookie("pwv-atXMVFeyFP1Ki09i", "1"); |
| 29 | addCookie("pwg-atXMVFeyFP1Ki09i", "basic"); |
| 30 | |
| 31 | addCookie("pwv", "1"); |
| 32 | addCookie("pw", "functional"); |
| 33 | |
| 34 | URL url = new URL("https://www.7sur7.be/7s7/privacy/callback.do" |
| 35 | + "?redirectUri=/" + "&pwv=1" + "&pws=functional%7Canalytics" |
| 36 | + "&days=3650" + "&referrer="); |
| 37 | |
| 38 | open(url).close(); |
| 39 | } |
| 40 | |
| 41 | @Override |
| 42 | protected List<Entry<URL, String>> getUrls() throws IOException { |
| 43 | List<Entry<URL, String>> urls = new ArrayList<Entry<URL, String>>(); |
| 44 | URL url = new URL("https://www.7sur7.be/"); |
| 45 | urls.add(new AbstractMap.SimpleEntry<URL, String>(url, "")); |
| 46 | |
| 47 | return urls; |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | protected List<Element> getArticles(Document doc) { |
| 52 | return doc.getElementsByClass("clip"); |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | protected String getArticleId(Document doc, Element article) { |
| 57 | String id = article.attr("id"); |
| 58 | if (id != null && id.startsWith("clip")) { |
| 59 | return id.substring("clip".length()); |
| 60 | } |
| 61 | |
| 62 | return null; |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | protected String getArticleTitle(Document doc, Element article) { |
| 67 | return article.attr("data-title"); |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | protected String getArticleAuthor(Document doc, Element article) { |
| 72 | return ""; |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | protected String getArticleDate(Document doc, Element article) { |
| 77 | return article.attr("data-date"); |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | protected String getArticleCategory(Document doc, Element article, |
| 82 | String currentCategory) { |
| 83 | Element parent = article.parent(); |
| 84 | if (parent != null) { |
| 85 | Element catElement = parent.previousElementSibling(); |
| 86 | if (catElement != null) { |
| 87 | return catElement.text(); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | return ""; |
| 92 | } |
| 93 | |
| 94 | @Override |
| 95 | protected String getArticleDetails(Document doc, Element article) { |
| 96 | return ""; |
| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | protected String getArticleIntUrl(Document doc, Element article) { |
| 101 | return article.absUrl("href"); |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | protected String getArticleExtUrl(Document doc, Element article) { |
| 106 | return ""; |
| 107 | } |
| 108 | |
| 109 | @Override |
| 110 | protected String getArticleContent(Document doc, Element article) { |
| 111 | return article.attr("data-intro").trim(); |
| 112 | } |
| 113 | |
| 114 | @Override |
| 115 | protected Element getFullArticle(Document doc) { |
| 116 | return doc.getElementById("detail_content"); |
| 117 | } |
| 118 | |
| 119 | @Override |
| 120 | protected List<Element> getFullArticleCommentPosts(Document doc, URL intUrl) { |
| 121 | return getSubCommentElements(doc.getElementsByClass("comment-list") |
| 122 | .first()); |
| 123 | } |
| 124 | |
| 125 | @Override |
| 126 | protected ElementProcessor getElementProcessorFullArticle() { |
| 127 | return new BasicElementProcessor() { |
| 128 | @Override |
| 129 | public boolean ignoreNode(Node node) { |
| 130 | return node.attr("class").contains("chapo"); |
| 131 | } |
| 132 | |
| 133 | @Override |
| 134 | public String isSubtitle(Node node) { |
| 135 | if (node instanceof Element) { |
| 136 | Element element = (Element) node; |
| 137 | if (element.tagName().startsWith("h") |
| 138 | && element.tagName().length() == 2) { |
| 139 | return element.text(); |
| 140 | } |
| 141 | } |
| 142 | return null; |
| 143 | } |
| 144 | }; |
| 145 | } |
| 146 | |
| 147 | @Override |
| 148 | protected List<Element> getCommentCommentPosts(Document doc, |
| 149 | Element container) { |
| 150 | return getSubCommentElements(container.getElementsByClass("children") |
| 151 | .first()); |
| 152 | } |
| 153 | |
| 154 | @Override |
| 155 | protected String getCommentId(Element post) { |
| 156 | Element idE = post.getElementsByTag("a").first(); |
| 157 | if (idE != null) { |
| 158 | return idE.attr("id"); |
| 159 | } |
| 160 | |
| 161 | return ""; |
| 162 | } |
| 163 | |
| 164 | @Override |
| 165 | protected String getCommentAuthor(Element post) { |
| 166 | // Since we have no title, we switch with author |
| 167 | return ""; |
| 168 | } |
| 169 | |
| 170 | @Override |
| 171 | protected String getCommentTitle(Element post) { |
| 172 | // Since we have no title, we switch with author |
| 173 | Element authorE = post.getElementsByTag("footer").first(); |
| 174 | if (authorE != null) { |
| 175 | authorE = authorE.getElementsByTag("cite").first(); |
| 176 | } |
| 177 | if (authorE != null) { |
| 178 | return authorE.text(); |
| 179 | } |
| 180 | |
| 181 | return ""; |
| 182 | } |
| 183 | |
| 184 | @Override |
| 185 | protected String getCommentDate(Element post) { |
| 186 | Element idE = post.getElementsByTag("a").first(); |
| 187 | if (idE != null) { |
| 188 | Element dateE = idE.getElementsByTag("span").first(); |
| 189 | if (dateE != null) { |
| 190 | return dateE.attr("data-epoch"); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | return ""; |
| 195 | } |
| 196 | |
| 197 | @Override |
| 198 | protected Element getCommentContentElement(Element post) { |
| 199 | Element contentE = post.getElementsByClass("comment-content").first(); |
| 200 | return contentE; |
| 201 | } |
| 202 | |
| 203 | @Override |
| 204 | protected ElementProcessor getElementProcessorComment() { |
| 205 | return new BasicElementProcessor() { |
| 206 | @Override |
| 207 | public boolean ignoreNode(Node node) { |
| 208 | if (node instanceof Element) { |
| 209 | Element el = (Element) node; |
| 210 | if ("h4".equals(el.tagName())) { |
| 211 | return true; |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | return false; |
| 216 | } |
| 217 | }; |
| 218 | } |
| 219 | |
| 220 | private List<Element> getSubCommentElements(Element posts) { |
| 221 | List<Element> commentElements = new ArrayList<Element>(); |
| 222 | if (posts != null) { |
| 223 | for (Element possibleCommentElement : posts.children()) { |
| 224 | if (possibleCommentElement.hasClass("comment")) { |
| 225 | commentElements.add(possibleCommentElement); |
| 226 | } |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | return commentElements; |
| 231 | } |
| 232 | } |