Skip to content

Commit 6ff7544

Browse files
committed
player: add current-watch-history-path property
Will be used next commit.
1 parent 995f6ca commit 6ff7544

File tree

6 files changed

+31
-3
lines changed

6 files changed

+31
-3
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
change `--watch-history-path` to be unset by default
2+
use the `current-watch-history-path` property to get the path instead

DOCS/man/input.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3880,6 +3880,11 @@ Property list
38803880
The working directory of the mpv process. Can be useful for JSON IPC users,
38813881
because the command line player usually works with relative paths.
38823882

3883+
``current-watch-history-path``
3884+
The path in which the watch history file is stored. This will return the
3885+
value of ``--watch-history-path`` or the default path if
3886+
``--watch-history-path`` has not been set with tilde placeholders expanded.
3887+
38833888
``current-watch-later-dir``
38843889
The directory in which watch later config files are stored. This returns
38853890
``--watch-later-dir``, or the default directory if ``--watch-later-dir`` has

player/command.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3632,6 +3632,16 @@ static int mp_property_cwd(void *ctx, struct m_property *prop,
36323632
return M_PROPERTY_NOT_IMPLEMENTED;
36333633
}
36343634

3635+
static int mp_property_current_watch_history_path(void *ctx, struct m_property *prop,
3636+
int action, void *arg)
3637+
{
3638+
MPContext *mpctx = ctx;
3639+
char *path = mp_get_watch_history_path(NULL, mpctx);
3640+
int r = m_property_strdup_ro(action, arg, path);
3641+
talloc_free(path);
3642+
return r;
3643+
}
3644+
36353645
static int mp_property_current_watch_later_dir(void *ctx, struct m_property *prop,
36363646
int action, void *arg)
36373647
{
@@ -4519,6 +4529,7 @@ static const struct m_property mp_properties_base[] = {
45194529
{"ambient-light", mp_property_ambient_light},
45204530

45214531
{"working-directory", mp_property_cwd},
4532+
{"current-watch-history-path", mp_property_current_watch_history_path},
45224533
{"current-watch-later-dir", mp_property_current_watch_later_dir},
45234534

45244535
{"protocol-list", mp_property_protocols},

player/configfiles.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,17 @@ static bool copy_mtime(const char *f1, const char *f2)
197197
return true;
198198
}
199199

200+
char *mp_get_watch_history_path(void *talloc_ctx, struct MPContext *mpctx)
201+
{
202+
char *history_path = mpctx->opts->watch_history_path;
203+
if (history_path && history_path[0]) {
204+
history_path = talloc_strdup(talloc_ctx, history_path);
205+
} else {
206+
history_path = mp_find_user_file(talloc_ctx, mpctx->log, "state", "watch_history.jsonl");
207+
}
208+
return history_path;
209+
}
210+
200211
char *mp_get_playback_resume_dir(struct MPContext *mpctx)
201212
{
202213
char *wl_dir = mpctx->opts->watch_later_dir;

player/core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ void audio_start_ao(struct MPContext *mpctx);
513513
void mp_parse_cfgfiles(struct MPContext *mpctx);
514514
void mp_load_auto_profiles(struct MPContext *mpctx);
515515
bool mp_load_playback_resume(struct MPContext *mpctx, const char *file);
516+
char *mp_get_watch_history_path(void *talloc_ctx, struct MPContext *mpctx);
516517
char *mp_get_playback_resume_dir(struct MPContext *mpctx);
517518
void mp_write_watch_later_conf(struct MPContext *mpctx);
518519
void mp_delete_watch_later_conf(struct MPContext *mpctx, const char *file);

player/loadfile.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,9 +1545,7 @@ static void append_to_watch_history(struct MPContext *mpctx)
15451545
return;
15461546

15471547
void *ctx = talloc_new(NULL);
1548-
char *history_path = mpctx->opts->watch_history_path;
1549-
if (!history_path || !history_path[0])
1550-
history_path = mp_find_user_file(ctx, mpctx->log, "state", "watch_history.jsonl");
1548+
char *history_path = mp_get_watch_history_path(NULL, mpctx);
15511549
char *history_path_dir = bstrto0(ctx, mp_dirname(history_path));
15521550
mp_mkdirp(history_path_dir);
15531551

0 commit comments

Comments
 (0)