MichaIng / DietPi

Lightweight justice for your single-board computer!
https://dietpi.com/
GNU General Public License v2.0
4.68k stars 492 forks source link

Ampache [Software ID 40]: Add Lighttpd routing configuration to enable Subsonic API out of the box #5103

Open MochaMage opened 2 years ago

MochaMage commented 2 years ago

Ampache's current install is not currently enabling Subsonic API routing out of the box. Adding the following configuration to a file within the /etc/lighttpd/conf-enabled directory will allow the Subsonic API to be accessible. This comes directly from the Ampache API Documentation but has been modified to included the ampache URI that is used by DietPi's current install.

url.rewrite-if-not-file += (
  "^/ampache/rest/(([^\?]+)\.view)(\?(.*))?" => "/ampache/rest/index.php?ssaction=$2&$4",
  "^/ampache/play/ssid/([^/]+)/type/([^/]+)/oid/([^/]+)/uid/([^/]+)/client/([^/]+)/noscrobble/([^/]+)/bitrate/([^/]+)/player/([^/]+)/name/([^/]+)(/.*)?$" => "/ampache/play/index.php?ssid=$1&type=$2&oid=$3&uid=$4&client=$5&noscrobble=$6&bitrate=$7&player=$8&name=$9"
)
MichaIng commented 2 years ago

Many thanks for your request.

I remember we thought about this once already. This means that Subsonic clients can be used, right? We'd need to add those rewrites for all three webservers, Lighttpd, Nginx and Apache.

MochaMage commented 1 year ago

@MichaIng Correct, though after testing this, it varies per client as well. This configuration works for Subsonic but not others like Substreamer. Substreamer's requests seem follow a different format that this regex doesn't cover

MochaMage commented 8 months ago

Related to this enhancement request, I've moved on to a new installation and used Apache2 this time around. I've made the following RewriteRules that, as of test time, work with both DSub and Substreamer applications with the new upgraded regex. I'm not super familiar with Apache so these are currently in my apache.conf file but having these be part of Dietpi Ampache's out-of-the-box installation would be immensely helpful.

        RewriteRule "rest/scrobble.view?u=(.*)&p=(.*)&v=(.*)&c=(.*)&id=30+(.*)&submission=(.*)$" "rest/scrobble.view?u=$1&p=$2&v=$3&c=$4&id=$5&submission=$6" [PT]
        RewriteRule "rest/(([^\?]+)\.view)" "rest/index.php?ssaction=$2" [QSA]
        RewriteRule "play/ssid/([^/]+)/type/([^/]+)/oid/([^/]+)/uid/([^/]+)/client/([^/]+)/bitrate/([^/]+)(/cache/([^/]+))?(/transcode_to/([^/]+))?(/action/([^/]+))?/player/([^/]+)/name/([^/]+)(/.*)?$" "play?ssid=$1&type=$2&oid=$3&uid=$4&client=$5&bitrate=$6&cache=$8&transcode_to=mp3&action=$12&player=$13&name=$14"
MichaIng commented 8 months ago

For Apache, there are .htaccess files in /var/www/ampache/rest and /var/www/ampache/play to enable those rewrites. But they seem to be disabled OOTB:

mv /var/www/ampache/rest/.htaccess{-dist,}
mv /var/www/ampache/play/.htaccess{-dist,}

The contained rules also look like they could be taken for Lighttpd just the same way, only replacing RewriteRule with url.rewrite-if-not-file and adding the ( "..." => "..." ). The only thing I am not 100% sure about is the flags. Would need to look through them.