# mpv-headlessserver This repository contains configs, service files and a python script to run a headless mpv service and controll mpv via http GET Requests. # Installation: ## Systemd If you want to autostart the service via systemd, there are * /etc/systemd/system/mpv_webserver.service * /etc/systemd/system/mpv.service Both services run as user 'radiowelle'. This will start the `python script` as a webserver and `mpv`. ## Config The config should be localted under `/home/radiowelle/.config/mpv/mpv.conf`. MPV will start a socket under `/tmp/mpvsocket` and is waiting for commands. ## webserver The webserver shuold be executable and localted under `/usr/local/bin/simple_webserver.py`. This script starts a simple webserver on port `8000` and with the correct GET requests, the script will send commands to the mpv socket. # Usage Open one of the followed links in your browser or with curl to command and control mpv. ## Status ### Request ``` http://domain.tld/?status ``` ### Request Example ``` http://localhost:8000/?status ``` ### Response example ``` Now Playing: Hugo Kant - High Gravity Duration: 0:01:34/0:05:45 Volume: 100.0 Playlist Position: 7/16 Playlist: [0] [1]https://hugokant.bandcamp.com/track/melancholia [2]https://hugokant.bandcamp.com/track/before-midnight-tonight [3]https://hugokant.bandcamp.com/track/the-second-sun [4]https://hugokant.bandcamp.com/track/sure-the-sun-will-rise [5]https://hugokant.bandcamp.com/track/everything-is-transformed [6]https://hugokant.bandcamp.com/track/one-more-step [7]https://hugokant.bandcamp.com/track/high-gravity [8]https://hugokant.bandcamp.com/track/2001-light-years-from-home [9]https://hugokant.bandcamp.com/track/koka [10]https://hugokant.bandcamp.com/track/its-an-unknown-jungle [11]https://hugokant.bandcamp.com/track/come-with-me [12]https://www.youtube.com/watch?v=Q0bnIKtF3E4&pp=ygUEbG9maQ%3D%3D [13]https://hugokant.bandcamp.com/album/the-seven-seas [14]https://hugokant.bandcamp.com/album/the-seven-seas [15]https://hugokant.bandcamp.com/album/out-of-time [16]https://hugokant.bandcamp.com/album/out-of-time ``` ## Play Track ### Request ``` http://domain.tld/?file=[Path|URL] ``` ### Request Example ``` http://localhost:8000/?file=https://www.mixcloud.com/couchsofa/joseph-wir-m%C3%BCssen-kochen-live-at-gpn21-kitchen/ ``` ### Response Example ``` Now Playing: https://www.mixcloud.com/couchsofa/joseph-wir-m%C3%BCssen-kochen-live-at-gpn21-kitchen/ ``` ## Add Track to Playlist ### Request ``` http://domain.tld/?add=[Path|URL] ``` ### Request Example ``` http://localhost:8000/?add=https://www.mixcloud.com/couchsofa/couchsofa-sitzraver-studioset-for-gpn-homelounge-2021/ ``` ### Response Example ``` Add File To Playlist: https://www.mixcloud.com/couchsofa/couchsofa-sitzraver-studioset-for-gpn-homelounge-2021/ ``` ## Play Next Track ### Request ``` http://domain.tld/?mpv=playnext ``` ### Request Example ``` http://localhost:8000/?mpv=playnext ``` ### Response Example ``` Playing Next Track ``` ## Play Prev Track ### Request ``` http://domain.tld/?mpv=playprev ``` ### Request Example ``` http://localhost:8000/?mpv=playprev ``` ### Response Example ``` Playing Prev Track ``` ## Pause ### Request ``` http://domain.tld/?mpv=pause ``` ### Request Example ``` http://localhost:8000/?mpv=pause ``` ### Response Example ``` (none) ``` ## Set Volume ### Request ``` http://domain.tld/?mpv=volset=50 ``` ### Request Example ``` http://localhost:8000/?mpv=volset=50 ``` ### Response Example ``` Volume is: 50 ``` ## Volume Up ### Request ``` http://domain.tld/?mpv=volup ``` ### Request Example ``` http://localhost:8000/?mpv=volplus ``` ### Response Example ``` Volume is: 100 ``` ## Volume down ### Request ``` http://domain.tld/?mpv=volminus ``` ### Request Example ``` http://localhost:8000/?mpv=volminus ``` ### Response Example ``` Volume is: 90 ```