command: add playlist-order
I couldn't find an straightforward and performant way to manipulate the playlist (from Lua scripts).
On one hand, playlist-move based solutions work but can be very slow, on the other hand loadfile/loadlist solutions are faster but they create new playlist entries that lose original id, title, options and playlist-path.
playlist-order covers functionality of playlist-move and playlist-remove. It modifies playlist in one operation, so observers don't get flooded with thousands of intermediate property changes.
Download the artifacts for this pull request:
Haven't actually looked at the code or thought about this hard yet, but I think you probably want to call this playlist-reorder. I was very confused for a while there.
Haven't actually looked at the code or thought about this hard yet, but I think you probably want to call this
playlist-reorder. I was very confused for a while there.
Agree it's the terrible name. I thought it would reverse the playlist.
Renamed to playlist-reorder.
This looks pretty low-level and niche use-case. To use this, you already need to have playlist itself parsed to generate indices for mpv to use. Wouldn't it be more straightforward to use external script to parse and reorder the playlist itself and send it to mpv in expected order?
This looks pretty low-level and niche use-case.
I consider it to be on the same level as playlist-move, it just takes more indexes.
Wouldn't it be more straightforward to use external script to parse and reorder the playlist itself and send it to mpv in expected order?
To be honest, I try really hard but since I've read your question I couldn't get over my first thought: I visioned a wrapper script with full of limitations, lot's of headaches and hard distribution/reuse. I can of course make something like this, but I also have slightly different use cases that playlist-reorder could cover. For example, I have a tiny ncurses client that allows me to open playlist in $EDITOR. Today, if I would like to load this edited playlist, I couldn't find a clear winner among the commands. So the wisest thing I can probably say is that an external script that generates the initial file list and playlist-reorder intersects somewhat, but neither one covers fully the other one regarding their use.
I think it's more useful to make the playlist property writable instead. It would cover the functionality of this and much more.
Is loadlist memory://foo.mp4\nbar.mp4 not enough?
Apart from that it creates new entries, it can work. However it's currently extremely memory hungry and slow because it strdup()s memory://… on each entry (playlist_path).
Just curious if this could be made to save media-title instead of just filename for the playlist items. Currently use the CogentRedTester save-playlist.lua to be able to name the playlist before saving and then if it's all youtube urls to have it populate the media-titles run one of these two scripts. Now when clicking on one of them the playlist is populated with the media-title for the urls.
# run "/bin/bash" "-c" 'cd ~/.config/mpv/data/download/srtfixer; ./m3u_yt_titles.sh' ; show-text "Titles are being added to all yt .m3u playlists"#! [Playlist] > [m3u] > Add titles to all yt .m3u playlists
# run "/bin/bash" "-c" 'cd ~/.config/mpv/data/download/srtfixer; ./m3u_yt_titlesreverse.sh' ; show-text "Titles are being added in reverse to all yt .m3u playlists"#! [Playlist] > [m3u] > Add titles in reverse to all yt .m3u playlists
m3u_yt_titles.sh
cd ~/.config/mpv/playlists
[ ! -d titles ] && mkdir titles
for f in *.m3u
do yt-dlp --skip-download --flat-playlist --no-warnings -O "#EXTINF:,%(upload_date>%Y%m%d)s %(title)s %(duration>[%H:%M])s" -O webpage_url -a "$f" > titles/"$f"
done
dt=$( date +%Y_%m_%d_%H_%M_%S)
mkdir "$dt" && mv *.m3u "$dt"
m3u_yt_titlesreverse.sh
cd ~/.config/mpv/playlists
[ ! -d titles_reversed ] && mkdir titles_reversed
for f in *.m3u ; do cat "$f" | awk '{a[i++]=$0} END {for (j=i-1; j>=0;) print a[j--] }' > ${f%.*}.m3u8 ; done
for f in *.m3u8
do yt-dlp --skip-download --flat-playlist --no-warnings -O "#EXTINF:,%(upload_date>%Y%m%d)s %(title)s %(duration>[%H:%M])s %(uploader)s" -O webpage_url -a "$f" > titles_reversed/${f%.*}.m3u
done
dt=$( date +%Y_%m_%d_%H_%M_%S)
mkdir "$dt" && mv *.m3u *.m3u8 "$dt"
I'm closing it in favor of #14990. I like writable playlist approach much better and I use that as a daily driver, so I've become uninterested in this command. (I guess it has near-zero chance, but if you say this command is worth to add, I would be happy to continue working on it.)