smplayer-dev / smplayer

Free Media Player for Windows, Linux and Mac OS with YouTube support.
https://smplayer.info
GNU General Public License v2.0
621 stars 90 forks source link

Sort video names in playlist using natural (Windows) sorting #313

Open ElektroStudios opened 2 years ago

ElektroStudios commented 2 years ago

Is your feature request related to a problem? Please describe. I'm always frustrated when I see the videos in the playlist are sorted in alphabetical sort. This frustrates me because is very different from Windows O.S. default sort order (Natural sort order).

Describe the solution you'd like Implement the Natural sort order as the default sort algorithm for playlists. Just because it is more precise to visualize sorted files (see the screenshot below), and because of habits when using almost all programs for Windows users.

Info: Natural sort order - Wikipedia

Describe alternatives you've considered Or add the chance to let the end-user select what ordering they prefer, between Natural sort or Alphabetical sort via an option in the SMPlayer program options.

Additional context Example. Left is natural sort order (Windows O.S. default sort order), right is the usual sort, i.e. lexicographical order (SMPlayer default sort order):

jimmy-1000 commented 2 years ago

MPC-HC had this problem too. And not only players, when I create bath files using Windows command line interface, this CLI order the elements this way.

ElektroStudios commented 2 years ago

MPC-HC had this problem too.

The fact that in MPC-HC there is the same problem according to your comment, it is probably because many developers simply do not come up with the idea of ordering things in this way.

And not only players, when I create bath files using Windows command line interface, this CLI order the elements this way.

It is because, by default, the built-in string sort algorithm of programming languages is the alphabetic sort order (at least the languages that I know). Even those from Microsoft like C#, VB.NET, PowerShell and Batch, for example. Therefore, the decision to switch to Natural sort order is responsibility of the programmer, as many other things in software development that are not optimized by default for the best usage and view of the end-user...

Batch has no built-in way to use Natural sort order because it just includes (less than)the basic functionalities of a scripting language, and for this it is not considered a programming language at all (anyways it can be done , there are examples on StackOverflow.com), but any major programming language has the ability to use Natural sort order, and without the need to implement the algorithm, just by calling the native 'StrCmpLogicalW' function from Windows API.

ElektroStudios commented 2 years ago

Hi, dev. Can you say if you are considering to implement this?... it is a basic and necessary feature...

The default ordering is not the proper one for sorting movie files and tv show episodes...

This could be solved by using natural sort order.

smplayer-dev commented 2 years ago

I'll try to take a look at it, but I think this is not as simple as it may seem.

ElektroStudios commented 2 years ago

I'll try to take a look at it, but I think this is not as simple as it may seem.

Thanks a lot.

I don't know anything about C/C++, but maybe this can help you:

Also I found that in theory it can be done with some Qt class:

And by last I found this code developed in PHP that implements three sort algorithms (being AvalancheSort.php a variant of Natural sort ordering) and per the answer and code example in StackOverflow it seems that this PHP class could be used in C/C++ although I don't know exactly how to...

In that StackOverflow thread you will find other possible solutions for C/C++ like for example this Composable natural sort.

Well, and this one that mixes C classes with Ruby and Javascript and I don't know if these mixed things can have a real utility for your source-code:

I think at least the first purely C/C++ implementation, or the second named Composable natural sort, or the alternative of using the QCollator class could do the trick for you.

PS: As I said I don't know about C/C++, but I thought it might help to look up these sources for you.

Thanks for read.

ElektroStudios commented 1 month ago

Bad default sorting:

WinSnap 01

Good (Natural) sorting:

WinSnap 02

It really is an annoying problem that drives me crazy, requiring the need to reorder the playlist all the time, because it does not sort as expected file names with numbers, file names with upper/lower case differences and file names with diacritics.