Embed YouTube

This commit is contained in:
M66B 2023-05-10 10:47:38 +02:00
parent d241aa2ded
commit a429d2a64d
1 changed files with 20 additions and 0 deletions

View File

@ -1616,6 +1616,26 @@ public class HtmlHelper {
}, document);
}
static boolean embedYouTube(Document document) {
// https://developers.google.com/youtube/player_parameters
// Requires: setBlockNetworkLoads and setJavaScriptEnabled
boolean has = false;
for (Element a : document.select("a"))
if (a.attr("href").startsWith("https://www.youtube.com/embed/")) {
String link = a.attr("href");
a.tagName("iframe");
a.attr("id", link.substring(link.lastIndexOf("/") + 1));
a.attr("type", "text/html");
a.attr("src", link);
a.attr("frameborder", "0");
a.removeAttr("href");
if (a.text().equals(link))
a.text("");
has = true;
}
return has;
}
static void guessSchemes(Document document) {
for (Element e : document.select("a,img"))
try {