mirror of
https://github.com/Hopiu/django-embed-video.git
synced 2026-03-17 05:40:24 +00:00
add new backend wistia video
This commit is contained in:
parent
85516a556b
commit
4cbb72a691
6 changed files with 81 additions and 1 deletions
|
|
@ -23,3 +23,5 @@ script:
|
|||
- PYTHONHASHSEED=0 python setup.py nosetests --verbosity 2 --with-coverage --cover-tests --cover-erase
|
||||
after_success:
|
||||
- coveralls
|
||||
notifications:
|
||||
email: false
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
django-embed-video
|
||||
==================
|
||||
|
||||
Django app for easy embedding YouTube and Vimeo videos and music from SoundCloud.
|
||||
Django app for easy embedding YouTube, Vimeo, Wistia videos and music from SoundCloud.
|
||||
|
||||
.. image:: https://jazzband.co/static/img/badge.svg
|
||||
:target: https://jazzband.co/
|
||||
|
|
|
|||
|
|
@ -368,6 +368,51 @@ class VimeoBackend(VideoBackend):
|
|||
return self.info.get('thumbnail_large')
|
||||
|
||||
|
||||
class WistiaBackend(VideoBackend):
|
||||
"""
|
||||
Backend for Wistia URLs.
|
||||
"""
|
||||
domain = None
|
||||
is_secure = True
|
||||
|
||||
re_detect = re.compile(r'https://(?P<domain>[a-z]+).wistia.com/medias/*', re.I)
|
||||
re_code = re.compile(r'''wistia\.com/(medias/(.*/)?|deliveries/)(?P<code>[a-z0-9;:@?&%=+/\$_.-]+)''', re.I)
|
||||
|
||||
pattern_url = '{protocol}://fast.wistia.net/embed/iframe/{code}'
|
||||
pattern_info = '{protocol}://fast.wistia.net/oembed?url={protocol}%3A%2F%2F{domain}.wistia.com%2Fmedias%2F{code}&embedType=async'
|
||||
|
||||
@cached_property
|
||||
def width(self):
|
||||
"""
|
||||
:rtype: str
|
||||
"""
|
||||
return self.info.get('width')
|
||||
|
||||
@cached_property
|
||||
def height(self):
|
||||
"""
|
||||
:rtype: str
|
||||
"""
|
||||
return self.info.get('height')
|
||||
|
||||
def get_info(self):
|
||||
try:
|
||||
response = requests.get(
|
||||
self.pattern_info.format(domain=self.domain, code=self.code, protocol=self.protocol), timeout=EMBED_VIDEO_TIMEOUT
|
||||
)
|
||||
return json.loads(response.text)
|
||||
except ValueError:
|
||||
raise VideoDoesntExistException()
|
||||
|
||||
def get_thumbnail_url(self):
|
||||
"""
|
||||
Returns thumbnail URL folded from :py:data:`pattern_thumbnail_url` and
|
||||
parsed code.
|
||||
:rtype: str
|
||||
"""
|
||||
return self.info.get('thumbnail_url')
|
||||
|
||||
|
||||
class SoundCloudBackend(VideoBackend):
|
||||
"""
|
||||
Backend for SoundCloud URLs.
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ from django.conf import settings
|
|||
EMBED_VIDEO_BACKENDS = getattr(settings, 'EMBED_VIDEO_BACKENDS', (
|
||||
'embed_video.backends.YoutubeBackend',
|
||||
'embed_video.backends.VimeoBackend',
|
||||
'embed_video.backends.WistiaBackend',
|
||||
'embed_video.backends.SoundCloudBackend',
|
||||
))
|
||||
""" :type: tuple[str] """
|
||||
|
|
|
|||
31
embed_video/tests/backends/tests_wistia.py
Normal file
31
embed_video/tests/backends/tests_wistia.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import requests
|
||||
from mock import patch
|
||||
from unittest import TestCase
|
||||
|
||||
from . import BackendTestMixin
|
||||
from embed_video.backends import WistiaBackend, VideoDoesntExistException
|
||||
|
||||
|
||||
class WistiaBackendTestCase(BackendTestMixin, TestCase):
|
||||
|
||||
urls = (
|
||||
('https://support.wistia.com/medias/26sk4lmiix', '26sk4lmiix'), # This comes from the wistia docs
|
||||
('https://home.wistia.com/medias/342jss6yh5', '342jss6yh5'),
|
||||
)
|
||||
|
||||
instance = WistiaBackend
|
||||
|
||||
def test_wistia_get_info_exception(self):
|
||||
with self.assertRaises(VideoDoesntExistException):
|
||||
backend = WistiaBackend('https://support.wistia.com/123')
|
||||
backend.get_info()
|
||||
|
||||
def test_get_thumbnail_url(self):
|
||||
backend = WistiaBackend('https://home.wistia.com/medias/342jss6yh5')
|
||||
self.assertEqual(backend.get_thumbnail_url(),
|
||||
'https://embed-ssl.wistia.com/deliveries/7fc8174a908ad1d349196405671e0fbdaa1e84eb.jpg?image_crop_resized=960x540')
|
||||
|
||||
@patch('embed_video.backends.EMBED_VIDEO_TIMEOUT', 0.000001)
|
||||
def test_timeout_in_get_info(self):
|
||||
backend = WistiaBackend('http://support.wistia.com/72304002')
|
||||
self.assertRaises(requests.Timeout, backend.get_info)
|
||||
|
|
@ -18,6 +18,7 @@ INSTALLED_APPS = (
|
|||
EMBED_VIDEO_BACKENDS = (
|
||||
'embed_video.backends.YoutubeBackend',
|
||||
'embed_video.backends.VimeoBackend',
|
||||
'embed_video.backends.WistiaBackend',
|
||||
'embed_video.backends.SoundCloudBackend',
|
||||
'embed_video.tests.backends.tests_custom_backend.CustomBackend',
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue