Skip to content

Commit

Permalink
make video plugin more flexible
Browse files Browse the repository at this point in the history
  • Loading branch information
benzkji committed Nov 11, 2024
1 parent 6e7f296 commit af668d2
Showing 1 changed file with 38 additions and 52 deletions.
90 changes: 38 additions & 52 deletions djangocms_baseplugins/video/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,72 +91,58 @@ def video_id(self):
return self._video_id

@property
def embed_url(self):
def embed_url_only(self):
if self.video_type == "youtube":
url = "https://www.youtube-nocookie.com/embed/%s?a=b" % (self.video_id,)
return url
if self.video_type == "vimeo":
url = "https://player.vimeo.com/video/%s?a=b" % (self.video_id,)
return url

@property
def embed_url_params(self):
params = {}
if self.video_type == "youtube":
# https://developers.google.com/youtube/player_parameters
rel = ""
if not getattr(self, "show_related", False):
rel = "&rel=0"
allowfullscreen = ""
params["rel"] = "0"
if not getattr(self, "fullscreen", True):
allowfullscreen = "&fs=0"
controls = ""
params["fs"] = "0"
if not getattr(self, "controls", True):
controls = "&controls=0"
autoplay = ""
params["controls"] = "0"
if getattr(self, "autoplay", False):
autoplay = "&autoplay=1"
infos = ""
params["autoplay"] = "1"
if not getattr(self, "infos", True):
infos = "&showinfo=0"
modestbranding = ""
params["showinfo"] = "0"
if conf.YOUTUBE_MODESTBRANDING:
modestbranding = "&modestbranding=1"
mute = ""
if getattr(self, "mute", None) or autoplay:
mute = "&mute=1"
color = "&color=%s" % conf.YOUTUBE_COLOR
url = "https://www.youtube-nocookie.com/embed/%s?a=b%s%s%s%s%s%s%s%s" % (
self.video_id,
rel,
allowfullscreen,
controls,
autoplay,
infos,
modestbranding,
color,
mute,
)
return url
params["modestbranding"] = "1"
if getattr(self, "mute", None) or params.get("autoplay"):
params["mute"] = "1"
params["color"] = conf.YOUTUBE_COLOR
if self.video_type == "vimeo":
# "https://player.vimeo.com/video/193349624?autoplay=1&loop=1&color=ff0b03&portrait=0"
controls = ""
# https://help.vimeo.com/hc/en-us/articles/12426260232977-Player-parameters-overview
# https://player.vimeo.com/video/193349624?autoplay=1&loop=1&color=ff0b03&portrait=0
if not getattr(self, "controls", True):
controls = "&controls=0"
autoplay = ""
params["controls"] = "0"
if getattr(self, "autoplay", False):
autoplay = "&autoplay=1"
infos = ""
params["autoplay"] = "1"
if not getattr(self, "infos", True):
infos = "&title=0&byline=0"
# modestbranding = ''
# if conf.YOUTUBE_MODESTBRANDING:
# modestbranding = '&modestbranding=1'
mute = ""
if getattr(self, "mute", False) or autoplay:
mute = "&muted=1"
color = ""
params["title"] = "0"
params["byline"] = "0"
if getattr(self, "mute", False) or params.get("autoplay"):
params["muted"] = "1"
if conf.VIMEO_COLOR:
color = "&color=%s" % conf.VIDEOPLUGIN_VIMEO_COLOR
url = "https://player.vimeo.com/video/%s?a=b&mute=1%s%s%s%s%s" % (
self.video_id,
controls,
autoplay,
infos,
color,
mute,
)
params["color"] = conf.VIDEOPLUGIN_VIMEO_COLOR
return params

@property
def embed_url(self):
url = self.embed_url_only
params = self.embed_url_params
for key, value in params.items():
url += "&%s=%s" % (key, value)
return url
return url

@property
def video_preview_image(self):
Expand Down

0 comments on commit af668d2

Please sign in to comment.