Use input name in 'new playlist' and 'load playlist' if p.name == None.
[hooke.git] / hooke / plugin / playlists.py
index 8de9ec1f643323d5fa1fb555f9e1203dcbda2665..ccd5020ab09b8698a194d4423aac851730e77525 100644 (file)
@@ -23,8 +23,8 @@ lists of :class:`hooke.playlist.Playlist` classes.
 
 from ..command import Command, Argument, Failure
 from ..playlist import FilePlaylist
-from ..plugin import Builtin
-from .playlist import PlaylistNameArgument
+from . import Builtin
+from .playlist import PlaylistNameArgument, PlaylistAddingCommand
 
 
 class PlaylistsPlugin (Builtin):
@@ -100,14 +100,13 @@ class PlaylistListCommand (Command):
        outqueue.put(list(hooke.playlists))
 
 
-class NewCommand (Command):
+class NewCommand (PlaylistAddingCommand):
     """Create a new playlist.
     """
     def __init__(self, plugin):
         super(NewCommand, self).__init__(
             name='new playlist',
             arguments=[
-                PlaylistNameArgument,
                 Argument(name='file', type='file', optional=True,
                          help="""
 Default filename for future saves.
@@ -116,10 +115,11 @@ Default filename for future saves.
             help=self.__doc__, plugin=plugin)
 
     def _run(self, hooke, inqueue, outqueue, params):
-        print 'PP', params['name']
-        hooke.playlists.append(
-            FilePlaylist(
-                drivers=hooke.drivers,
-                name=params['name'],
-                path=params['file'],
-                ))
+        p = FilePlaylist(
+            drivers=hooke.drivers,
+            path=params['file'],
+            )
+        playlist_names = [playlist.name for playlist in hooke.playlists]
+        if p.name in playlist_names or p.name == None:
+            p.name = params['output playlist']  # HACK: override input name.  How to tell if it is callback-generated?
+        hooke.playlists.append(p)