diff --git a/apps/content/models.py b/apps/content/models.py index 00c15312..345221f4 100644 --- a/apps/content/models.py +++ b/apps/content/models.py @@ -1,3 +1,4 @@ +from urllib.parse import urlparse from django.db import models from polymorphic.models import PolymorphicModel @@ -69,6 +70,12 @@ class Video(Content): url = models.URLField('Ссылка') def video_index(self): + if 'youtu.be' in self.url or 'youtube.com' in self.url and 'watch' in self.url: + url = urlparse(self.url) + query = url.query.split('&') + for q in query: + if 'v=' in q: + return q.split('=')[-1] return self.url.split('/')[-1]