[vlc-commits] [Git][videolan/vlc][3.0.x] 2 commits: src/playlist: add sorting by file size logic
Felix Paul Kühne (@fkuehne)
gitlab at videolan.org
Sun Mar 8 15:47:02 UTC 2026
Felix Paul Kühne pushed to branch 3.0.x at VideoLAN / VLC
Commits:
d112b455 by unichronic at 2026-03-08T16:10:39+01:00
src/playlist: add sorting by file size logic
Add SORT_FILE_SIZE to the core playlist sorting functions.
File sizes are retrieved using vlc_stat and cached in the input item's extra info (category '.stat', name 'size') to improve performance on subsequent sorts.
- - - - -
b257bca8 by unichronic at 2026-03-08T16:10:39+01:00
macosx: map SORT_FILE_SIZE to macos playlist GUI
- - - - -
3 changed files:
- include/vlc_playlist.h
- modules/gui/macosx/VLCPLModel.m
- src/playlist/sort.c
Changes:
=====================================
include/vlc_playlist.h
=====================================
@@ -181,7 +181,8 @@ struct playlist_t
DEF( SORT_RATING )\
DEF( SORT_URI )\
DEF( SORT_DISC_NUMBER )\
- DEF( SORT_DATE )
+ DEF( SORT_DATE )\
+ DEF( SORT_FILE_SIZE )
#define DEF( s ) s,
enum
=====================================
modules/gui/macosx/VLCPLModel.m
=====================================
@@ -460,6 +460,8 @@ static int VolumeUpdated(vlc_object_t *p_this, const char *psz_var,
i_column = SORT_DESCRIPTION;
else if ([o_column isEqualToString:URI_COLUMN])
i_column = SORT_URI;
+ else if ([o_column isEqualToString:FILESIZE_COLUMN])
+ i_column = SORT_FILE_SIZE;
else
return;
=====================================
src/playlist/sort.c
=====================================
@@ -31,6 +31,9 @@
#define VLC_INTERNAL_PLAYLIST_SORT_FUNCTIONS
#include "vlc_playlist.h"
#include "playlist_internal.h"
+#include <vlc_url.h>
+#include <vlc_fs.h>
+#include <sys/stat.h>
/* General comparison functions */
@@ -347,6 +350,64 @@ SORTFN( SORT_URI, first, second )
return i_ret;
}
+
+SORTFN( SORT_FILE_SIZE, first, second )
+{
+ input_item_t *p_input1 = first->p_input;
+ input_item_t *p_input2 = second->p_input;
+ int64_t i_size1 = 0;
+ int64_t i_size2 = 0;
+ /* we get the file size from metadata. If not present (first time added to playlist) then we store it*/
+ char *psz_size1 = input_item_GetInfo( p_input1, ".stat", "size" );
+ if( psz_size1 && *psz_size1 )
+ {
+ i_size1 = atoll( psz_size1 );
+ free( psz_size1 );
+ }
+ else
+ {
+ free( psz_size1 );
+ char *psz_url = input_item_GetURI( p_input1 );
+ char *psz_path = psz_url ? vlc_uri2path( psz_url ) : NULL;
+ struct stat result;
+ if( psz_path && vlc_stat( psz_path, &result ) == 0 )
+ {
+ i_size1 = result.st_size;
+ input_item_AddInfo( p_input1, ".stat", "size", "%lld", (long long)i_size1 );
+ }
+ free( psz_path );
+ free( psz_url );
+ }
+
+ char *psz_size2 = input_item_GetInfo( p_input2, ".stat", "size" );
+ if( psz_size2 && *psz_size2 )
+ {
+ i_size2 = atoll( psz_size2 );
+ free( psz_size2 );
+ }
+ else
+ {
+ free( psz_size2 );
+ char *psz_url = input_item_GetURI( p_input2 );
+ char *psz_path = psz_url ? vlc_uri2path( psz_url ) : NULL;
+ struct stat result;
+ if( psz_path && vlc_stat( psz_path, &result ) == 0 )
+ {
+ i_size2 = result.st_size;
+ input_item_AddInfo( p_input2, ".stat", "size", "%lld", (long long)i_size2 );
+ }
+ free( psz_path );
+ free( psz_url );
+ }
+
+ if( i_size1 > i_size2 )
+ return 1;
+ else if( i_size1 < i_size2 )
+ return -1;
+ else
+ return 0;
+}
+
#undef SORTFN
/* Generate stubs around the proto_## sorting functions, ascending and
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/9df1f7724628b9127aaf8c243d0c903d6725ce96...b257bca870d069696e0bba351d11d7293aa568ac
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/9df1f7724628b9127aaf8c243d0c903d6725ce96...b257bca870d069696e0bba351d11d7293aa568ac
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list