Skip to main content

Unofficial python API for brain.fm

Project description

Very few commands are currently implemented. Please open an issue if there’s a specific command you need. If you’re up for debugging their interesting wire format, additional details make it easier to implement your request.

This client requires Python 3.5+.

Quickstart

pip install brainfm
>>> import brainfm
>>> client = brainfm.Connection("your@email.here", "hunter2")
>>> client.get_stations()
[{'name': 'Cinematic Music Focus', 'station_id': 300,
  'canonical_name': 'explore.focus.cinematic'},
 {'name': 'Beach Focus', 'station_id': 53,
  'canonical_name': 'explore.focus.beach'},
 ...]
>>> client.get_station(station_id=53)
{'name': 'Beach Focus', 'station_id': 53, 'canonical_name': 'explore.focus.beach'}
>>> client.get_token(station_id=53)
{'session_token': '63f4b59b-93f4-45e6-b0c2-eb6b1582fb96',
 'group': 'FOCUS', 'name': 'Beach Focus', 'session_id': 121,
 'station_id': 53}

Now, open the stream using that token:

https://stream.brain.fm/?tkn=63f4b59b-93f4-45e6-b0c2-eb6b1582fb96

CLI

Needs a credentials file in ~/.brainfm/config with the format:

{
    "email": "your@email.here",
    "password": "hunter2"
}

Usage:

$ brain ls
+Available Stations------------+---------------------------+
| id  | name                   | canonical                 |
+-----+------------------------+---------------------------+
| 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 gs 60
{
    "canonical_name": "explore.focus.wind",
    "name": "Wind Focus",
    "station_id": 60
}

$ brain gt 60
{
    "group": "FOCUS",
    "name": "Wind Focus",
    "session_id": 143,
    "session_token": "3ff0eab0-a5f6-11e6-a5c2-f11c700a6178",
    "station_id": 60
}

$ 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.2.2.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

brainfm-0.2.2-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for brainfm-0.2.2.tar.gz
Algorithm Hash digest
SHA256 9e8c065fd60fea103dcb31a754f8b7019041c7f69b4ef3412901e065adfa5071
MD5 98e247961ef8f20e80fa738df30f5332
BLAKE2b-256 d234d03ad8fdf6f91aa8064ef93de4e26f360dc4c2b05ae54a80fa29a691e5b5

See more details on using hashes here.

File details

Details for the file brainfm-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for brainfm-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ed272b09fff57755f7b2222971dd395646963797edffa7453baabffd960a364b
MD5 fedfe40e197055ef2248b4b4938e9e90
BLAKE2b-256 4c686b8a204dcdca67d6e5bac08109b703b1f405c9c2b5ce1f31073f3d3f45d8

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