commit 464f00b4600318887d157ef8b293226fbeb5c9ef parent f9350c7950423415749aeee0e2c02762119940b0 Author: corndog <cauchyn@firemail.cc> Date: Thu, 27 Sep 2018 11:22:22 -0700 We actually build on the deployment server Diffstat:
| youtube-embed.py | | | 27 | +++++++++++++++++++++++++++ |
1 file changed, 27 insertions(+), 0 deletions(-)
diff --git a/youtube-embed.py b/youtube-embed.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 + +from bs4 import BeautifulSoup +import sys + +raw = sys.stdin.read() +raw = BeautifulSoup(raw, "html.parser") + +lists = raw.find_all('li') +for li in lists: + anchor = li.find('a') + if not anchor: + continue + if "youtube.com" in anchor['href']: + leftSide = True if len(anchor.get_text()) < 32 else False + vid = anchor['href'].split('=')[1] + embed_markup = (' [<button class="embed"' + f'onclick="toggleYT(\'{vid}\')">' + f'<img class="embed{" left" if leftSide else ""}" src=' + f'"https://img.youtube.com/vi/{vid}/mqdefault.jpg">' + 'toggle embed</button>]' + f'<div class="embed" id="{vid}"></div>' + ) + embed_markup = BeautifulSoup(embed_markup, 'html.parser') + li.insert(1, embed_markup) + +sys.stdout.write(str(raw))