Skip to content

Commit

Permalink
command: restore lang after track reload
Browse files Browse the repository at this point in the history
If a track's language was guessed from its filename, the commands that
reload the track, like sub-reload, remove it. Fix this by calling
guess_lang_from_filename() again.

Note that backing up t->lang and restoring it if nt->lang is NULL would
work incorrectly when lang is in the stream and it is removed before
reloading.
  • Loading branch information
guidocella authored and Dudemanguy committed Jan 20, 2024
1 parent 02c6165 commit 5871ba8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions player/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -5769,6 +5769,10 @@ static void cmd_track_reload(void *p)
}

struct track *nt = mpctx->tracks[nt_num];

if (!nt->lang)
nt->lang = mp_guess_lang_from_filename(nt, nt->external_filename);

mp_switch_track(mpctx, nt->type, nt, 0);
print_track_list(mpctx, "Reloaded:");
}
Expand Down
8 changes: 8 additions & 0 deletions player/external_files.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ static struct bstr guess_lang_from_filename(struct bstr name, int *fn_start)
return (struct bstr){name.start + i + 1, n};
}

char *mp_guess_lang_from_filename(void* ctx, const char *filename)
{
bstr filename_no_ext = bstr_strip_ext(bstr0(filename));
int start = 0; // only used in append_dir_subtitles()
char *lang = bstrto0(ctx, guess_lang_from_filename(filename_no_ext, &start));
return lang;
}

static void append_dir_subtitles(struct mpv_global *global, struct MPOpts *opts,
struct subfn **slist, int *nsub,
struct bstr path, const char *fname,
Expand Down
1 change: 1 addition & 0 deletions player/external_files.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ struct subfn *find_external_files(struct mpv_global *global, const char *fname,

bool mp_might_be_subtitle_file(const char *filename);
void mp_update_subtitle_exts(struct MPOpts *opts);
char *mp_guess_lang_from_filename(void *talloc_ctx, const char *filename);

#endif /* MPLAYER_FINDFILES_H */

0 comments on commit 5871ba8

Please sign in to comment.