fix in-client video player with correct content type headers

This commit is contained in:
meeb 2023-01-19 13:29:37 +11:00
parent 4ae454a4f3
commit fdc591cc7c
3 changed files with 12 additions and 2 deletions

View File

@ -1136,6 +1136,16 @@ class Media(models.Model):
return False return False
return os.path.exists(self.media_file.path) return os.path.exists(self.media_file.path)
@property
def content_type(self):
if not self.downloaded:
return 'video/mp4'
vcodec = self.downloaded_video_codec.lower()
if vcodec == 'vp9':
return 'video/webm'
else:
return 'video/mp4'
@property @property
def nfoxml(self): def nfoxml(self):
''' '''

View File

@ -13,7 +13,7 @@
<video controls style="width: 100%"> <video controls style="width: 100%">
<source src="{% url 'sync:media-content' pk=media.pk %}"> <source src="{% url 'sync:media-content' pk=media.pk %}">
</video> </video>
<p class="truncate"><a href="{% url 'sync:media-content' pk=media.pk %}" download="{{ media.filename }}">Download</a></p> <p class="truncate"><a href="{% url 'sync:media-content' pk=media.pk %}" download="{{ media.filename }}"><strong><i class="fas fa-download"></i> Download</strong></a></p>
{% endif %} {% endif %}
</div> </div>
</div> </div>

View File

@ -677,8 +677,8 @@ class MediaContent(DetailView):
def dispatch(self, request, *args, **kwargs): def dispatch(self, request, *args, **kwargs):
self.object = self.get_object() self.object = self.get_object()
headers = { headers = {
'Content-Type': self.object.content_type,
'X-Accel-Redirect': self.object.media_file.url, 'X-Accel-Redirect': self.object.media_file.url,
} }
return HttpResponse(headers=headers) return HttpResponse(headers=headers)