# HG changeset patch # User drewp@bigasterisk.com # Date 2008-06-09 07:07:10 # Node ID 2b2f5da47c5db09388f0de8b6f1cbbbb05f37e68 # Parent c7766729921a72042ba61f00fd7f7d331b201143 config file now lists paths in the same form you'd give to mpd. New cmdline on ascoltami to specify the song list from config.n3 diff --git a/bin/ascoltami b/bin/ascoltami --- a/bin/ascoltami +++ b/bin/ascoltami @@ -36,10 +36,11 @@ from __future__ import division,nested_s from optparse import OptionParser import os,math,time +from rdflib import URIRef import Tkinter as tk -#import logging -#log = logging.getLogger() -#log.setLevel(logging.DEBUG) +import logging +log = logging.getLogger() +log.setLevel(logging.DEBUG) from twisted.internet import reactor,tksupport from twisted.internet.error import CannotListenError @@ -109,7 +110,9 @@ class Player: def __init__(self): self.mpd = Mpd() - reactor.connectTCP(*(networking.mpdServer()+(self.mpd,))) + args = (networking.mpdServer()+(self.mpd,)) + log.info("connecting to %r", args) + reactor.connectTCP(*args) self.state = tk.StringVar() self.state.set("stop") # 'stop' 'pause' 'play' @@ -261,10 +264,10 @@ class Player: class GoButton: - def __init__(self, player, statusLabel, songPaths): + def __init__(self, player, statusLabel, songURIs): self.player = player self.statusLabel = statusLabel - self.songPaths = songPaths + self.songURIs = songURIs self.player.current_time.trace("w", self.updateStatus) @@ -273,12 +276,11 @@ class GoButton: if state == 'stop': currentPath = self.player.song_uri try: - i = self.songPaths.index(currentPath) + 1 + i = self.songURIs.index(currentPath) + 1 except ValueError: i = 0 - nextPath = self.songPaths[i] - return ("next song %s" % shortSongPath(nextPath, - self.songPaths), + nextPath = self.songURIs[i] + return ("next song %s" % shortSongPath(nextPath, self.songURIs), lambda: self.player.play(nextPath)) if state == 'pause': @@ -493,12 +495,14 @@ class ControlButtons(tk.Frame): def main(): global graph parser = OptionParser() + parser.add_option('--show', + help='show URI, like http://light9.bigasterisk.com/show/dance2008') graph = showconfig.getGraph() (options, songfiles) = parser.parse_args() if len(songfiles)<1: graph = showconfig.getGraph() - playList = graph.value(L9['show/dance2007'], L9['playList']) + playList = graph.value(URIRef(options.show), L9['playList']) songs = list(graph.items(playList)) else: raise NotImplementedError("don't know how to make rdf song nodes from cmdline song paths") diff --git a/light9/showconfig.py b/light9/showconfig.py --- a/light9/showconfig.py +++ b/light9/showconfig.py @@ -54,10 +54,11 @@ def findMpdHome(): raise ValueError("can't find music_directory in any mpd config file") +def songInMpd(song): + """ + get the mpd path (with correct encoding) from the song URI -def songInMpd(song): - - """mpd only works off its own musicroot, which for me is + mpd only works off its own musicroot, which for me is /my/music. song is a file in musicDir; this function returns a version starting with the mpd path, but minus the mpd root itself. the mpc ~/.mpdconf @@ -67,20 +68,15 @@ def songInMpd(song): assert isinstance(song, URIRef), "songInMpd now takes URIRefs" - mpdHome = findMpdHome() - - songFullPath = songOnDisk(song) - if not songFullPath.startswith(mpdHome): - raise ValueError("the song path %r is not under your MPD music_directory (%r)" % (songFullPath, mpdHome)) - - mpdRelativePath = songFullPath[len(mpdHome):] - if path.join(mpdHome, mpdRelativePath) != songFullPath: - raise ValueError("%r + %r doesn't make the songpath %r" % (mpdHome, mpdRelativePath, songFullPath)) - return mpdRelativePath.encode('ascii') + mpdPath = getGraph().value(song, L9['showPath']) + if mpdPath is None: + raise ValueError("no mpd path found for subject=%r" % song) + return mpdPath.encode('ascii') def songOnDisk(song): + """given a song URI, where's the on-disk file that mpd would read?""" graph = getGraph() - songFullPath = path.join(root(), graph.value(song, L9['showPath'])) + songFullPath = path.join(findMpdHome(), graph.value(song, L9['showPath'])) return songFullPath def songFilenameFromURI(uri):