Changeset - 2b2f5da47c5d
[Not reviewed]
default
0 2 0
drewp@bigasterisk.com - 17 years ago 2008-06-09 07:07:10
drewp@bigasterisk.com
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
2 files changed with 25 insertions and 25 deletions:
0 comments (0 inline, 0 general)
bin/ascoltami
Show inline comments
 
@@ -33,16 +33,17 @@ todo:
 
"""
 

	
 
from __future__ import division,nested_scopes
 

	
 
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
 
from twisted.web import xmlrpc, server
 

	
 
import run_local
 
@@ -106,13 +107,15 @@ class Player:
 

	
 
    song_pad_time = 10
 
    
 
    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'
 

	
 
        self.current_time = tk.DoubleVar()
 
        self.total_time = tk.DoubleVar()
 
@@ -258,30 +261,29 @@ class Player:
 
    def skip_to_post(self):
 
        self.seek_to(self.total_time.get() + self.song_pad_time)
 
        self.play()
 

	
 

	
 
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)
 

	
 
    def _nextAction(self):
 
        state = self.player.state.get() 
 
        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':
 
            return "play", self.player.play
 

	
 
        if state == 'play':
 
@@ -490,18 +492,20 @@ 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")
 

	
 

	
 
    root=tk.Tk()
light9/showconfig.py
Show inline comments
 
@@ -51,39 +51,35 @@ def findMpdHome():
 
                mpdHome = line.split()[1].strip('"')
 
                return mpdHome.rstrip(path.sep) + path.sep  
 

	
 
    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
 

	
 
    changed root to /home/drewp/projects/light9/show/dance2005 for now
 
    """
 

	
 
    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):
 
    """
 
    'http://light9.bigasterisk.com/show/dance2007/song8' -> 'song8'
 

	
0 comments (0 inline, 0 general)