示例#1
0
	def play_track( self, track ):
		Logger.log_message( "URLHandlerSpotify:\t\tplay track: %s " % track )
		# self.router = HaliteRouter( "hw:0,1,0", "hw:0,0,7" )
		self.sp_instance.play( track )
		self.playing = True;
		while self.playing:
			time.sleep( 1 )
		self.on_track_end()
示例#2
0
	def handle_spotify_url( self, url ):
		Logger.log_message( "URLHandlerSpotify: handle Spotify url: %s" % url )
		result = self.sp_instance.lookup( url )
		Logger.log_message( "URLHandlerSpotify:\tresult: %s" % result )
		if isinstance( result, spytify.Track ):
			self.play_track( result )
		elif isinstance( result, spytify.Artist ):
			album = random.choice( result.albums )
			self.play_album( album )
		elif isinstance( result, spytify.Album ):
			self.play_album( result )
示例#3
0
def main():
	
	if( len(sys.argv) > 1 ):
		exec_command = sys.argv[1]

		if( exec_command == "connect" ):
			listener_counter = listenercounter.ListenerCounter()
			num_listeners = listener_counter.increment_count()
			Logger.log_message( "Halite: listener connect, new num_listeners=%d" % num_listeners )
			if( num_listeners > 0 ):
				start()
		
		elif( exec_command == "disconnect" ):
			listener_counter = listenercounter.ListenerCounter()
			num_listeners = listener_counter.decrement_count()
			Logger.log_message( "Halite: listener disconnect, new num_listeners=%d" % num_listeners )
			if( num_listeners < 1 ):
				write_command( "stop" )
		
		elif( exec_command == "start" ):
			# Logger.PRINT_MESSAGES = False
			Logger.LOG_TO_USERCONSOLE = None
			start()
		
		else:
			# write command to COMMANDFILE so running instance can use it
			if( os.path.isfile(PIDFILE) ):
				write_command( exec_command )
			else:
				Logger.log_message( "There is no instance of Halite running" )
		
	else:
		Logger.log_message( "No argument provided" )
示例#4
0
def start():
	
	if( os.path.isfile(PIDFILE) ):
		Logger.log_message( "There is already an instance of Halite running." )
		exit()
	else:
		fh = open( PIDFILE, "w" )
		fh.write( "%d" % os.getpid() )
		fh.close()
	
	Logger.log_message( "Halite start, pid is %d" % os.getpid() )
	
	file_handlers		= [ FileHandlerMediaFile(),
							FileHandlerURL() ]
	playlist_handler	= PlaylistHandler()
	running = True
	while running:
		
		# get a new file
		file = playlist_handler.get_next_file()
		(path, ext) = os.path.splitext(file)
		
		# play it
		handled = False
		for file_handler in file_handlers:
			handled_extensions = file_handler.handled_extensions()
			for handled_extension in handled_extensions:
				if( handled_extension == ext ):
					file_handler.handle_file( file )
					handled = True
				if( handled ):
					break
			if( handled ):
					break
		
		# check contol file
		if( os.path.isfile(COMMANDFILE) ):
			Logger.log_message( "Halite: has a commandfile" )
			fh = open( COMMANDFILE )
			command = fh.read()
			fh.close()
			Logger.log_message( "-> command is %s" % command )
			if( command == "stop" ):
				running = False
				os.remove( COMMANDFILE )
	
	Logger.log_message( "Halite: end main loop" )
	os.remove(PIDFILE)
示例#5
0
	def __init__( self ):
		Logger.log_message( "URLHandlerSpotify: New Spytify instance" )
		self.sp_instance = spytify.Spytify( SP_USERNAME, SP_PASSWORD, callback=self.spytify_callback )
		self.playing = False
		self.router = None
示例#6
0
	def handle_file( self, filepath ):
		Logger.log_message( "-> handle file: %s" % filepath )
		mplayer_wrapper = MPlayerWrapper()
		mplayer_wrapper.play_file( filepath )