Inline YouTube Music embeds with one shared embed spec
YouTube Music has no player of its own and music.youtube.com sends X-Frame-Options SAMEORIGIN, so music links render YouTube's own player with an Open in YouTube Music caption. Tracks, playlists and OLAK5uy albums embed; browse, channel, search and library stay plain links. - embeds.py is the single URL spec (exact host allowlists, query-order independent, validated ids only); embed-spec.js is generated from it by the embeds-sync CLI command and drift is tested - rendering.py and ContentRenderer.js both follow it; the old duplicate YouTube regexes are removed - max 3 music embeds per content item, overflow stays a plain link - fixes evilyoutube.com matching and watch?feature=share&v=ID links - fixes the invalid unicode CSS escape that printed u2197 after every external link in rendered content - docs, privacy third-party row, parser table tests, server/client parity Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
|
||||
from tests.conftest import BASE_URL
|
||||
from tests.unit.embeds import EMBED_CASES, TRACK, VIDEO
|
||||
|
||||
ROCKET = "\U0001F680"
|
||||
FIRE = "\U0001F525"
|
||||
@@ -44,6 +45,58 @@ def test_content_youtube_embedded_server_side(alice):
|
||||
assert "youtube.com/embed/dQw4w9WgXcQ" in (iframe.get_attribute("src") or "")
|
||||
|
||||
|
||||
def test_content_music_embedded_server_side(alice):
|
||||
page, _ = alice
|
||||
_create_post(page, f"hear https://music.youtube.com/watch?v={TRACK} now", "Music host post")
|
||||
iframe = page.locator(".post-detail-content .embed-music .embed-youtube iframe").first
|
||||
iframe.wait_for(state="attached")
|
||||
assert f"youtube.com/embed/{TRACK}" in (iframe.get_attribute("src") or "")
|
||||
caption = page.locator(".post-detail-content .embed-music-caption").first
|
||||
caption.wait_for(state="visible")
|
||||
assert caption.text_content().strip() == "Open in YouTube Music"
|
||||
|
||||
|
||||
def test_client_embed_parser_matches_server_for_every_case(alice):
|
||||
page, _ = alice
|
||||
page.goto(f"{BASE_URL}/feed", wait_until="domcontentloaded")
|
||||
urls = [case[0] for case in EMBED_CASES]
|
||||
client = page.evaluate(
|
||||
"""async (urls) => {
|
||||
const mod = await import('/static/js/EmbedParser.js');
|
||||
return urls.map((u) => {
|
||||
const e = mod.EmbedParser.parse(u);
|
||||
return e ? [mod.EmbedParser.src(e), e.music] : null;
|
||||
});
|
||||
}""",
|
||||
urls,
|
||||
)
|
||||
for (url, expected, music), got in zip(EMBED_CASES, client):
|
||||
if expected is None:
|
||||
assert got is None, url
|
||||
else:
|
||||
assert got == [expected, music], url
|
||||
|
||||
|
||||
def test_client_renderer_embeds_music_and_caps_it(alice):
|
||||
page, _ = alice
|
||||
page.goto(f"{BASE_URL}/feed", wait_until="domcontentloaded")
|
||||
urls = " ".join(f"https://music.youtube.com/watch?v={VIDEO[:-1]}{c}" for c in "abcde")
|
||||
result = page.evaluate(
|
||||
"""async (text) => {
|
||||
const mod = await import('/static/js/ContentRenderer.js');
|
||||
const box = document.createElement('div');
|
||||
box.innerHTML = mod.contentRenderer.processMedia(text);
|
||||
return {
|
||||
frames: box.querySelectorAll('.embed-music iframe').length,
|
||||
captions: box.querySelectorAll('.embed-music-caption').length,
|
||||
links: box.querySelectorAll('a:not(.embed-music-caption)').length,
|
||||
};
|
||||
}""",
|
||||
urls,
|
||||
)
|
||||
assert result == {"frames": 3, "captions": 3, "links": 2}
|
||||
|
||||
|
||||
def test_content_code_block_has_copy_button(alice):
|
||||
page, _ = alice
|
||||
_create_post(page, "snippet\n\n```python\nprint('hi')\n```", "Code copy host post")
|
||||
|
||||
Reference in New Issue
Block a user