Author: duncan
Date: Thu Jan 10 15:19:49 2008
New Revision: 10278
Log:
[ 1865008 ] replacement MPD plugin
Updated patch from Graham Billiau applied
Modified:
branches/rel-1-7/freevo/src/audio/plugins/mpd_playlist.py
branches/rel-1-7/freevo/src/audio/plugins/mpd_status.py
branches/rel-1/freevo/src/audio/plugins/mpd_playlist.py
branches/rel-1/freevo/src/audio/plugins/mpd_status.py
Modified: branches/rel-1-7/freevo/src/audio/plugins/mpd_playlist.py
==============================================================================
--- branches/rel-1-7/freevo/src/audio/plugins/mpd_playlist.py (original)
+++ branches/rel-1-7/freevo/src/audio/plugins/mpd_playlist.py Thu Jan 10
15:19:49 2008
@@ -22,7 +22,6 @@
# Todo:
#
# add code to cope if the mpd server crashes
-# add code to enqueue an entire directory & sub-directories
# add code to enqueue an existing playlist
# modify code to support localisation
# investigate having the mpd connection managed by another class
@@ -52,6 +51,8 @@
import config
import mpdclient2
+import os.path
+
class PluginInterface(plugin.ItemPlugin):
"""
This plugin adds a 'enqueue in MPD' option to audio files
@@ -64,10 +65,7 @@
__author_email__ = '[EMAIL PROTECTED]'
__maintainer__ = __author__
__maintainer_email__ = __author_email__
- __version__ = '$Revision$'
- """open the connection to the mpd server and keep it alive
- assume that the plugin is loaded once, then kept in memory"""
-
+ __version__ = '2'
def __init__(self):
if not config.MPD_MUSIC_BASE_PATH:
@@ -75,6 +73,8 @@
return
plugin.ItemPlugin.__init__(self)
+ # open the connection to the mpd server and keep it alive
+ # assume that the plugin is loaded once, then kept in memory
self.conn = mpdclient2.Thread_MPD_Connection(config.MPD_SERVER_HOST,
config.MPD_SERVER_PORT, True,
config.MPD_SERVER_PASSWORD)
@@ -82,6 +82,9 @@
if not config.MPD_MUSIC_BASE_PATH.endswith('/'):
config.MPD_MUSIC_BASE_PATH = config.MPD_MUSIC_BASE_PATH + '/'
+ # don't calculate this every time
+ self.path_len = len(config.MPD_MUSIC_BASE_PATH)
+
def config(self):
"""returns the config variables used by this plugin"""
@@ -108,25 +111,58 @@
def actions (self, item):
"""add the option for all music that is in the mpd library"""
self.item = item
- # check to see if item is a FileItem
- if (item.type == 'file'):
+
+ # check to see if item is a AudioItem
+ if (item.type == 'audio'):
# check to see if item is in mpd's library
if (item.filename.startswith(config.MPD_MUSIC_BASE_PATH)):
# can query mpd to see if the file is in it's ibrary
return [ (self.enqueue_file, 'Add to MPD playlist') ]
- #elif (item.type == 'dir'):
+
+ elif (item.type == 'dir'):
+ if (item.dir.startswith(config.MPD_MUSIC_BASE_PATH)):
+ return [
+ (self.enqueue_dir, 'Add tracks to MPD playlist'),
+ (self.enqueue_dir_recursive, 'Add tracks to MPD playlist
recursively')
+ ]
+
#elif (item.type == 'playlist'):
return []
def enqueue_file(self, arg=None, menuw=None):
- self.conn.add(self.item.filename[len(config.MPD_MUSIC_BASE_PATH):])
+ self.conn.add(self.item.filename[self.path_len:])
+
if menuw is not None:
menuw.delete_menu(arg, menuw)
+ menuw.refresh()
return
- #def enqueue_dir(self, arg=None, menuw=None):
+ def enqueue_dir(self, arg=None, menuw=None):
+ path = self.item.dir[self.path_len:]
+ # rather than searching the filesystem for files, just search mpd's
database
+ for track in self.conn.search('file', path + '/'):
+ # filter out subdirectories
+ if (os.path.dirname(track.file) == path):
+ self.conn.add(track.file)
+
+ if menuw is not None:
+ menuw.delete_menu(arg, menuw)
+ menuw.refresh()
+ return
+
+
+ def enqueue_dir_recursive(self, arg=None, menuw=None):
+ path = self.item.dir[self.path_len:] + '/'
+ # rather than searching the filesystem for files, just search mpd's
database
+ for track in self.conn.search('file', path):
+ self.conn.add(track.file)
+
+ if menuw is not None:
+ menuw.delete_menu(arg, menuw)
+ menuw.refresh()
+ return
#def enqueue_playlist(self, arg=None, menuw=None):
Modified: branches/rel-1-7/freevo/src/audio/plugins/mpd_status.py
==============================================================================
--- branches/rel-1-7/freevo/src/audio/plugins/mpd_status.py (original)
+++ branches/rel-1-7/freevo/src/audio/plugins/mpd_status.py Thu Jan 10
15:19:49 2008
@@ -24,7 +24,6 @@
# have status/everything update periodicly
# add a playlist browser
# code to handle when the mpd server is down
-# show the currently playing song in the status view
# -----------------------------------------------------------------------
# Freevo - A Home Theater PC framework
# Copyright (C) 2002 Krister Lagerstrom, et al.
@@ -71,7 +70,7 @@
__author_email__ = '[EMAIL PROTECTED]'
__maintainer__ = __author__
__maintainer_email__ = __author_email__
- __version__ = '$Revision$'
+ __version__ = '2'
def __init__(self):
@@ -82,7 +81,7 @@
plugin.MainMenuPlugin.__init__(self)
self.show_item = menu.MenuItem('MPD status', action=self.show_menu)
- self.show_item.type = 'audio'
+ #self.show_item.type = 'menu'
plugin.register(self, 'audio.MPD_status')
# connect to the server
self.conn = mpdclient2.Thread_MPD_Connection(config.MPD_SERVER_HOST,
config.MPD_SERVER_PORT, True,
@@ -252,10 +251,13 @@
def mpd_status(self, arg=None, menuw=None):
"""bring up a dialog showing mpd's current status"""
stat = self.conn.status()
+ track = self.conn.currentsong()
text = "status: %s\n" %(stat['state'])
if (stat['state'] != 'stop'):
- # how do i get the song name?
+ text += "title: %s\n" %(track['title'])
+ text += "album: %s\n" %(track['album'])
+ text += "artist: %s\n" %(track['artist'])
text += "track: %s\\%s\n" %(int(stat['song']) + 1,
stat['playlistlength'])
text += "time: %s\n" %(stat['time'])
if (stat['repeat'] == '1'):
Modified: branches/rel-1/freevo/src/audio/plugins/mpd_playlist.py
==============================================================================
--- branches/rel-1/freevo/src/audio/plugins/mpd_playlist.py (original)
+++ branches/rel-1/freevo/src/audio/plugins/mpd_playlist.py Thu Jan 10
15:19:49 2008
@@ -22,7 +22,6 @@
# Todo:
#
# add code to cope if the mpd server crashes
-# add code to enqueue an entire directory & sub-directories
# add code to enqueue an existing playlist
# modify code to support localisation
# investigate having the mpd connection managed by another class
@@ -52,6 +51,8 @@
import config
import mpdclient2
+import os.path
+
class PluginInterface(plugin.ItemPlugin):
"""
This plugin adds a 'enqueue in MPD' option to audio files
@@ -64,10 +65,7 @@
__author_email__ = '[EMAIL PROTECTED]'
__maintainer__ = __author__
__maintainer_email__ = __author_email__
- __version__ = '$Revision$'
- """open the connection to the mpd server and keep it alive
- assume that the plugin is loaded once, then kept in memory"""
-
+ __version__ = '2'
def __init__(self):
if not config.MPD_MUSIC_BASE_PATH:
@@ -75,6 +73,8 @@
return
plugin.ItemPlugin.__init__(self)
+ # open the connection to the mpd server and keep it alive
+ # assume that the plugin is loaded once, then kept in memory
self.conn = mpdclient2.Thread_MPD_Connection(config.MPD_SERVER_HOST,
config.MPD_SERVER_PORT, True,
config.MPD_SERVER_PASSWORD)
@@ -82,6 +82,9 @@
if not config.MPD_MUSIC_BASE_PATH.endswith('/'):
config.MPD_MUSIC_BASE_PATH = config.MPD_MUSIC_BASE_PATH + '/'
+ # don't calculate this every time
+ self.path_len = len(config.MPD_MUSIC_BASE_PATH)
+
def config(self):
"""returns the config variables used by this plugin"""
@@ -108,25 +111,58 @@
def actions (self, item):
"""add the option for all music that is in the mpd library"""
self.item = item
- # check to see if item is a FileItem
- if (item.type == 'file'):
+
+ # check to see if item is a AudioItem
+ if (item.type == 'audio'):
# check to see if item is in mpd's library
if (item.filename.startswith(config.MPD_MUSIC_BASE_PATH)):
# can query mpd to see if the file is in it's ibrary
return [ (self.enqueue_file, 'Add to MPD playlist') ]
- #elif (item.type == 'dir'):
+
+ elif (item.type == 'dir'):
+ if (item.dir.startswith(config.MPD_MUSIC_BASE_PATH)):
+ return [
+ (self.enqueue_dir, 'Add tracks to MPD playlist'),
+ (self.enqueue_dir_recursive, 'Add tracks to MPD playlist
recursively')
+ ]
+
#elif (item.type == 'playlist'):
return []
def enqueue_file(self, arg=None, menuw=None):
- self.conn.add(self.item.filename[len(config.MPD_MUSIC_BASE_PATH):])
+ self.conn.add(self.item.filename[self.path_len:])
+
if menuw is not None:
menuw.delete_menu(arg, menuw)
+ menuw.refresh()
return
- #def enqueue_dir(self, arg=None, menuw=None):
+ def enqueue_dir(self, arg=None, menuw=None):
+ path = self.item.dir[self.path_len:]
+ # rather than searching the filesystem for files, just search mpd's
database
+ for track in self.conn.search('file', path + '/'):
+ # filter out subdirectories
+ if (os.path.dirname(track.file) == path):
+ self.conn.add(track.file)
+
+ if menuw is not None:
+ menuw.delete_menu(arg, menuw)
+ menuw.refresh()
+ return
+
+
+ def enqueue_dir_recursive(self, arg=None, menuw=None):
+ path = self.item.dir[self.path_len:] + '/'
+ # rather than searching the filesystem for files, just search mpd's
database
+ for track in self.conn.search('file', path):
+ self.conn.add(track.file)
+
+ if menuw is not None:
+ menuw.delete_menu(arg, menuw)
+ menuw.refresh()
+ return
#def enqueue_playlist(self, arg=None, menuw=None):
Modified: branches/rel-1/freevo/src/audio/plugins/mpd_status.py
==============================================================================
--- branches/rel-1/freevo/src/audio/plugins/mpd_status.py (original)
+++ branches/rel-1/freevo/src/audio/plugins/mpd_status.py Thu Jan 10
15:19:49 2008
@@ -24,7 +24,6 @@
# have status/everything update periodicly
# add a playlist browser
# code to handle when the mpd server is down
-# show the currently playing song in the status view
# -----------------------------------------------------------------------
# Freevo - A Home Theater PC framework
# Copyright (C) 2002 Krister Lagerstrom, et al.
@@ -71,7 +70,7 @@
__author_email__ = '[EMAIL PROTECTED]'
__maintainer__ = __author__
__maintainer_email__ = __author_email__
- __version__ = '$Revision$'
+ __version__ = '2'
def __init__(self):
@@ -82,7 +81,7 @@
plugin.MainMenuPlugin.__init__(self)
self.show_item = menu.MenuItem('MPD status', action=self.show_menu)
- self.show_item.type = 'audio'
+ #self.show_item.type = 'menu'
plugin.register(self, 'audio.MPD_status')
# connect to the server
self.conn = mpdclient2.Thread_MPD_Connection(config.MPD_SERVER_HOST,
config.MPD_SERVER_PORT, True,
@@ -252,10 +251,13 @@
def mpd_status(self, arg=None, menuw=None):
"""bring up a dialog showing mpd's current status"""
stat = self.conn.status()
+ track = self.conn.currentsong()
text = "status: %s\n" %(stat['state'])
if (stat['state'] != 'stop'):
- # how do i get the song name?
+ text += "title: %s\n" %(track['title'])
+ text += "album: %s\n" %(track['album'])
+ text += "artist: %s\n" %(track['artist'])
text += "track: %s\\%s\n" %(int(stat['song']) + 1,
stat['playlistlength'])
text += "time: %s\n" %(stat['time'])
if (stat['repeat'] == '1'):
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog