|
|
|
@ -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()
|
|
|
|
|