From 9055646f4c7ded6f17b15d93999b75b9f9195187 Mon Sep 17 00:00:00 2001 From: Brendan Howell Date: Sun, 22 Nov 2020 17:33:13 +0100 Subject: [PATCH] method to add and print radio stations --- screenless/bureau/audio/audio.py | 43 +++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/screenless/bureau/audio/audio.py b/screenless/bureau/audio/audio.py index 722a463..d367251 100644 --- a/screenless/bureau/audio/audio.py +++ b/screenless/bureau/audio/audio.py @@ -1,3 +1,5 @@ +import kode256 +import requests import vlc from bureau import Bureau, add_command, add_webview @@ -77,7 +79,7 @@ class Audio(Bureau): out += self.player.get_media().get_meta(vlc.Meta.Title) + "\n" nowplaying = self.player.get_media().get_meta(vlc.Meta.NowPlaying) if nowplaying == "": - out += "by " + self.player.get_media().get_meta(vlc.Meta.Title) + "\n" + out += "by " + self.player.get_media().get_meta(vlc.Meta.Artist) + "\n" out += "from the album '" + self.player.get_media().get_meta(vlc.Meta.Album) \ + "'\n" else: @@ -131,8 +133,47 @@ class Audio(Bureau): saves an url for a local file or network audio stream. """ code = self.urldb.store_and_get_shortcode(url) + self.print_url(code) print("saved url with shortcode: ", code) + def print_url(self, shortcode): + url = self.urldb.get(shortcode) + # download the url + headers = {'User-Agent': 'Mozilla/5.0'} + try: + resp = requests.get(rl, timeout=20.0, headers=headers) + except requests.ReadTimeout: + self.log.warning("Timeout reading url %s", url) + self.print_small("Error: timed out reading " + url) + return + except requests.ConnectionError as e: + self.log.warning("Error reading url %s", url) + 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: 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: + if line.startswith("#EXTINF:"): + # this is m3u playlist - title is from first comma to EOL + title = line[(line.find(',') + 1):].strip() + elif line.startswith("Title"): + # 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 + txt = "RADIO STATION:\r\n" + title + "\r\n" + url + self.print_small(txt, cut=False) + + bc_img = kode256.image("AUp." + shortcode) + self.print_small_image(bc_img) + + def main(): au = Audio()