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

select.lua: strip filename from the display of external track titles #15942

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dyphire
Copy link
Contributor

@dyphire dyphire commented Feb 23, 2025

It doesn't make much sense to display them, streamline the display as much as possible and avoid excessively long external titles

Before:
image
After:
image

@kasper93
Copy link
Contributor

kasper93 commented Feb 23, 2025

I wouldn't try to mimic external file selection logic from core. Instead I would just strip the common part of filename from the beginning of the external one. This way it will not show redundant long video file name part, but show all the remaining additional things like language (it's already there), but more importantly the the extension of the audio file. Imagine you have two files with the same language, .flac and .mka, after this change you won't be able to differentiate between them.

Copy link

github-actions bot commented Feb 23, 2025

Download the artifacts for this pull request:

Windows
macOS

@dyphire
Copy link
Contributor Author

dyphire commented Feb 23, 2025

I wouldn't try to mimic external file selection logic from core. Instead I would just strip the common part of filename from the beginning of the external one. This way it will not show redundant long video file name part, but show all the remaining additional things like language (it's already there), but more importantly the the extension of the audio file. Imagine you have two files with the same language, .flac and .mka, after this change you won't be able to differentiate between them.

Makes sense, keep the extension instead.

It doesn't make much sense to display them, streamline the display
as much as possible and avoid excessively long external titles
@guidocella
Copy link
Contributor

guidocella commented Feb 23, 2025

Should we change mp_add_external_file() itself to only set the extension as title so that show-text ${track-list} is also updated?

@llyyr
Copy link
Contributor

llyyr commented Feb 23, 2025

Actually, I'm not sure we want to strip the filename for all external tracks.

For audio streams sure, but for external subtitles, they may not necessary have all the proper metadata to identify which is which except the filename. see the following example:

image

I think the filename should always be there.

@dyphire
Copy link
Contributor Author

dyphire commented Feb 24, 2025

Actually, I'm not sure we want to strip the filename for all external tracks.

For audio streams sure, but for external subtitles, they may not necessary have all the proper metadata to identify which is which except the filename. see the following example:

image

I think the filename should always be there.

It is not necessary to display the video filename in an external track, which is redundant information. For subtitles, the necessary information is language identification and codec. In your screenshot, the external subtitles have shown the necessary information: extensions and additional Information(may be language suffixes). And when the external track file does not contain the video filename, the filename will still be retained intact, which I think is enough.

@dyphire
Copy link
Contributor Author

dyphire commented Feb 24, 2025

Should we change mp_add_external_file() itself to only set the extension as title so that show-text ${track-list} is also updated?

I think it's too radical to keep the extensions only, and there's other useful information in the external track files besides the extension: possible language suffixes or additional Information. And when the external track name does not contain the video file name, it should be retained intact, for example: English.srt.

@mrfragger
Copy link

image

This works fine..not showing subtitle name just language after . and extension
filename.language.vtt

only thing I can't do like in uosc is navigate to another directory in select.lua. I keep all these subs in a subdir except the English one.

@kasper93
Copy link
Contributor

kasper93 commented Feb 24, 2025

How about we just strip the common part of the main filename from external track title?

diff --git a/player/loadfile.c b/player/loadfile.c
index af563f7464..0fa93d569a 100644
--- a/player/loadfile.c
+++ b/player/loadfile.c
@@ -903,7 +903,13 @@ int mp_add_external_file(struct MPContext *mpctx, char *filename,
         if (sh->title && sh->title[0]) {
             t->title = talloc_strdup(t, sh->title);
         } else {
-            t->title = talloc_strdup(t, mp_basename(disp_filename));
+            bstr parent_filename = {0};
+            if (mpctx->filename)
+                parent_filename = bstr_strip_ext(bstr0(mp_basename(mpctx->filename)));
+            bstr title = bstr0(mp_basename(disp_filename));
+            bstr_eatstart(&title, parent_filename);
+            bstr_eatstart(&title, bstr0("."));
+            t->title = bstrdup0(t, title);
         }
         t->external_filename = mp_normalize_user_path(t, mpctx->global, filename);
         t->no_default = sh->type != filter;

Or if we want to keep it simpler and just strip the common part

diff --git a/player/loadfile.c b/player/loadfile.c
index af563f7464..162d57190e 100644
--- a/player/loadfile.c
+++ b/player/loadfile.c
@@ -903,7 +903,13 @@ int mp_add_external_file(struct MPContext *mpctx, char *filename,
         if (sh->title && sh->title[0]) {
             t->title = talloc_strdup(t, sh->title);
         } else {
-            t->title = talloc_strdup(t, mp_basename(disp_filename));
+            char *title = mp_basename(disp_filename);
+            char *parent = mpctx->filename ? mp_basename(mpctx->filename) : NULL;
+            while (*title && *parent && *title == *parent) {
+                title++;
+                parent++;
+            }
+            t->title = talloc_strdup(t, title);
         }
         t->external_filename = mp_normalize_user_path(t, mpctx->global, filename);
         t->no_default = sh->type != filter;

@dyphire
Copy link
Contributor Author

dyphire commented Feb 24, 2025

How about we just strip the common part of the main filename from external track title?

diff --git a/player/loadfile.c b/player/loadfile.c
index af563f7464..0fa93d569a 100644
--- a/player/loadfile.c
+++ b/player/loadfile.c
@@ -903,7 +903,13 @@ int mp_add_external_file(struct MPContext *mpctx, char *filename,
         if (sh->title && sh->title[0]) {
             t->title = talloc_strdup(t, sh->title);
         } else {
-            t->title = talloc_strdup(t, mp_basename(disp_filename));
+            bstr parent_filename = {0};
+            if (mpctx->filename)
+                parent_filename = bstr_strip_ext(bstr0(mp_basename(mpctx->filename)));
+            bstr title = bstr0(mp_basename(disp_filename));
+            bstr_eatstart(&title, parent_filename);
+            bstr_eatstart(&title, bstr0("."));
+            t->title = bstrdup0(t, title);
         }
         t->external_filename = mp_normalize_user_path(t, mpctx->global, filename);
         t->no_default = sh->type != filter;

I prefer this implementation, another implementation will retain the . characters after the public part which will be a little weird.
This is much better way to directly optimize the title content in the track-list property, and it will replace the modifications in the select.lua script.

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

Successfully merging this pull request may close these issues.

5 participants