コード例 #1
0
	def playVideo( self ) :
		#
		# Show wait dialog while parsing data...
		#
		dialogWait = xbmcgui.DialogProgress()
		dialogWait.create( __language__(30403), self.video_title )
		
		# 
		# Case 1: The id is part of the query (id=xyz) 
		# e.g. http://www.gamespot.com/xbox360/action/wanted/video_player.html?id=cSEynjOr5bIIvzTZ
		#
		if ("?id=" in self.video_page_url) :
			parsed    = urlparse(self.video_page_url)
			params    = dict(part.split('=') for part in parsed[4].split('&'))
			video_id  = params[ "id" ]
			video_url = "http://userimage.gamespot.com/cgi/deliver_user_video.php?id=%s" % ( video_id )
		#
		# Case 2: The id is part of the query (?sid=xyz)
		# e.g. http://uk.gamespot.com/events/gamescom-2012/video.html?sid=6392231
		#
		elif ("?sid=" in self.video_page_url) :
			parsed    = urlparse(self.video_page_url)
			params    = dict(part.split('=') for part in parsed[4].split('&'))
			video_id  = params[ "sid" ]
			
			if video_id != None :
				#
				# Call xml.php to get the address to the .FLV movie...
				#
				httpCommunicator = HTTPCommunicator()
				xml_php_url = "http://www.gamespot.com/pages/video_player/xml.php?id=%s" % str( video_id )
				xmlData     = httpCommunicator.get( xml_php_url )
				
				# Add the xml declaration + character encoding (missing)...
				xmlData = "<?xml version=\"1.0\" encoding=\"iso8859-1\" ?>" + os.linesep + xmlData

				# Parse the response...
				xmldoc      = minidom.parseString( xmlData )

				# Get the HTTP url...
				playlistNode = xmldoc.documentElement.getElementsByTagName( "playList" )[0]
				clipNode     = playlistNode.getElementsByTagName( "clip" )[0]
				uriNode      = clipNode.getElementsByTagName( "URI" )[0]
				
				# SD or HD...
				video_url = uriNode.childNodes[0].nodeValue
				
				# cleanup
				xmldoc.unlink()
		#
		# Other
		#
		else :
			video_id = None
			
			if (self.VIDEO_PAGE_URL2.match( self.video_page_url )) :
				video_id = self.VIDEO_PAGE_URL2.search( self.video_page_url ).group(1)
			if (self.VIDEO_PAGE_URL3.match( self.video_page_url )) :
				video_id = self.VIDEO_PAGE_URL3.search( self.video_page_url ).group(1)
			
			if video_id != None :
				#
				# Call xml.php to get the address to the .FLV movie...
				#
				httpCommunicator = HTTPCommunicator()
				xml_php_url = "http://www.gamespot.com/pages/video_player/xml.php?id=%s" % str( video_id )
				xmlData     = httpCommunicator.get( xml_php_url )
				
				# Add the xml declaration + character encoding (missing)...
				xmlData = "<?xml version=\"1.0\" encoding=\"iso8859-1\" ?>" + os.linesep + xmlData

				# Parse the response...
				xmldoc      = minidom.parseString( xmlData )

				# Get the HTTP url...
				playlistNode = xmldoc.documentElement.getElementsByTagName( "playList" )[0]
				clipNode     = playlistNode.getElementsByTagName( "clip" )[0]
				httpUriNode  = clipNode.getElementsByTagName( "httpURI" )[0]
				
				# SD or HD...
				video_url = httpUriNode.childNodes[0].nodeValue
				if (self.play_hd == "True") :
					video_url = video_url.replace( "_400.flv", "_1400.flv" )
				
				# cleanup
				playlistNode.unlink()

		#	
		# Play video...
		#
		playlist = xbmc.PlayList( xbmc.PLAYLIST_VIDEO )
		playlist.clear()

		# only need to add label, icon and thumbnail, setInfo() and addSortMethod() takes care of label2
		listitem = xbmcgui.ListItem( self.video_title, iconImage="DefaultVideo.png", thumbnailImage=self.video_thumbnail )
		# set the key information
		listitem.setInfo( "video", { "Title": self.video_title, "Studio" : self.video_studio, "Plot" : self.video_plot, "Genre" : self.video_genre } )
		# add item to our playlist
		playlist.add( video_url, listitem )

		# Close wait dialog...
		dialogWait.close()
		del dialogWait
		
		# Play video...
		xbmcPlayer = xbmc.Player( self.video_players[ self.video_player ] )
		xbmcPlayer.play(playlist)   

#
# The End
#
コード例 #2
0
	def getVideos( self ) :
		#
		# Init
		#
		user_date_format = xbmc.getRegion( "dateshort" ).replace( "MM", "%m" ).replace( "DD", "%d" ).replace( "YYYY", "%Y" ).strip()
		
		#
		# Get HTML page...
		#
		httpCommunicator = HTTPCommunicator()
		url              = "http://www.gamespot.com/videos/index.html?mode=filter&page=%u&type=%s&range=all&view=list&filter=latest" % ( self.current_page, self.video_type )
		htmlSource       = httpCommunicator.get( url )
		
		# Debug
		if (self.DEBUG) :
			print "PAGE URL = " + url
			f = open(os.path.join( xbmc.translatePath( "special://profile" ), "plugin_data", "video", sys.modules[ "__main__" ].__plugin__, "page_%i.html" % self.current_page), 'w')
			f.write( htmlSource )
			f.close()

		# Parse response...
		soupStrainer  = SoupStrainer( "div", { "class" : "body" } )
		beautifulSoup = BeautifulSoup( htmlSource, soupStrainer )
		
		# Parse movie entries...
		ul_video_list = beautifulSoup.find ("ul", { "id" : "video_list" } )  
		lis = ul_video_list.findAll( 'li', { "class" : re.compile( "video|video alt" ) } )		
		for li in lis :
			div_wrap = li.div
			em = div_wrap.em
			a = em.a
			
			# Title
			title = a.string.strip()
			
			# Video page
			href           = a[ "href" ]
			video_page_url = "http://www.gamespot.com%s" % href
			
			# Thumb
			div_details = div_wrap.div
			div_thumb   = div_details.div
			thumb_img   = div_thumb.img 
			thumb_src   = thumb_img[ "src" ]
			
			# Date
			ul_details   = div_details.ul
			li_date      = ul_details.li 
			date_str     = li_date.string.strip()
			date_display = datetime.date ( int( date_str.split( "/" )[ 2 ] ) + 2000, int( date_str.split( "/" )[ 0 ] ), int( date_str.split( "/" )[ 1 ] ) ).strftime( user_date_format )
			
			# HD?
			play_hd      = [ False, True ][ self.video_quality == "1" ]
			if (play_hd) :
				ul_watch = div_details.find( "ul", { "class" : re.compile( "actions watch" ) } )
				li_hd    = ul_watch.find( "li", { "class" : "hd last" } )
				play_hd  = [ False, True ][ li_hd != None ]			

			# Debug info...
			if (self.DEBUG) :
				print "TITLE = " + title
				print "DATE  = " + date_display
				print "HREF  = " + href
				print "THUMB = " + thumb_src
            
			# Add to list...
			listitem        = xbmcgui.ListItem( title, iconImage="DefaultVideo.png", thumbnailImage=thumb_src )
			listitem.setInfo( "video", { "Title" : title, "Studio" : "GameSpot", "Plot" : title, "Genre" : date_display } )
			plugin_play_url = '%s?action=play&video_page_url=%s&play_hd=%s' % ( sys.argv[ 0 ], urllib.quote( href ), play_hd )
			xbmcplugin.addDirectoryItem( handle=int(sys.argv[ 1 ]), url=plugin_play_url, listitem=listitem, totalItems=self.page_size, isFolder=False)
			
		# Total pages...
		div_pagination = beautifulSoup.find ("div", { "class" : "pagination" } )
		ol = div_pagination.ol
		last_li = ol.find ("li", { "class" : re.compile( "last |last on") } )
		last_li_a = last_li.a
		if last_li_a != None :
			total_pages = int( last_li_a.string.strip() )
		else :
			total_pages = int( last_li.span.string.strip() )				
		
		# Next page entry...
		if (self.current_page + 1 < total_pages) :
			listitem = xbmcgui.ListItem (__language__(30402), iconImage = "DefaultFolder.png", thumbnailImage = os.path.join(self.IMAGES_PATH, 'next-page.png'))
			xbmcplugin.addDirectoryItem( handle = int(sys.argv[1]), url = "%s?action=list&plugin_category=%s&video_type=%s&page=%i" % ( sys.argv[0], self.plugin_category, self.video_type, self.current_page + 1 ), listitem = listitem, isFolder = True)

		# Disable sorting...
		xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_NONE )
				
		# End of directory...
		xbmcplugin.endOfDirectory( handle=int( sys.argv[ 1 ] ), succeeded=True )