Skip to content

Commit

Permalink
EMBED_VIDEO_TIMEOUT
Browse files Browse the repository at this point in the history
  • Loading branch information
yetty committed Feb 21, 2014
1 parent 078e566 commit b1fb39c
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 19 deletions.
28 changes: 17 additions & 11 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Release 0.8 (dev)
-----------------

- Add ``EMBED_VIDEO_TIMEOUT`` to settings.


Release 0.7 (Dec. 21, 2013)
---------------------------

Expand All @@ -13,9 +19,9 @@ Release 0.7 (Dec. 21, 2013)
Release 0.6 (Oct. 04, 2013)
---------------------------

- Ability to overwrite embed code of backend
- Ability to overwrite embed code of backend

- Caching backends properties
- Caching backends properties

- PyPy compatibility

Expand All @@ -31,14 +37,14 @@ Release 0.5 (Sep. 03, 2013)

- Added example project

- Fixed template tag embed
- Fixed template tag embed

- Fixed raising UnknownIdException in YouTube detecting.



Release 0.4 (Aug. 22, 2013)
----------------------------
---------------------------

- Documentation was rewrited and moved to http://django-embed-video.rtfd.org/ .

Expand All @@ -54,14 +60,14 @@ Release 0.4 (Aug. 22, 2013)


Release 0.3 (Aug. 20, 2013)
----------------------------
---------------------------

- Security fix: faked urls are treated as invalid. See `this page
<https://github.com/yetty/django-embed-video/commit/d0d357b767e324a7cc21b5035357fdfbc7c8ce8e>`_
for more details.
for more details.

- Fixes:

- allow of empty video field.

- requirements in setup.py
Expand All @@ -73,18 +79,18 @@ Release 0.3 (Aug. 20, 2013)
- ``backend`` variable in ``video`` template tag.

Usage::

{% video item.video as my_video %}
Backend: {{ my_video.backend }}
{% endvideo %}


Release 0.2 (June 25, 2013)
----------------------------
Release 0.2 (June 25, 2013)
---------------------------

- Support of SoundCloud

Release 0.1 (June 1, 2013)
----------------------------
--------------------------

- Initial release
14 changes: 11 additions & 3 deletions docs/api/embed_video.settings.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Settings
===========
========

.. setting:: EMBED_VIDEO_BACKENDS

Expand All @@ -8,12 +8,20 @@ EMBED_VIDEO_BACKENDS

List of backends to use.

Default::
Default::

EMBED_VIDEO_BACKENDS = (
'embed_video.backends.YoutubeBackend',
'embed_video.backends.VimeoBackend',
'embed_video.backends.SoundCloudBackend',
)


.. setting:: EMBED_VIDEO_TIMEOUT

EMBED_VIDEO_TIMEOUT
-------------------

Sets timeout for ``GET`` requests to remote servers.

Default: ``10``
10 changes: 7 additions & 3 deletions embed_video/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from django.utils.functional import cached_property

from .utils import import_by_path
from .settings import EMBED_VIDEO_BACKENDS
from .settings import EMBED_VIDEO_BACKENDS, EMBED_VIDEO_TIMEOUT


class VideoDoesntExistException(Exception):
Expand Down Expand Up @@ -200,9 +200,11 @@ class VimeoBackend(VideoBackend):
pattern_info = '{protocol}://vimeo.com/api/v2/video/{code}.json'

def get_info(self):
print EMBED_VIDEO_TIMEOUT
try:
response = requests.get(
self.pattern_info.format(code=self.code, protocol=self.protocol)
self.pattern_info.format(code=self.code, protocol=self.protocol),
timeout=EMBED_VIDEO_TIMEOUT
)
return json.loads(response.text)[0]
except ValueError:
Expand Down Expand Up @@ -235,7 +237,9 @@ def get_info(self):
'format': 'json',
'url': self._url,
}
r = requests.get(self.base_url, data=params)
r = requests.get(self.base_url, data=params,
timeout=EMBED_VIDEO_TIMEOUT)

return json.loads(r.text)

def get_thumbnail_url(self):
Expand Down
2 changes: 2 additions & 0 deletions embed_video/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
'embed_video.backends.VimeoBackend',
'embed_video.backends.SoundCloudBackend',
))

EMBED_VIDEO_TIMEOUT = getattr(settings, 'EMBED_VIDEO_TIMEOUT', 10)
12 changes: 12 additions & 0 deletions embed_video/tests/tests_backend.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from unittest import TestCase
from mock import patch
import requests

from ..backends import detect_backend, YoutubeBackend, VimeoBackend, \
SoundCloudBackend, UnknownBackendException, \
Expand Down Expand Up @@ -87,6 +89,11 @@ def test_get_thumbnail_url(self):
self.assertEqual(backend.get_thumbnail_url(),
'http://b.vimeocdn.com/ts/446/150/446150690_640.jpg')

@patch('embed_video.backends.EMBED_VIDEO_TIMEOUT', 0.000001)
def test_timeout_in_get_info(self):
backend = VimeoBackend('http://vimeo.com/72304002')
self.assertRaises(requests.Timeout, backend.get_info)


class SoundCloudBackendTestCase(BackendTestMixin, TestCase):
urls = (
Expand Down Expand Up @@ -127,3 +134,8 @@ def test_get_embed_code(self):
self.assertEqual(self.foo.get_embed_code(100, 200),
'<iframe width="100" height="321" src="foobar" '
'frameborder="0" allowfullscreen></iframe>')

@patch('embed_video.backends.EMBED_VIDEO_TIMEOUT', 0.000001)
def test_timeout_in_get_info(self):
backend = SoundCloudBackend('https://soundcloud.com/community/soundcloud-case-study-wildlife')
self.assertRaises(requests.Timeout, backend.get_info)
2 changes: 0 additions & 2 deletions embed_video/tests/tests_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,3 @@ class InsecureRequest(RequestFactory):
backend = VideoNode.get_backend('http://www.youtube.com/watch?v=jsrRJyHBvzw', context)
self.assertFalse(backend.is_secure)



0 comments on commit b1fb39c

Please sign in to comment.