Skip to content

Commit f3e9d4c

Browse files
authored
Merge pull request #12 from radio-pi/feature/upgrade-to-2022
Feature/upgrade to 2022
2 parents 412b796 + b3c3036 commit f3e9d4c

21 files changed

Lines changed: 313 additions & 752 deletions

.github/workflows/main.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@ jobs:
88
runs-on: ubuntu-latest
99
strategy:
1010
matrix:
11-
python-version: [3.6, 3.7, 3.8]
11+
python-version: [3.9, "3.10", 3.11]
1212

1313
steps:
14-
- uses: actions/checkout@v2
14+
- uses: actions/checkout@v3
1515
- name: Set up Python ${{ matrix.python-version }}
16-
uses: actions/setup-python@v1
16+
uses: actions/setup-python@v4
1717
with:
1818
python-version: ${{ matrix.python-version }}
1919
- name: Install dependencies
2020
run: |
2121
python -m pip install --upgrade pip
2222
pip install -r requirements-dev.txt
23+
- name: Install vlc
24+
run: sudo apt-get install -y vlc
2325
- name: Test with pytest
24-
run: py.test tests/
26+
run: python -m pytest tests/

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ env
33
.pytest_cache/
44
.tox/
55
radiopi.egg-info/
6-
twistd.pid
6+
build

README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
Radio PI backend
2-
==================
3-
2+
================
43

54
A simple REST & websocket server to expose a simple API
65
to control a music player. Used by a [web client]( https://github.com/radio-pi/python-websocket-backend/blob/master/index.html)
76
and an [Android APP]( https://github.com/radio-pi/RadioPi ).
87

98
# Production
109

11-
Please check out these two blog posts:
10+
Please check out these two tutorials:
1211

13-
* [General setup]( https://radio-pi.github.io/2016-01-12-setup-a-radio-pi/ )
14-
* [Software setup]( https://radio-pi.github.io/2016-01-13-setup-a-radio-pi-software/ )
12+
* [General setup]( https://radio-pi.github.io/2022-11-20-setup-a-radio-pi/ )
13+
* [Software setup]( https://radio-pi.github.io/2022-11-26-setup-a-radio-pi-software/ )
1514

1615

1716
# Development
@@ -27,18 +26,18 @@ pip install -e .
2726
Run with:
2827

2928
```
30-
twistd -ny service.tac
29+
uvicorn radiopi.main:app --reload
3130
```
3231

33-
Checkout the simple web client at [http://localhost:3000](http://localhost:3000)!
32+
Checkout the simple web client at [http://localhost:8000](http://localhost:8000)!
3433

3534

3635
# Testing
3736

3837
To run the test suite you need `tox`.
3938

4039
```
41-
tox -e py37
40+
tox -e py310
4241
```
4342

4443
### curl
@@ -47,15 +46,17 @@ Here are some useful `curl` commands to copy and paste:
4746

4847

4948
Play a stream or a file:
50-
5149
```
52-
# curl
53-
curl -H "Content-Type: application/json" -d '{"url":"http://fritz.de/livemp3"}' http://localhost:3000/play
50+
curl -H "Content-Type: application/json" -d '{"url":"http://fritz.de/livemp3"}' http://localhost:8000/play
5451
```
5552

5653

5754
Set volume to 100:
55+
```
56+
curl -H "Content-Type: application/json" -d '{"volume":"100"}' http://localhost:8000/volume
57+
```
5858

59+
Stop the stream:
5960
```
60-
curl -H "Content-Type: application/json" -d '{"volume":"100"}' http://localhost:3000/volume
61+
curl -H "Content-Type: application/json" -X POST http://localhost:8000/stop
6162
```

radiopi.service

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ After=syslog.target
55
[Service]
66
Type=simple
77
WorkingDirectory=/usr/local/src/radiopi
8-
ExecStart=/usr/local/src/radiopi/env/bin/twistd --nodaemon --pidfile= -y service.tac
8+
ExecStart=/usr/local/src/radiopi/env/bin/uvicorn radiopi.main:app --host 0.0.0.0
99
StandardOutput=syslog
1010
StandardError=syslog
1111

radiopi/api.py

Lines changed: 0 additions & 127 deletions
This file was deleted.

radiopi/backend/IPlayerInterface.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,37 @@ class IPlayer:
55
__metaclass__ = ABCMeta
66

77
@classmethod
8-
def version(self): return "1.0"
8+
def version(self):
9+
return "1.0"
910

1011
@abstractmethod
11-
def play(self, url): raise NotImplementedError
12+
def play(self, url):
13+
raise NotImplementedError
1214

1315
@abstractmethod
14-
def stop(self): raise NotImplementedError
16+
def stop(self):
17+
raise NotImplementedError
1518

1619
@abstractmethod
17-
def get_playing_key(self): raise NotImplementedError
20+
def get_playing_key(self):
21+
raise NotImplementedError
1822

1923
@abstractmethod
20-
def get_volume(self): raise NotImplementedError
24+
def get_volume(self):
25+
raise NotImplementedError
2126

2227
@abstractmethod
23-
def get_title(self): raise NotImplementedError
28+
def get_title(self):
29+
raise NotImplementedError
2430

2531
@abstractmethod
26-
def set_volume(self, volume): raise NotImplementedError
32+
def set_volume(self, volume):
33+
raise NotImplementedError
2734

2835
@abstractmethod
29-
def get_sleep_timer(self): raise NotImplementedError
36+
def get_sleep_timer(self):
37+
raise NotImplementedError
3038

3139
@abstractmethod
32-
def set_sleep_timer(self, timeInMinutes): raise NotImplementedError
40+
def set_sleep_timer(self, timeInMinutes):
41+
raise NotImplementedError

radiopi/backend/MusicPlayerDaemon.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from .IPlayerInterface import IPlayer
22
from mpd import MPDClient, ConnectionError
33

4-
HOST = 'localhost'
4+
HOST = "localhost"
55
PORT = 6600
66

7-
class Player(IPlayer):
87

8+
class Player(IPlayer):
99
def __init__(self):
1010
mclient = MPDClient()
1111
mclient.connect(HOST, PORT)
@@ -25,7 +25,7 @@ def stop(self):
2525
def get_volume(self):
2626
self.__client_alive()
2727
statusDICT = self.client.status()
28-
vol = statusDICT.get('volume')
28+
vol = statusDICT.get("volume")
2929
return vol
3030

3131
def set_volume(self, volume):

radiopi/backend/VLCPlayer.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010

1111
class Player(IPlayer):
12-
1312
def __init__(self):
1413
self.instance = vlc.Instance("--no-xlib")
1514
self.player = self.instance.media_player_new()
@@ -31,20 +30,20 @@ def get_playing_key(self):
3130
return url
3231

3332
def get_title(self):
34-
title = ''
33+
title = ""
3534
if not self.player.get_media():
3635
return title
3736

3837
url = self.player.get_media().get_mrl()
3938

40-
request = urllib2.Request(url, headers={'Icy-MetaData': 1})
39+
request = urllib2.Request(url, headers={"Icy-MetaData": 1})
4140
response = urllib2.urlopen(request)
42-
metaint = int(response.headers['icy-metaint'])
41+
metaint = int(response.headers["icy-metaint"])
4342

4443
for _ in range(200):
4544
response.read(metaint)
46-
metadata_length = struct.unpack('B', response.read(1))[0] * 16
47-
metadata = response.read(metadata_length).rstrip(b'\0')
45+
metadata_length = struct.unpack("B", response.read(1))[0] * 16
46+
metadata = response.read(metadata_length).rstrip(b"\0")
4847
metadata = self._decode_metadata(metadata)
4948

5049
m = re.search(r"StreamTitle='([^']*)';", metadata)
@@ -64,7 +63,7 @@ def set_volume(self, volume):
6463
def set_sleep_timer(self, timeInMinutes):
6564
"""
6665
Create a new sleep timer. Cancels any existing timers.
67-
When set to 0 cancles timers.
66+
When set to 0 cancels timers.
6867
"""
6968
if self.sleep_timer:
7069
self.sleep_timer.cancel()
@@ -80,10 +79,10 @@ def get_sleep_timer(self):
8079

8180
def _decode_metadata(self, metadata):
8281
try:
83-
metadata = metadata.decode('utf8')
82+
metadata = metadata.decode("utf8")
8483
except UnicodeDecodeError:
8584
try:
86-
metadata = metadata.decode('latin-1')
85+
metadata = metadata.decode("latin-1")
8786
except UnicodeDecodeError:
88-
metadata = metadata.decode('utf8', errors='replace')
87+
metadata = metadata.decode("utf8", errors="replace")
8988
return metadata

radiopi/backend/sleep.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from time import time
33

44

5-
class Sleep():
5+
class Sleep:
66
def __init__(self, sleepInMinutes, callbackFnc):
77
self.__time_in_sec = sleepInMinutes * 60
88
self.__callback = callbackFnc

0 commit comments

Comments
 (0)