fix bug where playback on current stream is not stopped for new station. add preliminary album import methods

workspace
Brendan Howell 3 years ago
parent 0e146c14ff
commit 8432544f7e

@ -1,3 +1,4 @@
import glob
import urllib.request import urllib.request
import kode256 import kode256
@ -6,8 +7,9 @@ import gi
from gi.repository import TotemPlParser from gi.repository import TotemPlParser
from gsp import GstreamerPlayer 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): class Audio(Bureau):
@ -34,12 +36,13 @@ class Audio(Bureau):
stored on the local office or remote URLs for live playback. Currently, stored on the local office or remote URLs for live playback. Currently,
only supports line-out signals on the default DAC. only supports line-out signals on the default DAC.
""" """
self.stop()
shortcode, _ = data.split(".") shortcode, _ = data.split(".")
self.log.debug("looking up shortcode " + shortcode) self.log.debug("looking up shortcode " + shortcode)
pl_url = self.urldb.get(shortcode) pl_url = self.urldb.get(shortcode)
self.log.debug(" playing url " + pl_url) self.log.debug(" playing url " + pl_url)
pl_file, _ = urllib.request.urlretrieve(pl_url) pl_file, _ = urllib.request.urlretrieve(pl_url)
pl_file= "file://" + pl_file pl_file = "file://" + pl_file
parser = TotemPlParser.Parser() parser = TotemPlParser.Parser()
urls = [] urls = []
@ -51,9 +54,8 @@ class Audio(Bureau):
parser.parse(pl_file, False) parser.parse(pl_file, False)
for url in urls: for url in urls:
print("stream uri", url)
self.player.queue(url) self.player.queue(url)
self.current_uri = url self.current_uri = urls[0]
@add_command("stop", "Halt audio playback.") @add_command("stop", "Halt audio playback.")
def stop(self): def stop(self):
@ -147,6 +149,24 @@ class Audio(Bureau):
return ret 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): def save_url(self, url):
""" """
saves an url for a local file or network audio stream. 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) self.print_small("Error: connect error on " + url)
return return
# TODO: support #EXTINF: extended attributes - logo or #EXTIMG or #PLAYLIST # TODO: get rid of this stuff and use the playlist parser
# TODO: support XSPF?? does anyone use this?
# TODO: what to do with unwrapped links - raw mp3 or whateva - use vlc info? # 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 = "" title = ""
for line in resp.text.splitlines(): for line in resp.text.splitlines():
if line.startswith("#EXTINF:"): if line.startswith("#EXTINF:"):
@ -185,7 +202,6 @@ class Audio(Bureau):
# this looks like a pls playlist - title is from first '=' to EOL # this looks like a pls playlist - title is from first '=' to EOL
title = line[(line.find('=') + 1):].strip() title = line[(line.find('=') + 1):].strip()
# TODO: create barcode
# small print title, url, barcode # small print title, url, barcode
prn = self._get_small_printer() prn = self._get_small_printer()
@ -199,7 +215,6 @@ class Audio(Bureau):
prn.close() prn.close()
def main(): def main():
au = Audio() au = Audio()
au.run() au.run()

@ -589,17 +589,13 @@ class Bureau(object):
dot = msg.find(".") dot = msg.find(".")
ref = msg[:dot] ref = msg[:dot]
if (dot < len(msg) - 1) and (dot > 0): if (dot < len(msg) - 1) and (dot > 0):
self.log.debug("msg length: %d", len(msg)) # trim off the trailing "." for convenience
self.log.debug("dot at %d", dot)
# TODO: maybe trim off the trailing "." for convenience
data = msg[dot + 1:] data = msg[dot + 1:]
else: else:
data = None data = None
self.log.debug("data: " + str(data))
except IndexError as err: except IndexError as err:
self.log.warning("invalid message: %s", err) self.log.warning("invalid message: %s", err)
continue continue
self.log.debug("got method: " + ref)
if (ref in self.commands) or (ref in self.api) or (ref in if (ref in self.commands) or (ref in self.api) or (ref in
self.webviews): self.webviews):

Loading…
Cancel
Save