From c0433e715a46684ce18c17ce690b3b5315808b06 Mon Sep 17 00:00:00 2001 From: Brendan Howell Date: Mon, 26 Feb 2018 18:19:48 +0100 Subject: [PATCH] Audio Services dept. first commands - add url, play. good enough for internet radio basics. --- screenless/bureau/audio/__init__.py | 4 +++ screenless/bureau/audio/audio.py | 51 +++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 screenless/bureau/audio/__init__.py create mode 100644 screenless/bureau/audio/audio.py diff --git a/screenless/bureau/audio/__init__.py b/screenless/bureau/audio/__init__.py new file mode 100644 index 0000000..061097e --- /dev/null +++ b/screenless/bureau/audio/__init__.py @@ -0,0 +1,4 @@ +from . import audio + +def main(): + audio.main() diff --git a/screenless/bureau/audio/audio.py b/screenless/bureau/audio/audio.py new file mode 100644 index 0000000..dd80376 --- /dev/null +++ b/screenless/bureau/audio/audio.py @@ -0,0 +1,51 @@ +import mplayer + +from bureau import Bureau, add_command + + +class Audio(Bureau): + """ + The Audio Services department provides for playback and recording + of sound within the office environment. + """ + + name = "Audio Services Dept." + prefix = "AU" + version = 0 + + def __init__(self): + Bureau.__init__(self) + + self.player = mplayer.Player() + self.urldb = self.open_db("urldb") + + @add_command("p", "Play an album, track or a live stream.") + def play(self, data): + """ + Initiates playback of a media reference. This could be a song or album + stored on the local office or remote URLs for live playback. Currently, + only supports line-out signals on the default DAC. + """ + shortcode, _ = data.split(".") + url = self.urldb.get(shortcode) + + if not self.player.is_alive(): + self.player.spawn() + + self.player.loadfile(url) + + def save_url(self, url): + """ + saves an url for a local file or network audio stream. + """ + code = self.urldb.store_and_get_shortcode(url) + print("saved url with shortcode: ", code) + + +def main(): + au = Audio() + au.run() + + +if __name__ == "__main__": + main()