From 013e76e1c0e1bdfeee8ed644696d615cacf1cff7 Mon Sep 17 00:00:00 2001
From: sfan5 <sfan5@live.de>
Date: Sun, 1 Jun 2025 17:36:44 +0200
Subject: [PATCH] player: create missing folders for watch-history-path

fixes: #16357
---
 player/loadfile.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/player/loadfile.c b/player/loadfile.c
index 96c84bd458..04c10d92b4 100644
--- a/player/loadfile.c
+++ b/player/loadfile.c
@@ -1546,8 +1546,12 @@ static void append_to_watch_history(struct MPContext *mpctx)
     void *ctx = talloc_new(NULL);
     char *history_path = mp_get_user_path(ctx, mpctx->global,
                                           mpctx->opts->watch_history_path);
-    FILE *history_file = fopen(history_path, "ab");
+    char *history_path_dir = bstrto0(ctx, mp_dirname(history_path));
+    if (!mp_path_exists(history_path_dir)) {
+        mp_mkdirp(history_path_dir);
+    }
 
+    FILE *history_file = fopen(history_path, "ab");
     if (!history_file) {
         MP_ERR(mpctx, "Failed to open history file: %s\n",
                mp_strerror(errno));
-- 
2.51.0

