Commits

Gael Pasgrimaud committed eb6379e

add vimeo/daylimotion

Comments (0)

Files changed (6)

+0.2
+===
+
+Add support for Vimeo and Daylimotion
+
+
 0.1
 ===
 

djangovideos/forms.py

         if 'src=' in data:
             data = data.split('src=', 1)[1]
             data = data.split(' ')[0]
-            data = data.strip(''''"''')
-        if data.startswith('http://www.youtube.com/watch?v='):
-            data = data.replace('http://www.youtube.com/watch?v=', 'http://www.youtube.com/v/')
+            data = data.strip(''' '" ''')
+        if data.startswith('http://vimeo.com/'):
+            splited = data.split('/')
+            clip_id = splited[-1]
+            if clip_id.isdigit():
+                data = ('http://vimeo.com/moogaloop.swf?'
+                        'clip_id=%s&server=vimeo.com&'
+                        'show_title=1&show_byline=1&'
+                        'show_portrait=0&color=&'
+                        'fullscreen=1') % clip_id
+        if data.startswith('http://www.dailymotion.com/video/'):
+            data = data.split('_')[0]
+            data = data.replace('http://www.dailymotion.com/video/',
+                                'http://www.dailymotion.com/swf/video/')
+        elif data.startswith('http://www.youtube.com/watch?v='):
+            data = data.replace('http://www.youtube.com/watch?v=',
+                                'http://www.youtube.com/v/')
         if data.startswith('http'):
             return data
         else:

djangovideos/templates/djangovideos/video.html

            width="{{width}}" height="{{height}}">
   </embed>
 </object>
+<object width="480" height="360"><param name="movie" value="http://www.dailymotion.com/swf/video/xdhrzy" /></param><param name="allowFullScreen" value="true" /></param><param name="allowScriptAccess" value="always" /></param><embed type="application/x-shockwave-flash" src="http://www.dailymotion.com/swf/video/xdhrzy" width="480" height="360" allowfullscreen="true" allowscriptaccess="always"></embed></object></embed></object>

djangovideos/tests/functionnal.py

 # -*- coding: utf-8 -*-
 from django.core.urlresolvers import reverse
-from django_webtest import WebTest
+from django_webtest import WebTest as Base
 from webtest import Form
 from djangovideos import models
 
 __all__ = ('WebTest', 'UserWebTest', 'models', 'reverse')
 
+class WebTest(Base):
+    def _patch_settings(self):
+        Base._patch_settings(self)
+        from django.conf import settings
+        settings.MIDDLEWARE_CLASSES = tuple([m for m in settings.MIDDLEWARE_CLASSES if 'Csrf' not in m])
+
 class UserWebTest(WebTest):
 
     login = 'user1'

djangovideos/tests/test_index.py

 from djangovideos.tests.functionnal import *
 from djangovideos.models import Video
 
-class TestFlashUrl(UserWebTest):
+class TestYoutubeUrl(UserWebTest):
 
-    value = "http://www.youtube.com/watch?v=ZFeHUdEQ1Zs"
+    input = "http://www.youtube.com/watch?v=ZFeHUdEQ1Zs"
+    output = '<param name="movie" value="http://www.youtube.com/v/ZFeHUdEQ1Zs'
 
     def test_index(self):
         resp = self.app.get(reverse('index'), user='user1')
         resp.mustcontain('submit')
         form = resp.form
-        form['url'] = self.value
+        form['url'] = self.input
         resp = form.submit()
         resp = resp.follow()
-        resp.mustcontain('<param name="movie" value="http://www.youtube.com/v/ZFeHUdEQ1Zs')
+        resp.mustcontain(self.output)
 
-class TestObject(TestFlashUrl):
+class TestYoutubeObject(TestYoutubeUrl):
+    input = '<object width="640" height="505"><param name="movie" value="http://www.youtube.com/v/ZFeHUdEQ1Zs&hl=fr_FR&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/ZFeHUdEQ1Zs&hl=fr_FR&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="505"></embed></object>'
 
-    value = '<object width="640" height="505"><param name="movie" value="http://www.youtube.com/v/ZFeHUdEQ1Zs&hl=fr_FR&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/ZFeHUdEQ1Zs&hl=fr_FR&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="505"></embed></object>'
+
+class TestDaylimotionUrl(TestYoutubeUrl):
+    input = 'http://www.dailymotion.com/video/xdhrzy_eiffel-tower-jump-skater-breaks-rec_news'
+    output = '<param name="movie" value="http://www.dailymotion.com/swf/video/xdhrzy" />'
+
+class TestDaylimotionObject(TestDaylimotionUrl):
+    input = '<object width="480" height="360"><param name="movie" value="http://www.dailymotion.com/swf/video/xdhrzy" /></param><param name="allowFullScreen" value="true" /></param><param name="allowScriptAccess" value="always" /></param><embed type="application/x-shockwave-flash" src="http://www.dailymotion.com/swf/video/xdhrzy" width="480" height="360" allowfullscreen="true" allowscriptaccess="always"></embed></object></embed></object>'
+
+class TestVimeoUrl(TestYoutubeUrl):
+    input = 'http://vimeo.com/2237879'
+    output = '<param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=2237879&amp;'
+
+class TestVimeoObject(TestVimeoUrl):
+    input = '''<object width="400" height="267"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=2237879&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=2237879&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="267"></embed></object><p><a href="http://vimeo.com/2237879">Bob's Mega ramp</a> from <a href="http://vimeo.com/cexa">Cexa </a> on <a href="http://vimeo.com">Vimeo</a>.</p>'''
+
 
 """ % read('README', 'CHANGES')
 
-version = '0.1'
+version = '0.2'
 
 setup(name='django-videos',
       version=version,