Changeset - 8cab6a80215a
[Not reviewed]
default
0 3 1
drewp@bigasterisk.com - 20 months ago 2023-05-19 23:59:45
drewp@bigasterisk.com
asco cleanup, including a bugfix (rdflib dropped graph.label?)
4 files changed with 18 insertions and 7 deletions:
0 comments (0 inline, 0 general)
bin/ascoltami
Show inline comments
 
#!/bin/zsh
 
pnpm exec vite -c light9/ascoltami/vite.config.ts &
 
PYTHONPATH=`pwd` pdm run python light9/ascoltami/main.py
 
pdm run python light9/ascoltami/main.py
 
wait
light9/ascoltami/musictime_client.py
Show inline comments
 
import time, json, logging
 
from typing import Dict
 
from typing import Dict, cast
 
from twisted.internet.interfaces import IReactorTime
 

	
 
from twisted.internet import reactor
 
from twisted.internet.defer import inlineCallbacks
 
import treq
 

	
 
from light9 import networking
 

	
 
log = logging.getLogger()
 

	
 

	
 
class MusicTime(object):
 
    """
 
@@ -71,29 +72,29 @@ class MusicTime(object):
 

	
 
            position = yield response.json()
 

	
 
            # this is meant to be the time when the server gave me its
 
            # report, and I don't know if that's closer to the
 
            # beginning of my request or the end of it (or some
 
            # fraction of the way through)
 
            self.positionFetchTime = time.time()
 

	
 
            self.position = position
 
            self.onChange(position)
 

	
 
            reactor.callLater(self.period, self.pollMusicTime)
 
            cast(IReactorTime, reactor).callLater(self.period, self.pollMusicTime)
 

	
 
        def eb(err):
 
            log.warn("talking to ascoltami: %s", err.getErrorMessage())
 
            reactor.callLater(2, self.pollMusicTime)
 
            cast(IReactorTime, reactor).callLater(2, self.pollMusicTime)
 

	
 
        d = treq.get(networking.musicPlayer.path("time").toPython())
 
        d.addCallback(cb)
 
        d.addErrback(eb)  # note this includes errors in cb()
 

	
 
    def sendTime(self, t):
 
        """request that the player go to this time"""
 
        treq.post(
 
            networking.musicPlayer.path('time'),
 
            data=json.dumps({
 
                "t": time
 
            }).encode('utf8'),
light9/ascoltami/webapp.py
Show inline comments
 
@@ -2,25 +2,25 @@ import json
 
import logging
 
import socket
 
import subprocess
 
import time
 
from typing import cast
 

	
 
import cyclone.web
 
import cyclone.websocket
 
from cycloneerr import PrettyErrorHandler
 
from light9.metrics import metricsRoute
 
from light9.namespaces import L9
 
from light9.showconfig import getSongsFromShow, showUri, songOnDisk
 
from rdflib import URIRef
 
from rdflib import RDFS, Graph, URIRef
 
from twisted.internet import reactor
 
from twisted.internet.interfaces import IReactorTime
 

	
 
log = logging.getLogger()
 
_songUris = {}  # locationUri : song
 

	
 

	
 
def songLocation(graph, songUri):
 
    loc = URIRef("file://%s" % songOnDisk(songUri))
 
    _songUris[loc] = songUri
 
    return loc
 

	
 
@@ -115,30 +115,38 @@ class timeStreamResource(cyclone.websock
 
            self.lastSentTime = now
 

	
 
        if self.transport.connected:
 
            cast(IReactorTime, reactor).callLater(.2, self.loop)
 

	
 
    def connectionLost(self, reason):
 
        log.info("bye ws client %r: %s", self, reason)
 

	
 

	
 
class songs(PrettyErrorHandler, cyclone.web.RequestHandler):
 

	
 
    def get(self):
 
        graph = self.settings.app.graph
 
        graph = cast(Graph, self.settings.app.graph)
 

	
 
        songs = getSongsFromShow(graph, self.settings.app.show)
 

	
 
        self.set_header("Content-Type", "application/json")
 
        self.write(json.dumps({"songs": [{"uri": s, "path": graph.value(s, L9['showPath']), "label": graph.label(s)} for s in songs]}))
 
        self.write(json.dumps({
 
            "songs": [
 
                {  #
 
                    "uri": s,
 
                    "path": graph.value(s, L9['songFilename']),
 
                    "label": graph.value(s, RDFS.label)
 
                } for s in songs
 
            ]
 
        }))
 

	
 

	
 
class songResource(PrettyErrorHandler, cyclone.web.RequestHandler):
 

	
 
    def post(self):
 
        """post a uri of song to switch to (and start playing)"""
 
        graph = self.settings.app.graph
 

	
 
        self.settings.app.player.setSong(songLocation(graph, URIRef(self.request.body.decode('utf8'))))
 
        self.set_header("Content-Type", "text/plain")
 
        self.write("ok")
 

	
light9/ascoltami/webapp_test.py
Show inline comments
 
new file 100644
 
# todo
 
# test that GET /songs doesn't break, etc
0 comments (0 inline, 0 general)