From 8432544f7e4b6176b61e94d7850a2fa6ac015a47 Mon Sep 17 00:00:00 2001 From: Brendan Howell Date: Wed, 2 Feb 2022 23:47:53 +0100 Subject: [PATCH] fix bug where playback on current stream is not stopped for new station. add preliminary album import methods --- screenless/bureau/audio/audio.py | 35 +++++++++++++++++++++++--------- screenless/bureau/bureau.py | 6 +----- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/screenless/bureau/audio/audio.py b/screenless/bureau/audio/audio.py index 870a48a..5c675f8 100644 --- a/screenless/bureau/audio/audio.py +++ b/screenless/bureau/audio/audio.py @@ -1,3 +1,4 @@ +import glob import urllib.request import kode256 @@ -6,8 +7,9 @@ import gi from gi.repository import TotemPlParser from gsp import GstreamerPlayer +from tinytag import TinyTag -from bureau import Bureau, add_command, add_webview +from bureau import Bureau, add_command, add_webview, add_api class Audio(Bureau): @@ -34,12 +36,13 @@ class Audio(Bureau): stored on the local office or remote URLs for live playback. Currently, only supports line-out signals on the default DAC. """ + self.stop() shortcode, _ = data.split(".") self.log.debug("looking up shortcode " + shortcode) pl_url = self.urldb.get(shortcode) self.log.debug(" playing url " + pl_url) pl_file, _ = urllib.request.urlretrieve(pl_url) - pl_file= "file://" + pl_file + pl_file = "file://" + pl_file parser = TotemPlParser.Parser() urls = [] @@ -51,9 +54,8 @@ class Audio(Bureau): parser.parse(pl_file, False) for url in urls: - print("stream uri", url) self.player.queue(url) - self.current_uri = url + self.current_uri = urls[0] @add_command("stop", "Halt audio playback.") def stop(self): @@ -147,6 +149,24 @@ class Audio(Bureau): return ret + @add_api("add_album", "Add a music album.") + def add_album(self, data): + """ + add a local folder with music or audio + """ + try: + im_dir = data["album_dir"] + store = data["music_dir"] + except KeyError as e: + self.log.error("you must specify a directory to import") + # scan to find out the name(s) of artist/albums and track order + + + # create necessary folders and copy the files over + # create a playlist and add the files in the right order + # save the url + # print a nice card for perusal and playing + def save_url(self, url): """ saves an url for a local file or network audio stream. @@ -171,11 +191,8 @@ class Audio(Bureau): self.print_small("Error: connect error on " + url) return - # TODO: support #EXTINF: extended attributes - logo or #EXTIMG or #PLAYLIST - # TODO: support XSPF?? does anyone use this? + # TODO: get rid of this stuff and use the playlist parser # TODO: what to do with unwrapped links - raw mp3 or whateva - use vlc info? - # if line startswith #EXTINF: title = first comma to EOL - # if line startswith Title then title = first '=' to EOL title = "" for line in resp.text.splitlines(): if line.startswith("#EXTINF:"): @@ -185,7 +202,6 @@ class Audio(Bureau): # this looks like a pls playlist - title is from first '=' to EOL title = line[(line.find('=') + 1):].strip() - # TODO: create barcode # small print title, url, barcode prn = self._get_small_printer() @@ -198,7 +214,6 @@ class Audio(Bureau): #TODO: cut prn.close() - def main(): au = Audio() diff --git a/screenless/bureau/bureau.py b/screenless/bureau/bureau.py index 0d72203..3b2962f 100644 --- a/screenless/bureau/bureau.py +++ b/screenless/bureau/bureau.py @@ -589,17 +589,13 @@ class Bureau(object): dot = msg.find(".") ref = msg[:dot] if (dot < len(msg) - 1) and (dot > 0): - self.log.debug("msg length: %d", len(msg)) - self.log.debug("dot at %d", dot) - # TODO: maybe trim off the trailing "." for convenience + # trim off the trailing "." for convenience data = msg[dot + 1:] else: data = None - self.log.debug("data: " + str(data)) except IndexError as err: self.log.warning("invalid message: %s", err) continue - self.log.debug("got method: " + ref) if (ref in self.commands) or (ref in self.api) or (ref in self.webviews):