method to add and print radio stations

workspace
Brendan Howell 4 years ago
parent 17a9ba708f
commit 9055646f4c

@ -1,3 +1,5 @@
import kode256
import requests
import vlc import vlc
from bureau import Bureau, add_command, add_webview 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" out += self.player.get_media().get_meta(vlc.Meta.Title) + "\n"
nowplaying = self.player.get_media().get_meta(vlc.Meta.NowPlaying) nowplaying = self.player.get_media().get_meta(vlc.Meta.NowPlaying)
if 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) \ out += "from the album '" + self.player.get_media().get_meta(vlc.Meta.Album) \
+ "'\n" + "'\n"
else: else:
@ -131,8 +133,47 @@ class Audio(Bureau):
saves an url for a local file or network audio stream. saves an url for a local file or network audio stream.
""" """
code = self.urldb.store_and_get_shortcode(url) code = self.urldb.store_and_get_shortcode(url)
self.print_url(code)
print("saved url with shortcode: ", 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(): def main():
au = Audio() au = Audio()

Loading…
Cancel
Save