ranger-cmus icon indicating copy to clipboard operation
ranger-cmus copied to clipboard

Feature: play a file/folder directly

Open agenbite opened this issue 4 years ago • 0 comments

Hi,

This small piece of software is just great. I've spent some time looking around and, wow, this is exactly it. Thank you so much for sharing.

Now, I said "exactly" but I feel there is a small improvement that could be added. When I browse my files/folders, I'd like to select one and play it right away. That is: no adding to a playlist, no adding to a queue: just play it.

As far as I can tell, the cli commands for such a thing would apparently be:

cmus-remote -c -q && cmus-remote -q [file/folder] && cmus-remote -n

This works for me.

Do you think a fourth command could be added to provide this functionality? There must be a cleaner way (never wrote in python before), but I guess something like this works for me:

class cmus_justplay(Command):
    def execute(self):
        """ Play selected files or folders """
        file_objs = get_files(self.fm)

        cmus1 = ["cmus-remote", "-c", "-q"]
        self.fm.execute_command(cmus1)
        cmus2 = ["cmus-remote", "-q"]
        cmus2.extend([f.path for f in file_objs])
        self.fm.execute_command(cmus2)
        cmus3 = ["cmus-remote", "-n", "-p"]
        self.fm.execute_command(cmus3)
        self.fm.notify("Cmus queue was cleared and files were sent to it.")
        self.fm.thisdir.mark_all(False)

I provisionally named it cmus_justplay because imho there would be a collision in names, since probably this new command deserves the name cmus_play, while the old cmus_play could be called cmus_playlist, or something like that.

What do you think?

EDIT: There are some corners to round up: if there's a song playing, the last command is -n, but if the player is stopped, we need -p. I don't know how to get around this atm. EDIT 2: Apparently, it's as easy as to use both flags simultaneously: -n -p.

agenbite avatar Nov 18 '21 13:11 agenbite