mpv
mpv copied to clipboard
autoload.lua sorts movie series incorrectly
Important Information
Provide following Information:
- mpv version: mpv 0.33.0-177-gfd8c673cfc x64
- Windows Version: Windows 10 21H1 (19043.1052)
- Source of the mpv binary: https://sourceforge.net/projects/mpv-player-windows/files/
- If known which version of mpv introduced the problem: Unknown
- Possible screenshot or video of visual glitches: N/A
Reproduction steps
- Play movie file in folder of movie files named according to Plex conventions, i.e., "Movie Title (YYYY).mkv".
- Attempt to move between playlist items in a numbered film series, provided the first film in that series has no number.
Expected behavior
When playing a movie in a directory of movies, autoload.lua loads all movies into the playlist in the same alphabetical order as File Explorer, Total Command, zsh in WSL, etc.
Actual behavior
When playing a movie, autoload.lua loads most of the surrounding movies in the correct order, but breaks on movie series which are named according to Plex conventions. For example:
[autoload] Adding Pirates of the Caribbean 2 - Dead Man's Chest (2006).mkv
[autoload] Adding Pirates of the Caribbean 3 - At World's End (2007).mkv
[autoload] Adding Pirates of the Caribbean 4 - On Stranger Tides.mkv
[autoload] Adding Pirates of the Caribbean (2003).mkv
or
[autoload] Adding The Godfather 2 (1974).mkv
[autoload] Adding The Godfather 3 (1990).mkv
[autoload] Adding The Godfather (1972).mkv
This causes moving between files in the playlist to be unpredictable and annoying. The issue occurs no matter which video I play - first, last, or in-between - as it appears to be a matter of comparison matching between "(" and numbers. I know I could fix the issue by putting a "1" after the first movie in the series, but frankly, I'd rather not do that when everything else seems to sort the files just fine.
Log file
In addition, here is the console output from the folder in question. Yes, I know there are some garbage movies in there. Sue me.
Z:\rips\reduce\check-rip>mpv "Evangelion 1.11 - You Are (Not) Alone (2007).mkv"
[autoload] Adding Ghost in the Shell 2.0 (2008).mkv
[autoload] Adding Kingdom of Heaven (2005).mkv
[autoload] Adding Marvel's Thor (2011).mkv
[autoload] Adding Millennium 1 - The Girl With the Dragon Tattoo (2009).mkv
[autoload] Adding Millennium 1 - The Girl With the Dragon Tattoo [US] (2011).mkv
[autoload] Adding Millennium 2 - The Girl Who Played With Fire (2009).mkv
[autoload] Adding Millennium 3 - The Girl Who Kicked the Hornets' Nest (2009).mkv
[autoload] Adding No Country for Old Men (2007).mkv
[autoload] Adding Paprika (2006).mkv
[autoload] Adding Persepolis (2007).mkv
[autoload] Adding Pirates of the Caribbean 2 - Dead Man's Chest (2006).mkv
[autoload] Adding Pirates of the Caribbean 3 - At World's End (2007).mkv
[autoload] Adding Pirates of the Caribbean 4 - On Stranger Tides.mkv
[autoload] Adding Pirates of the Caribbean (2003).mkv
[autoload] Adding Rango (2011).mkv
[autoload] Adding Red Cliff 2 (2009).mkv
[autoload] Adding Red Cliff (2008).mkv
[autoload] Adding Regina Spektor - Live in London (2010).mkv
[autoload] Adding Regina Spektor - Live on Soundstage (2017).mkv
[autoload] Adding Riddick 1 - Pitch Black (2000).mkv
[autoload] Adding Riddick 3 - The Chronicles of Riddick (2004).mkv
[autoload] Adding Sherlock Holmes 2 - A Game of Shadows (2011).mkv
[autoload] Adding Sherlock Holmes (2009).mkv
[autoload] Adding Star Wars 7 - The Force Awakens (2015).mkv
[autoload] Adding The Book Thief (2013).mkv
[autoload] Adding The Godfather 2 (1974).mkv
[autoload] Adding The Godfather 3 (1990).mkv
[autoload] Adding The Godfather (1972).mkv
[autoload] Adding The King's Speech (2010).mkv
[autoload] Adding Underworld 2 - Evolution (2006).mkv
[autoload] Adding Underworld 3 - Rise of the Lycans (2009).mkv
[autoload] Adding Underworld 4 - Awakening (2012).mkv
[autoload] Adding Underworld (2003).mkv
[autoload] Adding X-Men 2 (2003).mkv
[autoload] Adding X-Men 3 - The Last Stand (2006).mkv
[autoload] Adding X-Men 4 - Origins Wolverine (2009).mkv
[autoload] Adding X-Men 5 - First Class (2011).mkv
[autoload] Adding X-Men 6 - The Wolverine (2013).mkv
[autoload] Adding X-Men 7 - Days of Future Past (2014).mkv
[autoload] Adding X-Men (2000).mkv
(+) Video --vid=1 (h264 1920x1080 23.976fps)
(+) Audio --aid=1 --alang=eng (*) 'Surround 6.1' (truehd 7ch 48000Hz)
Audio --aid=2 --alang=jpn 'Surround 6.1' (truehd 7ch 48000Hz)
Subs --sid=1 --slang=eng (hdmv_pgs_subtitle)
Subs --sid=2 --slang=eng (hdmv_pgs_subtitle)
File tags:
Title: Evangelion 1.11 You Are (Not) Alone
[dynamic_crop] File loaded.
AO: [wasapi] 48000Hz 6.1 7ch float
VO: [gpu] 1920x1080 yuv420p
AV: 00:00:03.504 / 01:41:07.644 (0%) A-V: 0.000
[dynamic_crop] Meta Stats:
Exiting... (Quit)
[dynamic_crop] Trusted Offset: X:0 Y:0
[dynamic_crop] w=1920:h=1080:x=0:y=0 | offX=0 offY=0 | applied=1 detected_total=1.502 last=1.21
[dynamic_crop] Cleanup.
File Explorer and mpv.net use:
https://docs.microsoft.com/en-us/windows/win32/api/shlwapi/nf-shlwapi-strcmplogicalw
I'm not doubting you, but I'm even more lost, in that case. If both programs use the same function for sorting, then why does mpv sort them differently than File Explorer or Total Commander? This Windows installation is barely a week old, and I use File Explorer so rarely - in favor of Total Commander - that I haven't messed with any of its settings, beyond enabling file extensions and hidden files. In theory, then, shouldn't autoload have the same playlist folder as a File Explorer listing?
but I'm even more lost
Because you don't understand what he said. mpv.net & File Explorer use the same solution. But autoload.lua not.
Source of the mpv binary: https://sourceforge.net/projects/mpv-player-windows/files/
mpv.net is not mpv, and I don't know what autoload.lua looks like in mpv.net.
EDIT - oops, I thought it's related to mpv.net but that URL is an mpv build by shinchiro. Sorry.
autoload.lua uses "natural sorting" using the alphanum algorithm, which splits each string into portions of text and numbers, and compares only text to text and numbers to numbers, however, I'm not sure how it does or should behave when only one of the compared strings has a number at the next place to compare.
Note that I didn't inspect the algorithm, so I don't know exactly what it does.
I can imagine one of few approaches to take on such case:
- I think the simplest approach is that if two strings are identical up to some point, and then one string has a number while the other continues without numbers, then the one without numbers is considered longer (because the number at the other string "stops" the text part of the string), and would show after the one with the number - I'm guessing this is how the algorithm behaves currently.
- Abort the alphanum algorithm and fallback to plain byte order for the rest of the string (i.e. stop treating numbers in a special way), at which case it would place
foo (beforefoo 1because the(code is smaller than that of1- just like OP wants it to be. However,xcode is bigger than1, so by this approachfoo 1would still end up beforefoo x- which I think is the oposite of what OP wants. - Decide arbitrarily (but consistently) that if two strings are identical up to some point, and then one string continues with text while the other continues with a number, then either numbers should come before non-numbers, or numbers should come after non-numbers. According to OP, this approach should make numbers come after non-numbers. However, I didn't think it through, and it's entirely possible that there are gotchas with this approach too. Also, it's possible that the alphanum algorithm takes this approach but decides that numbers should come before non-numbers.
Bottom line, suggestions/PRs are welcome, but preferably only of existing proven algorithms, with reasonably simple way to implement them in lua.
File Explorer and mpv.net use:
https://docs.microsoft.com/en-us/windows/win32/api/shlwapi/nf-shlwapi-strcmplogicalw
These docs mention: "Note Behavior of this function, and therefore the results it returns, can change from release to release..."
The algorithm itself is not explained, the example at these docs don't show cases where one string continues with text while the other continues with a number, and it can change.
I realized that we can use the approachs mentioned there of Alphanum sorting for humans in lua to achieve a more reasonable natural sorting, which is simpler than the existing approach.
This is also the approach that the script of playlistmanager.lua is using.
There is new development and a discussion here: https://github.com/tomasklaen/uosc/pull/798