Unverified Commit 212b46de authored by Kevin Gutiérrez's avatar Kevin Gutiérrez Committed by GitHub
Browse files

Fix mimetype when the URL has params

Using Cloud Storage could generate urls like:

`https://storage.googleapis.com/<BUCKET_NAME>/<PATH>/testwebm?Expires=1612931745&GoogleAccessId=<ACCOUNT>&Signature=<SIGNATURE>`

Passing parameters to the URL returns None in mime.guess_type(url)

Also, extracting the mimetype to some property that can be reused. Similar to https://github.com/wagtail/wagtail/blob/master/wagtail/documents/models.py#L170
parent cf01a878
...@@ -171,6 +171,11 @@ class AbstractVideo(CollectionMember, index.Indexed, models.Model): ...@@ -171,6 +171,11 @@ class AbstractVideo(CollectionMember, index.Indexed, models.Model):
@property @property
def file_ext(self): def file_ext(self):
return os.path.splitext(self.filename())[1][1:] return os.path.splitext(self.filename())[1][1:]
@property
def content_type(self):
mime = mimetypes.MimeTypes()
mimetype = mime.guess_type(self.url)[0] or mime.guess_type(self.filename())[0]
def is_editable_by_user(self, user): def is_editable_by_user(self, user):
from wagtailvideos.permissions import permission_policy from wagtailvideos.permissions import permission_policy
...@@ -199,7 +204,7 @@ class AbstractVideo(CollectionMember, index.Indexed, models.Model): ...@@ -199,7 +204,7 @@ class AbstractVideo(CollectionMember, index.Indexed, models.Model):
mime = mimetypes.MimeTypes() mime = mimetypes.MimeTypes()
sources.append("<source src='{0}' type='{1}'>" sources.append("<source src='{0}' type='{1}'>"
.format(self.url, mime.guess_type(self.url)[0])) .format(self.url, self.content_type))
sources.append("<p>Sorry, your browser doesn't support playback for this video</p>") sources.append("<p>Sorry, your browser doesn't support playback for this video</p>")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment