Unofficial python API for brain.fm
Project description
The Connection class exposes four operations: login, list_stations, get_token and make_stream_url. Please open an issue if there’s another operation you need.
This client requires Python 3.5+.
CLI Quickstart
$ pip install brainfm $ brain init Email: user@gdomain.com Password: <hidden> Repeat for confirmation: <hidden> Add the following to your .profile, .bashrc, or equivalent: export BRAINFM_SID="s%3...s0xo" export BRAINFM_STREAM_ENDPOINT="https://..." $ # ... commands to modify and reload profile ... $ brain play 300
Library Quickstart
pip install brainfm
>>> import brainfm
>>> client = brainfm.Connection()
>>> client.login("your@email.here", "hunter2")
>>> client.list_stations()
[{'name': 'Cinematic Music Focus', 'id': 300,
'string_id': 'explore.focus.cinematic'},
{'name': 'Beach Focus', 'id': 53,
'string_id': 'explore.focus.beach'},
...]
>>> token = client.get_token(53)
>>> token
'63f4b59b-93f4-45e6-b0c2-eb6b1582fb96'
>>> client.make_stream_url(token)
'https://stream.brain.fm/?tkn=63f4b59b-93f4-45e6-b0c2-eb6b1582fb96'
Now, open the stream using that token:
https://stream.brain.fm/?tkn=63f4b59b-93f4-45e6-b0c2-eb6b1582fb96
CLI
You must pass an sid with --sid or define an environment variable BRAINFM_SID. You can use brain init to generate one:
$ brain init Email: user@gdomain.com Password: <hidden> Repeat for confirmation: <hidden> Add the following to your .profile, .bashrc, or equivalent: export BRAINFM_SID="s%3...s0xo" export BRAINFM_STREAM_ENDPOINT="https://..."
While setting BRAINFM_STREAM_ENDPOINT is not strictly necessary, the cli is faster when either the env var is defined or you provide the endpoint explicitly: brain --stream-endpoint=... ls
Usage:
$ brain ls +Available Stations------------+---------------------------+ | id | name | string_id | +-----+------------------------+---------------------------+ | 34 | Relaxed Focus | explore.relaxed | | 53 | Beach Focus | explore.focus.beach | | 54 | Chimes & Bowls Focus | explore.focus.bells | | 55 | Electronic Music Focus | explore.focus.electronic | | ... | ... | ... | | 262 | Wind Relax | explore.relax.wind | | 300 | Cinematic Music Focus | explore.focus.cinematic | +-----+------------------------+---------------------------+ $ brain gt 60 3ff0eab0-a5f6-11e6-a5c2-f11c700a6178 $ brain play 60 # opens a browser at: # https://stream.brain.fm/?tkn=3ff0eab0-a5f6-11e6-a5c2-f11c700a6178
Override Endpoints
From the cli you can override the api and stream endpoints with --api-endpoint and --stream-endpoint respectively. This is useful when the service switches endpoints but this library hasn’t been updated to match.
You can also provide these as env variables BRAINFM_API_ENDPOINT and BRAINFM_STREAM_ENDPOINT
User-Agent
By default the user agent is github.com/numberoverzero/brainfm followed by the project __version__. There is also a packaged browser-like user-agent:
>>> client = brainfm.Connection(...)
>>> client.user_agent = brainfm.BROWSER
Instead of filtering, maybe this will be a good metric for customer interest in an official API :heart:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file brainfm-2.0.0.tar.gz
.
File metadata
- Download URL: brainfm-2.0.0.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32a7b323bd8111bf7b496b625ba05418a2f890ed9be383c18611fbad644373d9 |
|
MD5 | 970464e79f4c6e36f01dcc3283a702ef |
|
BLAKE2b-256 | dd1d82c7506d1deb3694609cc12461d44d259f5c4c1cbe4acbee678554c65e32 |
File details
Details for the file brainfm-2.0.0-py3-none-any.whl
.
File metadata
- Download URL: brainfm-2.0.0-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2982e5d5ec78917290d33941d085247eb62850724163df4ebdd864572a118ca2 |
|
MD5 | 69e9a4c3f66746602afe90ef0d256252 |
|
BLAKE2b-256 | 6d3c7b13f127979364819be23c7abf9e1befd073ce9f1be4c9346793944b0cd4 |