Mpv: play all files in directory

Created on 24 Nov 2013  ·  16Comments  ·  Source: mpv-player/mpv

For example, in vlc you can call vlc subdir and it'll play all files in that directory

feature-request

Most helpful comment

Implemented in git master.

All 16 comments

If you are on linux or OSX, you can use run "mpv subdir/*", which will use bash expansion to play all the individual files in the directory.

I am aware, however what about subdirs of subdirs? In bash this will work if you turn on advanced globbing by doing mpv subdir/**/* (in zsh this will work automatically). This is just more keystrokes. I can easily type that, and this is just a suggestion. If it won't be implemented then that's fine, just wondering :)

I'm not sure if mpv should have such a feature.

What order should the files even be played? (The order as returned by the OS is essentially random.)

Well the actual code required for such a feature would be minimal, a simple directory transversal, checking for circular softlinks, adding each file to the playlist. As for ordering, I'd personally say add them in the order we get them, and maybe implement sorting functionality for the playlist.

Unless there are objections, I might write up some trial code for this. There aren't too many negatives to having the feature, and it won't add any complexity to the code itself. Implementing sorting for the playlist would be the harder matter, which personally I don't see as a requirement for this feature request.

Feel free to try it.

If this is done, it'd be nice if the sorting took into account things like 12, 13, 13.5, 14, ...
This kind of thing can happen if there's a recap episode, or an extra released separately that fits into the middle of a show.
Depending on the character following the number, these will usually end up sorted with e.g. 13.5 before 13, which would result in the episodes playing in the wrong order if mpv were to play the directory.

If this were implemented without any sorting at all, and just used the random order returned by the OS, I don't personally see it being very useful. I think you'd usually want a bunch of files in a directory to play in order (episodes of a show, tracks in an album).

That might be as simple as calling a qsort on the list.

12,13,13.5,14 is the natural ordering of that sequence (assuming they come at the end of the file name). If they don't it'll require some heuristic.

The numbers would not be at the end of the filename. There's the file extension, often a CRC, and sometimes other things. Or sometimes the files might be named starting with the number. So some heuristic would be required.

I'm already going to throw some playlist sorting into my code, just a quick qsort. If you have 13 and 13.5, these will be sorted fine. However, if you had 9, 10, this would _not_ be sorted correctly. Most series have 09, 10 though, so it shouldn't be an issue.

This seems to be related to something I opened a while back.

mpv-player/mpv#132

So, mpv itself has an internal playlist (a doubly linked list). Currently my code, if passed a directory on the command line, will explore it recursively, throwing everything onto the playlist. It then sorts the playlist using the filename string. I'll probably make it use a _new_ playlist, which I append to the current one, to handle specifying multiple directories/files on the command line correctly. I'll submit the code after I add some more error handling.

The feature referenced in #132, while similar, must use its own code. It would simply need to find the directory the current file is in, get a list of files, sort them, find where the old file is, and play the next entry. The problem with this is how it interacts with the current playlist (ie. should this only done for the last element, should it create a new playlist, should all the future elements be added). It does sound like a handy feature though, especially when launching from a file manager.

I still think #132 could probably be implemented as a lua script. It would just have to react to a new file being played, scan the directory, and add the next file(s) to the playlist. Of course this can't be done when trying to play a directory itself.

Also, I'm still unsure whether this feature is needed at all (over mpv dir/*), but let's see.

As mentioned earlier, the only advantage this code actually gives (over bash expansion) is exploring sub-directories. Whether that's good or not, I'm not sure.

So this is still an open issue in pull request #371. I'm closing _this_ issue, because we don't need two open issues for this.

Implemented in git master.

Too bad this doesn't use natural sorting for 1*, … , 9*, 10*.

Was this page helpful?
0 / 5 - 0 ratings