Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autoload.lua sorts movie series incorrectly #8969

Closed
FitzWM opened this issue Jun 27, 2021 · 7 comments · Fixed by #10779
Closed

autoload.lua sorts movie series incorrectly #8969

FitzWM opened this issue Jun 27, 2021 · 7 comments · Fixed by #10779
Labels

Comments

@FitzWM
Copy link

FitzWM commented Jun 27, 2021

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

  1. Play movie file in folder of movie files named according to Plex conventions, i.e., "Movie Title (YYYY).mkv".
  2. 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

mpv.log

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.
@FitzWM FitzWM added the os:win label Jun 27, 2021
@stax76
Copy link
Contributor

stax76 commented Jun 28, 2021

@FitzWM
Copy link
Author

FitzWM commented Jun 29, 2021

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?

@hooke007
Copy link
Contributor

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.

@avih
Copy link
Member

avih commented Jun 29, 2021

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 ( before foo 1 because the ( code is smaller than that of 1 - just like OP wants it to be. However, x code is bigger than 1, so by this approach foo 1 would still end up before foo 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.

@avih
Copy link
Member

avih commented Jun 29, 2021

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.

@dyphire
Copy link
Contributor

dyphire commented Oct 24, 2022

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.

dyphire added a commit to dyphire/mpv that referenced this issue Oct 24, 2022
Commits mpv-player@257dbdf uses a algorithm of splitting strings
into a table of number and string values to achieve natural sorting.
This approach works well in most cases, but it does not work well
in some specific scenarios.
Now let's implement natural sorting with a stronger algorithm.

Ref: jonniek/mpv-playlistmanager@3cf323f
Closes mpv-player#8969
dyphire added a commit to dyphire/mpv that referenced this issue Oct 24, 2022
Commits mpv-player@257dbdf uses a algorithm of splitting strings
into a table of number and string values to achieve natural sorting.
This approach works well in most cases, but it does not work well
in some specific scenarios.
Now let's implement natural sorting with a stronger algorithm.

Ref: jonniek/mpv-playlistmanager@3cf323f
Closes mpv-player#8969
dyphire added a commit to dyphire/mpv that referenced this issue Oct 24, 2022
Commits mpv-player@257dbdf uses a algorithm of splitting strings
into a table of number and string values to achieve natural sorting.
This approach works well in most cases, but it does not work well
in some specific scenarios.
Now let's implement natural sorting with a stronger algorithm.

Also fixes indentation.

Ref: jonniek/mpv-playlistmanager@3cf323f
Closes mpv-player#8969
dyphire added a commit to dyphire/mpv that referenced this issue Oct 24, 2022
Commits mpv-player@257dbdf uses a algorithm of splitting strings
into a table of number and string values to achieve natural sorting.
This approach works well in most cases, but it does not work well
in some specific scenarios.
Now let's implement natural sorting with a stronger algorithm.

Also fixes indentation.

Ref: jonniek/mpv-playlistmanager@3cf323f
Closes mpv-player#8969
Dudemanguy pushed a commit that referenced this issue Jan 9, 2023
Commits 257dbdf uses a algorithm of splitting strings
into a table of number and string values to achieve natural sorting.
This approach works well in most cases, but it does not work well
in some specific scenarios.
Now let's implement natural sorting with a stronger algorithm.

Also fixes indentation.

Ref: jonniek/mpv-playlistmanager@3cf323f
Closes #8969
dyphire added a commit to dyphire/mpv that referenced this issue Feb 22, 2023
Commits mpv-player@257dbdf uses a algorithm of splitting strings
into a table of number and string values to achieve natural sorting.
This approach works well in most cases, but it does not work well
in some specific scenarios.
Now let's implement natural sorting with a stronger algorithm.

Also fixes indentation.

Ref: jonniek/mpv-playlistmanager@3cf323f
Closes mpv-player#8969
dyphire added a commit to dyphire/mpv that referenced this issue Feb 22, 2023
Commits mpv-player@257dbdf uses a algorithm of splitting strings
into a table of number and string values to achieve natural sorting.
This approach works well in most cases, but it does not work well
in some specific scenarios.
Now let's implement natural sorting with a stronger algorithm.

Also fixes indentation.

Ref: jonniek/mpv-playlistmanager@3cf323f
Closes mpv-player#8969
@stax76
Copy link
Contributor

stax76 commented Nov 19, 2023

There is new development and a discussion here: tomasklaen/uosc#798

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants