[mp3togo] amarok playlist grabbing

Justus Pendleton justus at ryoohki.net
Wed May 17 17:28:13 PDT 2006


Here's a quick first pass to add support for grabbing the current 
playlist from Amarok. It might make sense to introduce a new command 
line option along the lines of --from-player=amarok.

I also fixed two bugs with logging when modules (such as ID3) aren't found.
-------------- next part --------------
=== modified file 'mp3togo/conf.py'
--- mp3togo/conf.py	
+++ mp3togo/conf.py	
@@ -46,6 +46,12 @@
 	pass
 
 class ErrorXMMSNotRunning(Error):
+	pass
+
+class ErrorNoDCOP(Error):
+	pass
+
+class ErrorAmarokNotRunning(Error):
 	pass
 
 class ErrorUnlocked(Error):
@@ -89,6 +95,8 @@
  '''The playlist to convert. Playlists can be simple lists of file paths, one per line, or .m3u files or the native XMMS playlist file format.'''),
  ('readxmms', 'x', 'import-xmms', False, None, 
  '''Get playlist from running instance of XMMS. (You must have xmms-shell installed)'''),
+ ('readamarok', '', 'import-amarok', False, None,
+ '''Get playlist from running instance of Amarok.'''),
  ('playerdir', 'o', 'output-dir', os.curdir, self._playerdir, 
  '''Where to write the output files.'''),
  ('index', '', 'index', False, None, 
@@ -109,6 +117,7 @@
 		self.bin['metaflac'] = False
 		self.bin['normalize-audio'] = False
 		self.bin['xmms-shell'] = False
+		self.bin['dcop'] = False
 
 		self.version = mp3togo.version
 		self._help_preamble = """
@@ -138,7 +147,7 @@
 			except ImportError:
 				msg = "Third party module: " + name
 				msg += "is not available. Doing without"
-				log(1, "Third party module: %s is not available. Doing without")
+				self.log(1, "Third party module: %s is not available. Doing without")
 
 		# Go ahead and read in the data:
 		self.getconf(argv, conffile, readconf)

=== modified file 'mp3togo/filelist.py'
--- mp3togo/filelist.py	
+++ mp3togo/filelist.py	
@@ -20,6 +20,7 @@
 """Create a list of files for processing."""
 
 import mp3togo.conf as setup
+import tempfile
 
 if setup.THREADED == True:
 	import threading
@@ -108,6 +109,14 @@
 		# locks self in addfiles
 		self.addfiles(res, block)
 
+	def addAmarok(self, session=0, block=True):
+		m3u = tempfile.NamedTemporaryFile(suffix='.m3u', prefix='.', dir=os.getenv('HOME'))
+		# shouldn't hard code /usr/bin/dcop...should find it $PATH
+		exit_code = os.spawnl(os.P_WAIT, '/usr/bin/dcop', 'dcop', 'amarok', 'playlist', 'saveM3u', m3u.name, '0')
+		if exit_code != 0:
+			raise setup.ErrorAmarokNotRunning
+		self.addplaylist(m3u.name)
+
 	def removefile(self, name, block=True):
 		if not self._lock.acquire(block) and not block:
 			return False

=== modified file 'mp3togo/main.py'
--- mp3togo/main.py	
+++ mp3togo/main.py	
@@ -76,6 +76,9 @@
 
 	if opts['readxmms']:
 		playlist.addXMMS()
+
+	if opts['readamarok']:
+		playlist.addAmarok()
 
 	# Offer a hint
 	if len(playlist) == 0:

=== modified file 'mp3togo/options.py'
--- mp3togo/options.py	
+++ mp3togo/options.py	
@@ -325,8 +325,16 @@
 		# Don't lock
 		if level < 1:
 			raise Fail, "log() called with insufficiently high level."
-		if level <= self._d['verbosity']: 
+
+		# conf.py checks for various modules and calls log if they
+		# can't be found. except verbosity hasn't been set yet
+		# at that point. make sure the key exists before using it.
+		# if it doesn't exist print the message
+		if self._d.has_key('verbosity') and level <= self._d['verbosity']: 
 			print >>sys.stderr, msg
+		else
+			print >>sys.stderr, msg
+
 
 	def usage(self):
 		"""Returns a pretty printed usage message with the available



More information about the mp3togo mailing list