|
@@ -11,7 +11,10 @@ import pygame # type: ignore
|
|
|
import tornado.ioloop, tornado.web
|
|
|
import asyncio
|
|
|
|
|
|
-import RPi.GPIO as GPIO # Support for Raspberry PI GPIO input
|
|
|
+try:
|
|
|
+ import RPi.GPIO as GPIO # Support for Raspberry PI GPIO input
|
|
|
+except:
|
|
|
+ import mock_rpi_gpio as GPIO
|
|
|
|
|
|
from display import Display
|
|
|
from player import Player
|
|
@@ -38,6 +41,7 @@ class Musikautomat:
|
|
|
|
|
|
# Initialise state objects
|
|
|
|
|
|
+ self._autostart = config.get("autostart")
|
|
|
self._pydsp = pydsp
|
|
|
self._display = Display(config, self._pydsp)
|
|
|
self._display.update()
|
|
@@ -95,6 +99,10 @@ class Musikautomat:
|
|
|
clk = pygame.time.Clock()
|
|
|
gpio_event_timer = 0
|
|
|
|
|
|
+ if self._autostart:
|
|
|
+ self.eventRight()
|
|
|
+ self.eventRight()
|
|
|
+
|
|
|
while True:
|
|
|
clk.tick(10) # We only need 10 FPS
|
|
|
|
|
@@ -154,6 +162,9 @@ class Musikautomat:
|
|
|
|
|
|
pygame.display.update()
|
|
|
|
|
|
+ def toDisplayName(self, s):
|
|
|
+ s = os.path.splitext(s)[0]
|
|
|
+ return s.replace("_", " ").title()
|
|
|
|
|
|
def play(self, item, start=False):
|
|
|
'''
|
|
@@ -166,6 +177,10 @@ class Musikautomat:
|
|
|
t = item.get("type")
|
|
|
if t == "dir":
|
|
|
self.playDir(item)
|
|
|
+ elif t == "m3u":
|
|
|
+ self.playM3U(item)
|
|
|
+ elif t == "stream":
|
|
|
+ self.playStream(item)
|
|
|
else:
|
|
|
raise Exception("Unknown type: %s" % t)
|
|
|
|
|
@@ -173,6 +188,18 @@ class Musikautomat:
|
|
|
self._player.togglePlay()
|
|
|
|
|
|
|
|
|
+ def playStream(self, item):
|
|
|
+ '''
|
|
|
+ Play a stream.
|
|
|
+ '''
|
|
|
+ self._player.setPlaylist([{
|
|
|
+ "name" : item["name"],
|
|
|
+ "path" : item["url"]
|
|
|
+ }])
|
|
|
+
|
|
|
+ self._player.update()
|
|
|
+
|
|
|
+
|
|
|
def playDir(self, item):
|
|
|
'''
|
|
|
Play all files in a directory.
|
|
@@ -180,13 +207,29 @@ class Musikautomat:
|
|
|
path = item.get("path")
|
|
|
files = os.listdir(path)
|
|
|
|
|
|
- def toDisplayName(s):
|
|
|
- s = os.path.splitext(s)[0]
|
|
|
- return s.replace("_", " ").title()
|
|
|
-
|
|
|
self._player.setPlaylist(sorted([{
|
|
|
- "name" : toDisplayName(f),
|
|
|
+ "name" : self.toDisplayName(f),
|
|
|
"path" : os.path.join(path, f)
|
|
|
} for f in files], key=lambda i: i["name"]))
|
|
|
|
|
|
self._player.update()
|
|
|
+
|
|
|
+
|
|
|
+ def playM3U(self, item):
|
|
|
+ '''
|
|
|
+ Play all files of a M3U playlist.
|
|
|
+ '''
|
|
|
+ path = item.get("path")
|
|
|
+ items = []
|
|
|
+
|
|
|
+ with open(path) as f:
|
|
|
+ for line in f:
|
|
|
+ item_path = str(line).strip()
|
|
|
+ if not item_path.startswith("#"):
|
|
|
+ items.append({
|
|
|
+ "name" : self.toDisplayName(os.path.basename(item_path)),
|
|
|
+ "path" : os.path.join(os.path.dirname(path), item_path)
|
|
|
+ })
|
|
|
+
|
|
|
+ self._player.setPlaylist(items)
|
|
|
+ self._player.update()
|