Exemple #1
0
def startPlaylist(tracks, defaultPosition = 0):		
		if defaultPosition != None and is_valid_num(0, len(tracks) - 1, defaultPosition):
			data = playlistThreader.getThread(tracks, defaultPosition)
		else:
			data = playlistThreader.getThread(tracks)

		if len(tracks) == 0:
			return send_error(error_codes.NO_PATH_DEFINED, "No track parameter passed.")

		errorPos = []
		for index, trackPath in enumerate(tracks):

			if not os.path.exists(trackPath) or not check_path(trackPath):
				errorPos.append({"index" : index})
				errorPos[-1].update(send_error(error_codes.WRONG_PATH_SPECIFIED, "File doesn't exsist.", False))
				continue

			if not is_valid_file(trackPath):
				errorPos.append({"index" : index})
				errorPos[-1].update(send_error(error_codes.INVALID_TYPE, "Invalid filetype.", False))
				continue

		if len(errorPos) > 0:
			return send_playlist_play_error(errorPos, "Invalid track array")

		flushTrack()
		currentPlaylist = data.get('playlist')

		playlistThreader.startThread()

		return send_state_playlist_message(currentPlaylist, "Playlist succesfully started", None, 1, False)
Exemple #2
0
def playlist_pos():
	currentPlaylist = playlistThreader.currentPlaylist()

	if currentPlaylist != None and currentPlaylist.currentTrack != None:
		index = check_integer(request, params.INDEX)

		if index == None or not is_valid_num(0, len(currentPlaylist.tracks) - 1, index):
			return send_error(error_codes.INVALID_TRACK_INDEX, "Invalid track index")
		else:
			currentPlaylist.play(index)
			return send_state_playlist_message(currentPlaylist, "Track succesfully changed")
	else:
		return send_error(error_codes.NO_PLAYLIST, "Playlist doesn't exsist")