Beispiel #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)
Beispiel #2
0
def playlist_smartpause():
	currentPlaylist = playlistThreader.currentPlaylist()

	if currentPlaylist != None and currentPlaylist.currentTrack != None:
		currentTrack = currentPlaylist.currentTrack

		if(currentTrack == None):
			return send_error(error_codes.NO_TRACK, "No track playing")

		if currentTrack.isPaused():
			currentTrack.unpause()
			return send_state_playlist_message(currentPlaylist, "Track unpaused")
		else:
			currentTrack.pause()
			return send_state_playlist_message(currentPlaylist, "Track paused")

	else:
		return send_error(error_codes.NO_PLAYLIST, "Playlist doesn't exsist")	
Beispiel #3
0
def playlist_prev():
	currentPlaylist = playlistThreader.currentPlaylist()

	if currentPlaylist != None and currentPlaylist.currentTrack != None:
		if currentPlaylist.prevTrackAvilable():
			currentPlaylist.previousTrack(onPlaylistLoadError)
			return send_state_playlist_message(currentPlaylist, "Track succesfully changed")
		else:
			return send_error(error_codes.NO_PREV_TRACK, "No previous track avilable")
	else:
		return send_error(error_codes.NO_PLAYLIST, "Playlist doesn't exsist")
Beispiel #4
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")
Beispiel #5
0
def playlist_rewind():
	currentPlaylist = playlistThreader.currentPlaylist()

	if currentPlaylist != None:
		currentTrack = currentPlaylist.currentTrack
		
		destPos = check_integer(request, params.POSITION)
		unpause = True

		if destPos == None:
			return send_error(error_codes.WRONG_PLAYBACK_POSITION, "Wrong playback position")

		unpause = check_boolean(request, params.UNPAUSE)

		if currentTrack == None:
			return send_error(error_codes.NO_TRACK, "No track playing")
		elif destPos == -1:
			return send_error(error_codes.WRONG_PLAYBACK_POSITION, "No position specified")
		elif destPos < 0 or destPos > round(currentTrack.getLength() / 1000):
			return send_error(error_codes.WRONG_PLAYBACK_POSITION, "Wrong playback position. It should be specified with seconds")
		else:

			oldPos = currentTrack.playbackInfo().get('playback').get('position').get('secs')
			total = currentTrack.playbackInfo().get('playback').get('total').get('secs')
			currentTrack.setPlaybackPosition(destPos)

			if unpause and currentTrack.isPaused():
				currentTrack.unpause()

			return send_state_playlist_message(currentPlaylist, "Playback position succesfully changed", {
					'newPosition' : destPos,
					'oldPosition' : oldPos,
					'total' : total
				})
	else:
		return send_error(error_codes.NO_PLAYLIST, "Playlist doesn't exsist")