11from urlparse import parse_qs
22import re
33import urllib
4- import simplejson
4+ from django . utils import simplejson
55
66class Provider (object ):
77
@@ -10,16 +10,16 @@ def __init__(self, url, size = (640, 480)):
1010 self .size = size
1111
1212 def render_video (self ):
13- '''simply returns html to render embed
13+ '''simply returns html to render embed
1414 video in a template'''
1515 raise NotImplementedError
16-
16+
1717 def render_thumbnail (self , link_to ):
1818 '''Renders the html with a link_to a parameter'''
1919 raise NotImplementedError
2020
2121class Youtube (Provider ):
22-
22+
2323 def __init__ (self , url , size = (640 , 480 )):
2424 super (Youtube , self ).__init__ (url , size )
2525 qs = url .split ('?' )
@@ -40,10 +40,10 @@ def __init__(self, url, size=(640, 480)):
4040 pattern = re .compile ('http://(?:www\.)?vimeo\.com/([0-9]{1,12})' )
4141 self .video_id = pattern .match (url ).groups ()[0 ]
4242 self .api_url = 'http://vimeo.com/api/v2/video/%s.json' % self .video_id
43-
43+
4444 def render_video (self ):
4545 html = '''<iframe src="http://player.vimeo.com/video/%s" width="%d" height="%d" frameborder="0"></iframe><p><a href="http://vimeo.com/%s">Das Pop: The Game</a> from <a href="http://vimeo.com/bigactive">Big Active</a> on <a href="http://vimeo.com">Vimeo</a>.</p>'''
46- return html % (self .video_id , self .size [0 ],
46+ return html % (self .video_id , self .size [0 ],
4747 self .size [1 ], self .video_id )
4848
4949 def render_thumbnail (self , link_to = "#" ):
@@ -57,7 +57,7 @@ def __init__(self, url, size=(640, 480)):
5757 self .api_url = 'http://api.embed.ly/1/oembed?url=%s&maxwidth=%s&format=json' % (url , size [0 ])
5858
5959 def render_video (self ):
60- return self ._call_api ()['html' ]
60+ return self ._call_api ()['html' ]
6161
6262 def render_thumbnail (self ):
6363 return self ._call_api ()['thumbnail_url' ]
@@ -68,7 +68,7 @@ def _call_api(self):
6868
6969def get_provider (url , size = None ):
7070 '''returns a provider instance acording to the url'''
71- provider_domain = dict (youtube = Youtube , vimeo = Vimeo )
71+ provider_domain = dict (youtube = Youtube , vimeo = Vimeo )
7272 for domain , provider in provider_domain .items ():
7373 if domain in url :
7474 return provider (url , size ) if size else provider (url )
0 commit comments