示例#1
0
def handle_uri_change(service, action):
    from server import get_context
    CONTEXT = get_context()
    uri = action.get_value("CurrentURI", GObject.TYPE_STRING)
    if not uri:
      return None
    
    print uri, CONTEXT.get_host_ip(), CONTEXT.get_port()
    if CONTEXT.get_host_ip() in uri and str(CONTEXT.get_port()) in uri:
        return set_mpd_uri(service, action, uri)
    else:
        return set_http_uri(service, action, uri)
示例#2
0
def setup_mpd():
    global CON_ID, MPDCLIENT, HOST, PORT
    CON_ID = {'host':HOST, 'port':PORT}

    client.MPDCLIENT = MPDClient(CON_ID)
    
    import server
    library.LIBRARY = MPDLibrary(client.get_client(),
                                 CON_ID, server.get_context(),
                                 MUSIC_PATH)

    library.LIBRARY.start_updating()
    
    print "Scheduling MPD Database refresh every 60 seconds..."
示例#3
0
def set_http_uri(service, action, uri):
    """
    This is a bit tricker.  We need to download the file from the local network
    (hopefully its quick), add the file to MPD (the file has to be 100% downloaded first)
    then add the file to the playlist and seek to it.

    1) Download file
    2) Add file to DB
    3) Load file to local library
    4) Generate an MPD uri and then call set_mpd_uri
    """
    LIBRARY = get_library()
    MPDCLIENT = get_client()
    from server import get_context, MUSIC_PATH
    CONTEXT = get_context()

    path = uri.replace("http:/", "")
    filename = os.path.basename(path)

    if not "." in filename:
        filename += ".mp3" # assume mp3 for now
    
    os.system("wget %s -O %s/%s" % (uri, MUSIC_PATH, filename))
    
    LIBRARY.connect()
    MPDCLIENT.update(filename)
    
    songdata = MPDCLIENT.find('file', filename)
    if not songdata:
        action.return_error(0, "Couldn't add file to MPD database")
        return
    
    song_id = LIBRARY.register_song(LIBRARY.song_from_dict(songdata[0]))

    LIBRARY.disconnect()
    set_mpd_uri(service, action, "http://%s:%s/file/%s" % (
        CONTEXT.get_host_ip(),
        CONTEXT.get_port(),
        song_id)
                )