#NEWLINE# def save( self , * args , **kwargs ) : #NEWLINE# #INDENT# video_service = None #NEWLINE# if ( self . url . find ( 'youtube.com' ) >= 0 ) : #NEWLINE# #INDENT# video_service = 'youtube' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( self . url . find ( 'vimeo.com' ) >= 0 ) : #NEWLINE# #INDENT# video_service = 'vimeo' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( self . url . find ( 'blip.tv' ) >= 0 ) : #NEWLINE# #INDENT# video_service = 'blip' #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( video_service == 'youtube' ) : #NEWLINE# #INDENT# video_id = self . url . replace ( 'http://www.youtube.com/watch?v=' , '' ) #NEWLINE# yt_service = gdata . youtube . service . YouTubeService ( ) #NEWLINE# yt_service . developer_key = settings . YOUTUBE_API_KEY #NEWLINE# yt_service . client_id = settings . YOUTUBE_CLIENT_ID #NEWLINE# video_obj = yt_service . GetYouTubeVideoEntry ( video_id = video_id ) #NEWLINE# if ( not self . title ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# self . title = video_obj . media . title . text #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# if ( not self . length ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# self . length = video_obj . media . duration . seconds #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# if ( not self . swf ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# hd_add = '&fs=1&rel=0&ap=%2526fmt%3D22&hd=1' #NEWLINE# swf = ( '%s%s' % ( video_obj . GetSwfUrl ( ) , hd_add ) ) #NEWLINE# self . swf = swf #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# if ( not self . thumbnail ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# self . thumbnail = video_obj . media . thumbnail [ 1 ] . url #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# if ( not self . description ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# self . description = video_obj . media . description . text #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( video_service == 'vimeo' ) : #NEWLINE# #INDENT# video_id = self . url . replace ( 'http://vimeo.com/' , '' ) #NEWLINE# if ( video_id == self . url ) : #NEWLINE# #INDENT# video_id = self . url . replace ( 'http://www.vimeo.com/' , '' ) #NEWLINE# #UNINDENT# dom = minidom . parse ( urllib . urlopen ( ( ( 'http://vimeo.com/api/clip/' + video_id ) + '.xml' ) ) ) #NEWLINE# if ( not self . title ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# self . title = dom . getElementsByTagName ( 'title' ) [ 0 ] . firstChild . data #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# if ( not self . length ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# self . length = int ( dom . getElementsByTagName ( 'duration' ) [ 0 ] . firstChild . data ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# if ( not self . thumbnail ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# self . thumbnail = dom . getElementsByTagName ( 'thumbnail_medium' ) [ 0 ] . firstChild . data #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# if ( not self . swf ) : #NEWLINE# #INDENT# self . swf = ( ( 'http://vimeo.com/moogaloop.swf?clip_id=' + video_id ) + '&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1' ) #NEWLINE# #UNINDENT# if ( not self . description ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# self . description = dom . getElementsByTagName ( 'caption' ) [ 0 ] . firstChild . data #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( video_service == 'blip' ) : #NEWLINE# #INDENT# api_url = self . url #NEWLINE# if ( api_url . find ( '?' ) >= 0 ) : #NEWLINE# #INDENT# api_url += '&' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# api_url += '?' #NEWLINE# #UNINDENT# api_url += 'skin=rss' #NEWLINE# dom = minidom . parse ( urllib . urlopen ( api_url ) ) #NEWLINE# if ( not self . title ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# self . title = dom . getElementsByTagName ( 'title' ) [ 1 ] . firstChild . data #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# if ( not self . length ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# self . length = int ( dom . getElementsByTagName ( 'blip:runtime' ) [ 0 ] . firstChild . data ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# if ( not self . swf ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# self . swf = dom . getElementsByTagName ( 'blip:embedUrl' ) [ 0 ] . firstChild . data #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# if ( not self . thumbnail ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# self . thumbnail = dom . getElementsByTagName ( 'blip:smallThumbnail' ) [ 0 ] . firstChild . data #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# if ( not self . description ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# self . description = dom . getElementsByTagName ( 'blip:puredescription' ) [ 0 ] . firstChild . data #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# self . title = 'Invalid URL--not a YouTube, Vimeo or blip.tv video' #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# super ( Video , self ) . save ( * args , ** kwargs )