Skip to content

Commit

Permalink
embed: Use youtube-nocookie.com
Browse files Browse the repository at this point in the history
YouTube supports embedding videos with "privacy enhanced mode" [1].
This is done by using https://www.youtube-nocookie.com/embed instead of
https://www.youtube.com/embed.

Override wagtails oembed finder to fixup the url we've got from YouTubes
oEmbed API.

We still load external content and need to trust Google, but it could be
verified, that no tracking cookies are sent around. This is even true,
when the video is actually played.

[1]: https://support.google.com/youtube/answer/171780
  • Loading branch information
donald committed Mar 25, 2021
1 parent 73e2c78 commit 58ed790
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,5 @@
WAGTAILAPI_LIMIT_MAX = 50

DATA_UPLOAD_MAX_NUMBER_FIELDS=None

WAGTAILEMBEDS_FINDERS = [ { 'class': 'mpicms.base.oembed' } ]
9 changes: 9 additions & 0 deletions mpicms/base/oembed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import wagtail.embeds.finders.oembed

class OEmbedFinder(wagtail.embeds.finders.oembed.embed_finder_class):
def find_embed(self, url, max_width=None):
d = super().find_embed(url, max_width);
d['html'] = d['html'].replace('https://www.youtube.com/embed/', 'https://www.youtube-nocookie.com/embed/', 1)
return d

embed_finder_class = OEmbedFinder

0 comments on commit 58ed790

Please sign in to comment.