A Python3 Flask REST API to retrieve currently playing local music
python3
subprocess
Flask
mpris2
dbus
Clone the repo, install all the python dependencies using pip3
, and launch the server using python3 main.py
.
It only works with Linux (dbus' MPRIS) for now, but a Win32 compatibility is to come.
The webserver will now be available at the local address (e.g. localhost
, 127.0.0.1
) with the port 5175
by default.
See https://github.com/busybox11/localmusic-api/projects/1.
Returns the API information in a JSON element similar to this one:
{
"platform": "Linux",
"python_version": "3.8.4",
"version": "v0.4"
}
platform
: Current OS platform of the API.
python_version
: Version of Python which is being used by the API.
version
: Current version of the API.
Pong
Returns the current playing state in a JSON element similar to this one:
{
"album": "a modern tragedy vol. 2",
"artist": "grandson",
"artwork": "https://i.scdn.co/image/ab67616d00001e0298561ed4bf6615bfc788bfcc",
"config": [
{
"canPause": true,
"canPlay": true,
"canSeek": true
}
],
"length": "198693000",
"position": "45371000",
"platform": "Linux",
"status": "Playing",
"title": "Apologize",
"uri": "org.mpris.MediaPlayer2.spotify",
"volume": "1.0"
}
Notice: All elements are optional, except the uri
, platform
and config
.
All time elements are microseconds strings.
If there is no MPRIS players available, the API will return a 504 GATEWAY TIMEOUT
with a blank JSON.
All control endpoints have the following response:
On success: HTTP CODE 201
with JSON {"success": true}
.
On error: HTTP CODE 502
with JSON {"success": false}
.
Go to the next song.
Go back the previous song.
Play / resume the previous song.
Pause the previous song.
Play / resume or pause the previous song, based on the current playback state.
Currently, all the config is stored in config.py
. You can edit this file to meet your needs.
Boolean, default: True
Ignore Chrome MPRIS player.
String, default: 127.0.0.1
The host domain / IP of the API.
Integer, default: 5175
The port of the API.
Boolean, default: True
Enable debug mode on Flask.