jazzband / django-embed-video

Django app for easy embedding YouTube and Vimeo videos and music from SoundCloud.

Home Page:http://django-embed-video.rtfd.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HTML video/audio backend

thijstriemstra opened this issue · comments

It looks like regular urls don't have a fallback to a <video> element that plays back the content. Would adding a native HTML video/audio backend (as a default for urls that end with .mp3, .mp4 etc) make sense (and be welcome or considered a plugin)?

New backend to provide <video> functionality sounds great. I'm looking forward to your pull request.

Cool, I've started working on it here. Just switched to tox for testing against multiple Django/Pythons locally, now on to the real code.

@yetty I suppose as long as the URL is correct (verified by django's urlvalidator in the model or form field) we will try the 'BasicMediaBackend' (what I called it for now, better suggestions for a name are welcome). This because a media URL doesn't necessarily have an extension (e.g. http://foo.com/myvideostream). Should the code and thumbnail url always return None? Maybe there should be a audio and video backend, so the user can decide if a certain field uses a specific backend (maybe a backend keyword with a dotted path to the backend)?

There should be at least some checks, that given URL is valid. I guess the best solution would be to check, if server gives correct Content-Type in response. Based on content type it would be used the propriate backend — video or audio.

For example if you use the video from http://www.quirksmode.org/html5/tests/video.html, the headers are

curl -XHEAD -i http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4
HTTP/1.1 200 OK
Date: Mon, 18 Apr 2016 11:02:40 GMT
Server: Apache/2.2.22 (Debian)
Last-Modified: Wed, 16 Feb 2011 14:20:59 GMT
ETag: "1d670c9-5416d8-49c66fd774813"
Accept-Ranges: bytes
Content-Length: 5510872
Content-Type: video/mp4

so video backend should be used.

I suggest the naming Html5VideoBackend and Html5AudioBackend.

@yetty I've opened #58 with a backend that works here but there are still some quirks:

  • we need sane defaults for width/height of the audio and video elements
  • the tests need to be improved (what to do with urls that return 404, 301 etc, because adding a check for this causes the other backend tests to fail)

Any feedback is welcome.

Thanks for all the spelling and grammar corrections! :)

  • For video I would use the default_size. For audio there is no need of sizes.
  • BackendTestMixin is designed to run tests against real urls. (In fact it works more like integration test than like a unit test.) One way is to give working urls for Html5 backends too. Or write custom test cases for new backends, independent on the BackendTestMixin.

I suggest next improvements:

  • the templates for new backends are missing. We cannot use the default template.
  • it would be fine if the template rendering would also be covered with tests.
  • add some examples to initial data, to show how the functionality is working.

Updated the PR @yetty

For video I would use the default_size. For audio there is no need of sizes.

I'm not sure how to change the default_size on a custom backend?

I've added some real urls. It seems to succeed on all builders except Django 1.5 and 1.6 on Python 3.4 (?!).

Also added the templates. Coverage remains the same. Leaving the initial data for the example up to you, I couldn't get it to work with Django 1.9.

@thijstriemstra Since we're both now maintainers on this, would you be OK with me reviewing your changes (starting with this one), and you review mine should I have any?

Sounds good @mgrdcm!

Let me change the title of this ticket to HTML5 video or something. Video.js support can be integrated later.

👍