0

I try to create a mpv playlist with 5 most recent movies in a specific folder - add to playlist (creation date).

Not successful ❌ was those commands:

mpv --playlist | ls -lrt1 /home/Georgette/Downloads/Bridgerton | tail -n 5
mpv --playlist=$(ls -lrt1 /home/Georgette/Downloads/Bridgerton | tail -n 5)

Update after comment (thanks!): mpv $(ls -lrt1 /home/Georgette/Downloads/Bridgerton | tail -n5) is working but has problems with spaces and other stuff in filenames: [file] Cannot open file 'zzz': No such file or directory. So there is still a quoting problem.

Sybil
  • 1,823
  • 5
  • 20
  • 41
  • 1
    The manpage states, the --playlist command expects an existing playlist file. Have you tried just passing the list of files (the second variant without --playlist)? The first command does not make any sense by the way. – Hermann Feb 04 '23 at 11:23

1 Answers1

1

The mpv manpage states, the --playlist command expects an existing playlist file. You can still make mpv play a list of files by passing them on the command line.

Your files seem to have spaces in them – which can lead to unexpected behaviour and is exactly the reason Why *not* parse `ls` (and what to do instead)? or similar discussions.

You can still try with something like this:

cd /home/Georgette/Downloads/Bridgerton 
IFS=$'\n' ; mpv $(ls -rt1 . | tail -n 5)

Setting IFS will tell your shell to treat each line of the ls output as a file name (opposed to each word). Please also note I removed the long listing from the call to ls since that adds meta-information to the output. You only want the filenames.

Note: While mpv is playing, you can use > and < to jump from one file to the next or previous.

Hermann
  • 6,148