def play(client: brainfm.Connection, station_id, player=None): """Play a station""" validate_client(client) token = client.get_token(station_id) stream_url = client.make_stream_url(token) if player: subprocess.run(shlex.split(player) + [stream_url]) else: webbrowser.open_new_tab(stream_url)
def init(client: brainfm.Connection, email, password, simple): """Create a session id. Use --simple to omit instructions""" client.login(email, password) if simple: print(client.sid) else: args = ENVKEY_SID, client.sid, ENVKEY_STREAM_ENDPOINT, client.stream_endpoint print( "\nAdd the following to your .profile, .bashrc, or equivalent:\n") print(" export {}=\"{}\"\n export {}=\"{}\"\n".format(*args))
def ls(client: brainfm.Connection, a): """List stations""" validate_client(client) stations = client.list_stations() headers = ["id", "name", "string_id", "length"] data = sorted(STATIONS_PATTERN.search(stations)) ls_title = "Available Stations" if a: ls_title = "All Stations" else: ls_title = "Playable Stations" data = [station for station in data if station[3]] for i, station in enumerate(data[:]): duration = int(station[3]) if duration == 0: data[i][3] = "None" elif duration == 60: data[i][3] = "1 hr" elif duration > 60: data[i][3] = str(int(duration / 60)) + " hrs" else: data[i][3] = str(duration) + " mins" table = terminaltables.AsciiTable(table_data=[headers] + data, title=ls_title) print(table.table)
def gt(client: brainfm.Connection, station_id): """Create a station token""" validate_client(client) token = client.get_token(station_id) print(token)
def url(client: brainfm.Connection, station_id): """Create a station url""" validate_client(client) token = client.get_token(station_id) print(client.make_stream_url(token))