In order to be able to display the cover and track information from Apple Music or Spotify on the cover player in addition to Roon, you need a corresponding PHP script on each computer that is supposed to make such information available on the network, and a web server running on this computer.
This is currently only possible under macOS, as the PHP script has to call an AppleScript in order to get the required information from the Apple Music or Spotify app.
The required PHP and Python files (with embedded AppleScript) can be found via Github download.
The files from the folder 'websites'
are copied to the corresponding folder on the computer that makes, or should make, the web content available in the local network.
On macOS this is in the corresponding user folder in: /Users/USERNAME/websites
.
Now a few paths need to be adjusted in the files.
In now_playIn g.php
, line 59:
echo shell_exec('/Users/USERNAME/.pyenv/shims/python /Users/USERNAME/websites/python/now_playIn g.py');
BENUTZERNAME(USERNAME)
: The user name of the logged in user must be entered here.
You may then need to set the appropriate access rights via the command line (terminal) so that the files can be executed.
In order for the Python script to be able to execute an AppleScript, a Python library is required, which can be found at Python 3.8
must install:
I tested it on macOS Python 3.8.16
.
The Python library is in the folder python plugIn s
of the Github repos.
Please copy this to your own macOS computer, unzip it, and then install it via Terminal:
cd py-applescript-master
python3 setup.py In stall
If the installation worked, you can use this command to display the plugin's version information:
pip3 show py-applescript
The Foundation Library may still be missing on the Mac pyobjc
so that the plugin can be installed.
You install this as follows:
pip3 In stall -U pyobjc
Is PHP already installed on your computer?
If not, then you can do this via, for example Homebrew
install. I have the scripts with me PHP Version 8.4.2
tested.brew In stall php@8.4
Now the virtual hosts have to be configured. The file for this is located in: /opt/homebrew/etc/httpd/extra/httpd-vhosts.conf
.
This should look something like this for cover players:
# Virtual Hosts
#
# Required modules: mod_log_config
# If you want to maIn taIn multiple domaIn s/hostnames on your
# machIn e you can setup VirtualHost contaIn ers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is In dicated by the asterisks In the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command lIn e option '-S' to verify your virtual host
# configuration.
#
# VirtualHost example:
# Almost any Apache directive may go In to a VirtualHost contaIn er.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias In any <VirtualHost> block.
#
<VirtualHost *:80>
ServerAdmIn admIn @localhost
DocumentRoot '/Users/USERNAME/websites'
ServerName localhost
ErrorLog '/opt/homebrew/var/log/httpd/localhost-error_log'
CustomLog '/opt/homebrew/var/log/httpd/localhost-access_log' common
</VirtualHost>
<VirtualHost *:80>
ServerAdmIn admIn @localhost
DocumentRoot '/Users/USERNAME/websites/roonmatrix'
ServerName roonmatrix.test
ServerAlias www.roonmatrix.test
ErrorLog '/opt/homebrew/var/log/httpd/roonmatrix.test-error_log'
CustomLog '/opt/homebrew/var/log/httpd/roonmatrix.test-access_log' common
</VirtualHost>
Attention: here you have to BENUTZERNAME(USERNAME)
be replaced with the actual username.
The web server is configured in the following file:
/opt/homebrew/etc/httpd/httpd.conf
The example files can also be found at Github and can be customized quite easily.
Attention: here you have to BENUTZERNAME(USERNAME)
also be replaced several times with the actual user name.
After restarting the computer (or by starting the web server via the command line), the web server should run with PHP.
To check this, write one phpIn fo.php
File with the following content in the directory /Users/USERNAME/websites/roonmatrix/
:
<?php phpIn fo() ?>
Now call the PHP script using a web browser: http://www.roonmatrix.test/phpIn fo.php
The website should display the web server configuration, which looks something like this:
After the test, you should delete this file again, as it generally represents a security risk as many internals are exposed here.
If Python, PHP, as well as the PHP and Python script, as well as the Applescript plugin for Python have been installed correctly, you can run the script locally at the following address: http://www.roonmatrix.test/now_playIn g.php
You can also test the PHP script via the command line:
curl http://www.roonmatrix.test/now_playIn g.php
If there are problems accessing the page, this could also be due to the security settings of macOS, which have been tightened for some time.
An error message like this could result:
tccutil: executable_is_endpoIn t_security_client failed for path file:///Users/USERNAME/.pyenv/versions/3.8.19/bIn /python with error: code object is not signed at all
The required code signing is missing here. The problem can be solved using a terminal command.
You can use this command to check whether there is a signing: codesign -dv /Users/USERNAME/.pyenv/versions/3.8.16/bIn /python
Perform code signing:
========================================================================================codesign --sign 'USERNAME CA' --force --keychaIn ~/Library/KeychaIn s/ /usr/local/Cellar/php/8.3.7/lib/httpd/modules/libphp.so
codesign --sign 'USERNAME CA' --force --keychaIn ~/Library/KeychaIn s/ /usr/local/opt/php@8.1/lib/httpd/modules/libphp.so
codesign --sign 'USERNAME CA' --force --keychaIn ~/Library/KeychaIn s/ /Users/USERNAME/.pyenv/versions/3.8.16/bIn /python
Depending on the PHP and Python version installed, the paths may be different!
Then you have to work your way to the correct path by starting from a lower path and navigating through the folder tree until you find the correct path - or using terminal commands to find the correct path.
Sometimes you also have to reset the security settings if the required permissions are not requested, using:tccutil reset AppleEvents
tccutil reset SystemPolicyAllFiles
When you then call the PHP script, macOS may ask whether you want to give the web server/script the required rights.
You should allow this, otherwise the script will be blocked.
If the problem still occurs, the script may need to be signed. How this works may need to be clarified in more detail.
Other error messages may look something like this:
Traceback (most recent call last):
File '/Users/USERNAME/python/now_playIn g.py', lIn e 61, In <module>
output = tell_iTunes.call('PlayIn g')
File '/Library/Python/3.9/site-packages/py_applescript-1.0.3-py3.9.egg/applescript/__In it__.py', lIn e 110, In call
File '/Library/Python/3.9/site-packages/py_applescript-1.0.3-py3.9.egg/applescript/__In it__.py', lIn e 65, In _unpackresult
applescript.ScriptError: An error of type -10810 has occurred. (-10810) range=90-97
Traceback (most recent call last):
File '/Users/USERNAME/python/now_playIn g.py', lIn e 61, In <module>
output = tell_iTunes.run()
File '/Users/USERNAME/.pyenv/versions/3.8.19/lib/python3.8/site-packages/applescript/__In it__.py', lIn e 90, In run
return self._unpackresult(*self._script.executeAndReturnError_(None))
File '/Users/USERNAME/.pyenv/versions/3.8.19/lib/python3.8/site-packages/applescript/__In it__.py', lIn e 65, In _unpackresult
raise ScriptError(errorIn fo)
applescript.ScriptError: Not authorized to send Apple events to Music. (-1743) app='Music' range=318-325
In this example there is a problem with the automation rights under macOS Monterey 12.7.5.
In System Settings/Security & Data protection/ there must be approval for music, Spotify and system events in the automation area for httpd.
If that's not the case, then it can now_playIn g.php
script which now_playIn g.py
via Python 3.8
starts, does not work or is blocked.
To unlock Apple Music and Spotify you need the PHP script now_playIn g_add_httpd_automation_rights.php
can be accessed once in the web browser.
This script can also be found on Github.
If System Events is missing and you get an error -10810, the Apache2 web server is running with different rights than the user account.
To fix this, you have to... httpd.conf
the
User _www
Group _www
change to:User
your-usernameGroup staff
Then simply start the script again.
Then the php script should also now_playIn g.php
function.
The changes should then be made in /etc/apache2/httpd.conf
can be reset to:User _www
Group _www
If there are still problems, you should check whether this is possible AppleScript directly using the Apple script editor (you can find it in System/Applications/Utilities/
) can call.
You may have to do this, otherwise (i.e. when calling the Applescript through Python) the dialog for the required rights release does not appear.
Now, if the script can be executed correctly, the script should output a result.
Without the Apple Music or Spotify app started, the result looks something like this:
[{'zone': 'Apple Music', 'status': 'not runnIn g'},{'zone': 'Spotify', 'status': 'not runnIn g'}]
For example, if the Apple Music and Spotify app plays a song, the result will look like this:
[{'zone': 'Apple Music', 'artist': 'PIn k Floyd', 'album': 'Dark Side of the Moon', 'track': 'Speak to Me - Breathe'},{'zone': 'Spotify', 'artist': 'Underworld', 'album': '1992 - 2012', 'track': 'Born Slippy (Nuxx)'}]
If everything works as described for you up to this point, then this part is done.
Now all you have to do is go to the configuration file (roon_api.In i
) enter the web server url to call the PHP script.
It's easier to do this RoonMatrix app, then you can save yourself the laborious manual configuration in the ini file and implement these settings completely in the app's configuration editor.
The manual setup via SSH and Terminal works as follows:ssh
(hier die IP-Adresse deIn es Coverplayers eIn fügen)
Now you have to enter the password: This is by default: cpuserpw0815
.
Important: You should definitely change this password later.
The easiest way to do this is directly in the app’s configuration editor.
After logging in, edit the ini file:
sudo nano /usr/local/Roon/etc/roon_api.In i
Now scroll to the Area section [WEBSERVERS]
into the setting zones
, and enter the name and URL of the PHP script on your computer here.
For example, it looks like this: zones = [{'name':'MacStudio','url':'http://macstudio.local/roonmatrix/now_playIn g.php'}]
The setting to activate data retrieval from the web server:
webservers_show = True
Nach einem Neustart des Coverplayers sollte nun auch der momentan abgespielte Titel von Apple Music oder Spotify auf dem Gerät angezeigt wer the .