예제 #1
0
def getAllTracks():

	simple = check_boolean(request, params.SIMPLE)
	local = check_boolean(request, params.LOCAL)
	initialPath = check_string(request, params.PATH)

	sortingMethod = check_integer(request, params.SORT)
	if sortingMethod == None:
		sortingMethod = check_string(request, params.SORT)
	sortingMethod = translate_sorting_method(sortingMethod, 1)

	if not check_path(initialPath):
		initialPath = None

	if initialPath == None:
		initialPath = get_defaults()["defaults"]["default_path"]

	if not os.path.isdir(initialPath):
		return send_error(error_codes.INVALID_PATH, "Invalid path")

	respone = explorer.getAllTracks(initialPath, sortingMethod, simple, local)
	
	if not 'error' in respone:
		respone['code'] = error_codes.SUCCESFULL_QUERY

	return jsonify(respone)
예제 #2
0
def youtube_upload():
	path = check_string(request, params.PATH)
	
	if not check_path(path):
		path = None	
	
	if path == None:
		return send_error(error_codes.INVALID_PATH, "You need to specify path parameter")
	if not os.path.isdir(path):
		return send_no_dir_error(path)

	url = check_string(request, params.URL)
	if url == None:
		return send_error(error_codes.INVALID_URL, "You need to specify URL parameter")

	threaded = check_boolean(request, params.THREADED)

	if threaded:
		thread = threading.Thread(target = explorer.downloadYouTube, args = (path, url))
		thread.daemon = True
		thread.start()
	else:
		explorer.downloadYouTube(path, url)

	return jsonify({
			"code" : error_codes.SUCCESFULL_QUERY,
			"message" : "Query has been dispatched"
		})
예제 #3
0
def getAllPlaylists():

	local = check_boolean(request, params.LOCAL)
	sortingMethod = check_integer(request, params.SORT)
	if sortingMethod == None:
		sortingMethod = check_string(request, params.SORT)
	sortingMethod = translate_sorting_method(sortingMethod)

	trackSortingMethod = check_integer(request, params.TRACK_SORT)
	if trackSortingMethod == None:
		trackSortingMethod = check_string(request, params.TRACK_SORT)
	trackSortingMethod = translate_sorting_method(trackSortingMethod, 1)

	filters = check_int_array(request, params.FILTER)
	if len(filters) == 0:
		filters.append(0) #0 means no filtering

	initialPath = check_string(request, params.PATH)

	if not check_path(initialPath):
		initialPath = None
	
	if initialPath == None:
		initialPath = get_defaults()["defaults"]["default_path"]

	if not os.path.isdir(initialPath):
		return send_error(error_codes.INVALID_PATH, "Invalid path")

	respone = explorer.getAllPlaylists(initialPath, sortingMethod, trackSortingMethod, filters, local)
	
	if not 'error' in respone:
		respone['code'] = error_codes.SUCCESFULL_QUERY

	return jsonify(respone)
예제 #4
0
def rewind_track():
	currentTrack = trackThreader.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('millis')
		total = currentTrack.playbackInfo().get('playback').get('total').get('millis')
		currentTrack.setPlaybackPosition(destPos)

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

		return send_state_track_message(currentTrack, "Playback position succesfully changed", {
				'newPosition' : destPos * 1000,
				'oldPosition' : oldPos,
				'total' : total
			})
예제 #5
0
def play_track():
	currentTrack = trackThreader.currentTrack()

	trackPath = check_string(request, params.PATH)
	terminate = check_boolean(request, params.TERMINATE)

	if not file_exsists(trackPath) or not check_path(trackPath):
		return send_no_file_error(trackPath)

	if currentTrack == None:
		return startTrack(trackPath)
	else:
		if terminate:
			currentTrack.stop()
			trackThreader.setTrack(None)
			return startTrack(trackPath)

		return send_error(error_codes.TRACK_ALREADY_PLAYING, "Track already exsists")
예제 #6
0
def play_playlist():
	currentPlaylist = playlistThreader.currentPlaylist()

	defaultPosition = check_integer(request, params.INDEX)
	terminate = check_boolean(request, params.TERMINATE)
	tracks = check_string_array(request, params.TRACK)

	#http://localhost:5000/playlist/play?track=tracks/track5.mp3&track=tracks/track2.mp3&track=tracks/track5.mp3&i=0&t=True

	if currentPlaylist == None:
		return startPlaylist(tracks, defaultPosition)
	else:

		if terminate:
			if currentPlaylist != None and currentPlaylist.currentTrack != None:
				currentPlaylist.stop()
				playlistThreader.setPlaylist(None)
				playlistThreader.reInit()
			return startPlaylist(tracks, defaultPosition)

		return send_error(error_codes.PLAYLIST_EXSIST, "Playlist already exsist")
예제 #7
0
def getDirectory():

	path = check_string(request, params.PATH)
	if path == None:
		path = get_defaults()['defaults']['default_path']

	metadata = check_boolean(request, params.METADATA)

	sortingMethod = check_integer(request, params.SORT)
	if sortingMethod == None:
		sortingMethod = check_string(request, params.SORT)
	sortingMethod = translate_sorting_method(sortingMethod, 0)

	if check_path(path):
		respone = explorer.getPathContent(path, metadata, sorting = sortingMethod)
		if respone == None:
			return send_error(error_codes.INVALID_PATH, "Invalid path")
	else:
		return send_error(error_codes.INVALID_PATH, "Invalid path")

	respone['code'] = error_codes.SUCCESFULL_QUERY
	return jsonify(respone)