Skip to main content

Unofficial python API for brain.fm

Project description

The Connection class exposes three operations: login, list_stations, and get_token. 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"
$ # <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'
>>> brainfm.build_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

Expects an environment variable named BRAINFM_SID to exist. 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"

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

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

brainfm-0.3.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

brainfm-0.3.0-py2.py3-none-any.whl (7.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file brainfm-0.3.0.tar.gz.

File metadata

  • Download URL: brainfm-0.3.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for brainfm-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b8bdd33897af3c34601c9074f4b8db73449b15710424fb1a872abfdd13b7d4f4
MD5 38997a70f775739a96ab587a00f3873a
BLAKE2b-256 134ab4fc274709a8e4f5eb0a0ab46c0846591d2c6444168a96c5bc5ff78b89cf

See more details on using hashes here.

File details

Details for the file brainfm-0.3.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for brainfm-0.3.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9c109138883a2e82eca10201503dd73c5b0b889cd8a89dc3be88fb2ef9122f4c
MD5 fdf090b007595b56783a4695d8f225c2
BLAKE2b-256 c12972fbdfafb3655170d2badb804a86cbded23833ee748e0c9b385b9588fdc8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page