Skip to content

Commit

Permalink
added support for various forms of youtube video url, vimeo and googl…
Browse files Browse the repository at this point in the history
…e 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
  • Loading branch information
NdibeRaymond authored Dec 22, 2020
1 parent ff6269d commit ab5f381
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions zubhub_backend/zubhub/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit ab5f381

Please sign in to comment.