コード例 #1
0
	def getVideos( self ) :
		#
		# Get HTML page...
		#
		url              = "http://www.eurogamer.net/ajax.php?action=frontpage&page=%i&type=video" % (self.current_page )
		if self.channel == "show" :
			url			 = "http://www.eurogamer.net/ajax.php?action=frontpage&page=%i&topic=egtv-show" % (self.current_page )
		httpCommunicator = HTTPCommunicator()
		htmlSource       = httpCommunicator.get( url )
		
		#
		# Tells us if we have items (so we can display/or not the Next Page)
		#
		self.items = False
		
		#
		# Parse HTML page...
		#
		soupStrainer  = SoupStrainer( "ul" )
		beautifulSoup = BeautifulStoneSoup( htmlSource, parseOnlyThese=soupStrainer )

		# Loop through "playlist" divs...
		uls = beautifulSoup.findAll( "ul", recursive = False )
		for ul in uls:
		
			# skip popular now and popular recently as they will be found at they normal (chronological) position
			ul_id = ul.get( "id" )
			if self.channel == "now" :
				if ul_id != "popular-now" :
					continue
			elif self.channel == "recently" :
				if ul_id != "popular-recently" :
					continue
			else:
				if ul_id != None and ( ul_id == "popular-now" or ul_id == "popular-recently" ) :
					continue
			
			lis = ul.findAll( "li", recursive=False )
			for li in lis :
				# Get A link...
				li_a = li.find("a", recursive=False)				

				# Video page URL
				video_page_url = None
				div_a = li.find( "div", recursive=False )
				if div_a != None :
					h2_a = div_a.find ( "h2", recursive=False )
					if h2_a != None :
						a_a = h2_a.find ( "a", recursive=False)
						if a_a != None :
							video_page_url = a_a[ "href" ]
							
				if (video_page_url == None) :
					continue
				
				# Thumbnail...
				thumbnail = "";
				img_a = li.find( "img" )
				if img_a != None:
					thumbnail = img_a["src"]
				
				# Title
				title = li.div.h2.a.string.strip()
				# Normalize unicode cause we can find funny accents and they are not properly unicode encoded
				# so we just transform into their ascii equivalent
				title = unicodedata.normalize('NFKD', title).encode("ascii", "ignore")
				
				# Plot
				plot = ""
				p_p = div_a.find ( "p", recursive=False )
				if p_p != None :
					p_plot = p_p.contents[0]
					if ( p_plot != None ) :
						plot = p_plot.strip()
						plot = unicodedata.normalize('NFKD', plot).encode("ascii", "ignore")
				
				play_script_url = '%s?action=play&video_page_url=%s' % ( sys.argv[ 0 ], urllib.quote_plus( video_page_url ) )
				
				# Notify to show Next Page
				self.items = True
				# Add directory entry...
				listitem = xbmcgui.ListItem( title, iconImage=thumbnail, thumbnailImage=thumbnail )
				listitem.setInfo( "video", { "Title" : title, "Studio" : "Eurogamer", "Plot" : plot } )
				xbmcplugin.addDirectoryItem( handle=int(sys.argv[ 1 ]), url=play_script_url, listitem=listitem, isFolder=False)
				

		# Next page...
		if self.items and self.channel != "now" and self.channel != "recently" :
			listitem = xbmcgui.ListItem (__language__(30401), iconImage = "DefaultFolder.png", thumbnailImage = os.path.join(self.IMAGES_PATH, 'next-page.png'))
			xbmcplugin.addDirectoryItem( handle = int(sys.argv[1]), url = "%s?action=list&channel=%s&channel_desc=%s&page=%i" % ( sys.argv[0], self.channel, self.channel_desc, 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 )
コード例 #2
0
	def playVideo( self ) :
		#print "video_page_url = " + self.video_page_url
		
		#
		# Init
		#
		video_url = None

		#
		# Get current list item details...
		#
		title     = unicode( xbmc.getInfoLabel( "ListItem.Title"  ), "utf-8" )
		thumbnail =          xbmc.getInfoImage( "ListItem.Thumb"  )
		studio    = unicode( xbmc.getInfoLabel( "ListItem.Studio" ), "utf-8" )
		plot      = unicode( xbmc.getInfoLabel( "ListItem.Plot"   ), "utf-8" )
		genre     = unicode( xbmc.getInfoLabel( "ListItem.Genre"  ), "utf-8" )
		
		#
		# Show wait dialog while parsing data...
		#
		dialogWait = xbmcgui.DialogProgress()
		dialogWait.create( __language__(30402), title )	
		
		# 
		# Parse video HTML page to get the video playlist i... 
		#
		httpCommunicator = HTTPCommunicator()
		htmlSource       = httpCommunicator.post( "www.eurogamer.net", "/" + self.video_page_url, {'version' : 'portable' } )        
		
		#
		playlist_id_re = re.compile( 'Playlist\["id"\]\s*=\s*"(.*)"')
		playlist_id_m    = playlist_id_re.search( htmlSource )
		
		if (playlist_id_m != None) :
			playlist_id = playlist_id_m.group(1)
			print playlist_id
			
			#
			# Parse JSON reply...
			#
			httpCommunicator = HTTPCommunicator()
			jsonReply        = httpCommunicator.get( "http://www.eurogamer.net/tv/playlist/%s" % playlist_id )        
			
			json = simplejson.loads( jsonReply )
			video_url = json[0][ 'file' ]
			if self.video_quality == "1" :
				video_url_hd = json[0].get( 'hd.file' )
				if video_url_hd != None and video_url_hd != "":
					video_url = video_url_hd

		#
		# Close wait dialog...
		#
		dialogWait.close()
		del dialogWait
		
		if (video_url != None) :
			#	
			# Play video...
			#
			playlist = xbmc.PlayList( xbmc.PLAYLIST_VIDEO )
			playlist.clear()
	
			# Set video info...
			listitem = xbmcgui.ListItem( title, iconImage="DefaultVideo.png", thumbnailImage=thumbnail )
			listitem.setInfo( "video", { "Title": title, "Studio" : studio, "Plot" : plot, "Genre" : genre } )
	
			# Add item to our playlist...
			playlist.add( video_url, listitem )
	
			# Play...
			xbmcPlayer = xbmc.Player( self.video_players[ self.video_player ] ).play( playlist )
		else :
			#
			# Video not found...
			#
			xbmcgui.Dialog().ok( __language__(30000), __language__(30403) )

#
# The End
#
コード例 #3
0
	def getVideos( self ) :
		#
		# Get HTML page...
		#
		url				 = "http://www.eurogamer.net/search.php?q=%s&type=videos" % ( urllib.quote( self.query ) )
		if ( self.current_page > 1 ):
			url = url + "&start=%s" % ( (self.current_page - 1) * 20 )
		httpCommunicator = HTTPCommunicator()
		htmlSource       = httpCommunicator.get( url )
		
		#
		# Parse HTML page...
		#
		soupStrainer  = SoupStrainer( "ul", { "class" : "list" } )
		beautifulSoup = BeautifulSoup(htmlSource, soupStrainer)

		#
		# Get all the videos found
		# 
		lis = beautifulSoup.findAll( "li", { "class" : "article medium" } )
		
		# No results found...
		if len(lis) == 0 :
			xbmcgui.Dialog().ok( __language__(30008), __language__(30404), self.query )
			xbmcplugin.endOfDirectory( handle=int( sys.argv[ 1 ] ), succeeded=False )
			return	
		
		for li in lis:
			
			# video page url
			video_page_url = None
			h2_a = li.find( "h2" )
			if h2_a != None :
				a = h2_a.find ( "a", recursive=False )
				if a != None:
					video_page_url = a[ "href" ]
			
			if video_page_url == None:
				continue
			
			# Title
			title = ""
			
			ss = ""
			for cont in a.contents:
				if (isinstance(cont, Tag)):
					ss = ss + cont.contents[0]
				else:
					ss = ss + cont
				
			if ss != "":
				title = ss.strip()
				title = title.replace("•", ".")
				title = title.replace("'", "'")
				title = unicodedata.normalize('NFKD', title).encode("ascii", "ignore")
			
			# Thumbnail
			thumbnail = ""
			img = li.find("img")
			if img != None:
				thumbnail = img[ "src" ]
				
			# Plot
			plot = ""
			plot_p = li.find ("p")
			if plot_p != None and plot_p.string != None:
				plot = plot_p.string.strip()
				plot = unicodedata.normalize('NFKD', plot).encode("ascii", "ignore")
				

			play_script_url = '%s?action=play&video_page_url=%s' % ( sys.argv[ 0 ], urllib.quote_plus( video_page_url ) )
			
			# Add directory entry...
			listitem = xbmcgui.ListItem( title, iconImage=thumbnail, thumbnailImage=thumbnail )
			listitem.setInfo( "video", { "Title" : title, "Studio" : "Eurogamer", "Plot" : plot } )
			xbmcplugin.addDirectoryItem( handle=int(sys.argv[ 1 ]), url=play_script_url, listitem=listitem, isFolder=False)
		
		# Check if we should show the next page		
		a_next = beautifulSoup.find("a", {"class":"tool next"})
		if a_next != None:
			self.items = True
		else:
			self.items = False

		# Next page...
		if self.items :
			listitem = xbmcgui.ListItem (__language__(30401), iconImage = "DefaultFolder.png", thumbnailImage = os.path.join(self.IMAGES_PATH, 'next-page.png'))
			xbmcplugin.addDirectoryItem( handle = int(sys.argv[1]), url = '%s?action=search-list&query=%s&plugin_category=%s&page=%i' % ( sys.argv[ 0 ], urllib.quote( self.query ), __language__(30008), 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 )
		
		#
		# Save the query for future use...
		#
		#
		try :
			saved_queries = eval( __settings__.getSetting( "saved_queries" ) )
		except :
			saved_queries = []
		
		# Add the entry to the list...
		try :
			# ... if not already in the list...
			saved_queries.index( self.query )
		except :
			saved_queries.append( self.query )
			
			# Sort the list...
			saved_queries.sort()
			
			# Save queries...
			__settings__.setSetting( "saved_queries", repr( saved_queries ))