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)
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 })
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)
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")
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")
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)