From ab5f3819ddd1ae3eeacc6c48fdefde8bcb96df97 Mon Sep 17 00:00:00 2001 From: Ndibe Raymond Olisaemeka Date: Tue, 22 Dec 2020 01:40:13 +0100 Subject: [PATCH] added support for various forms of youtube video url, vimeo and google drive (#24) * added functionality to format youtube video url to embedable format * made video url optional * switched image upload location from cloudinary to digital ocean spaces * added functionality to automatically delete image from digitalocean space once image is deleted from db * added image count indicator and made video optional. also added project create button to navbar * removed .ssl from git * untracked .ssl-data * added support for various forms of youtube video url, vimeo and google drive --- zubhub_backend/zubhub/projects/models.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/zubhub_backend/zubhub/projects/models.py b/zubhub_backend/zubhub/projects/models.py index 6df7d3ede..3ddf9c569 100644 --- a/zubhub_backend/zubhub/projects/models.py +++ b/zubhub_backend/zubhub/projects/models.py @@ -33,8 +33,28 @@ class Project(models.Model): published = models.BooleanField(default=True) def save(self, *args, **kwargs): - if(self.video.find("youtube.com") != -1): - self.video = "embed/".join(self.video.split("watch?v=")) + if isinstance(self.video, str): + if self.video.find("m.youtube.com") != -1: + self.video = "youtube.com/embed/".join( + self.video.split("m.youtube.com/watch?v=")) + + elif self.video.find("youtube.com") != -1: + self.video = "embed/".join(self.video.split("watch?v=")) + + elif self.video.find("youtu.be") != -1: + self.video = "youtube.com/embed".join( + self.video.split("youtu.be")) + + elif self.video.find("m.youtube.com") != -1: + self.video = "youtube.com/embed/".join( + self.video.split("m.youtube.com/watch?v=")) + + elif self.video.find("https://vimeo.com") != -1: + self.video = "player.vimeo.com/video".join( + self.video.split("vimeo.com")) + + elif self.video.find("drive.google.com") != -1 and self.video.find("view") != -1: + self.video = self.video.split("view")[0] + "preview" if self.id: self.likes_count = self.likes.count()