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()