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 +Playable Stations-------------+-----------------------+-------- + | id | name | string_id | length | +-----+------------------------+-----------------------+-------- + | 32 | Quick Relax | relax.justrelax15min | 15 mins | | 34 | Relaxed Focus | explore.relaxed | 30 mins | | 35 | Focus | focus.3 | 30 mins | | 36 | Sleep | sleep | 45 mins | | ... | ... | ... | ... | | 540 | Study Focus | explore.focus.study | 30 mins | | 541 | LoFi Focus | explore.focus.lowfi | 30 mins | +-----+------------------------+-----------------------+-------- + $ brain ls -a +All Stations------------------+-----------------------+-------- + | id | name | string_id | length | +-----+------------------------+-----------------------+-------- + | 0 | Favorites | None | None | | 32 | Quick Relax | relax.justrelax15min | 15 mins | | 34 | Relaxed Focus | explore.relaxed | 30 mins | | ... | ... | ... | ... | | 46 | Explore | explore | None | | 47 | Explore Relax | explore.relax | None | | ... | ... | ... | ... | | 541 | LoFi Focus | explore.focus.lowfi | 30 mins | +-----+------------------------+-----------------------+-------- + $ 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:
Metadata
Release files for brainfm 3.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| brainfm-3.0.0.tar.gz | 7.1 kB | Without provenance | Details for brainfm-3.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| brainfm-3.0.0-py3-none-any.whl | Python 3 | none | any | Details for brainfm-3.0.0-py3-none-any.whl |
Total release size: 14.5 kB
Release files / brainfm-3.0.0.tar.gz
| Download URL | brainfm-3.0.0.tar.gz |
|---|---|
| Size | 7.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f52052fc9e9b04bc947f294aca36276d4f6fef0361dbba8559bd92709fa964af
|
|
BLAKE2b-256 checksum How to use checksums |
972610a4e92b81159c835def951ee761fa0379541b81225276ad9075b36bd1e9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / brainfm-3.0.0-py3-none-any.whl
| Download URL | brainfm-3.0.0-py3-none-any.whl |
|---|---|
| Size | 7.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0eac1cad1f4239015ba680efe9bbb55a3129163e406615230ecdc7416fc6e825
|
|
BLAKE2b-256 checksum How to use checksums |
d2ad66b6f3b75dd2b6232bf5a64ec569bc793c412dcb21fe88d9451e51d6e90a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Security for brainfm 3.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.