-
Notifications
You must be signed in to change notification settings - Fork 3k
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: select from the watch history with g-h #15655
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
add `--save-watch-history` and `--watch-history-path` options |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
#include <stdbool.h> | ||
#include <inttypes.h> | ||
#include <assert.h> | ||
#include <time.h> | ||
|
||
#include <libavutil/avutil.h> | ||
|
||
|
@@ -44,6 +45,7 @@ | |
#include "common/encode.h" | ||
#include "common/stats.h" | ||
#include "input/input.h" | ||
#include "misc/json.h" | ||
kasper93 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#include "misc/language.h" | ||
|
||
#include "audio/out/ao.h" | ||
|
@@ -1521,6 +1523,64 @@ static void load_external_opts(struct MPContext *mpctx) | |
mp_waiter_wait(&wait); | ||
} | ||
|
||
static void append_to_watch_history(struct MPContext *mpctx) | ||
{ | ||
if (!mpctx->opts->save_watch_history) | ||
return; | ||
|
||
void *ctx = talloc_new(NULL); | ||
char *history_path = mp_get_user_path(ctx, mpctx->global, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be null when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So what happens it saves history in cwd? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep. |
||
mpctx->opts->watch_history_path); | ||
FILE *history_file = fopen(history_path, "ab"); | ||
|
||
if (!history_file) { | ||
MP_ERR(mpctx, "Failed to write to %s: %s\n", history_path, | ||
mp_strerror(errno)); | ||
goto done; | ||
} | ||
|
||
char *title = (char *)find_non_filename_media_title(mpctx); | ||
|
||
mpv_node_list *list = talloc_zero(ctx, mpv_node_list); | ||
mpv_node node = { | ||
.format = MPV_FORMAT_NODE_MAP, | ||
.u.list = list, | ||
}; | ||
list->num = title ? 3 : 2; | ||
list->keys = talloc_array(ctx, char*, list->num); | ||
list->values = talloc_array(ctx, mpv_node, list->num); | ||
list->keys[0] = "time"; | ||
list->values[0] = (struct mpv_node) { | ||
.format = MPV_FORMAT_INT64, | ||
.u.int64 = time(NULL), | ||
}; | ||
list->keys[1] = "path"; | ||
list->values[1] = (struct mpv_node) { | ||
.format = MPV_FORMAT_STRING, | ||
.u.string = mp_normalize_path(ctx, mpctx->filename), | ||
}; | ||
if (title) { | ||
list->keys[2] = "title"; | ||
list->values[2] = (struct mpv_node) { | ||
.format = MPV_FORMAT_STRING, | ||
.u.string = title, | ||
}; | ||
} | ||
|
||
char *dst = talloc_strdup(ctx, ""); | ||
json_write(&dst, &node); | ||
dst = talloc_strdup_append(dst, "\n"); | ||
|
||
bool failed = fwrite(dst, strlen(dst), 1, history_file) != 1; | ||
if (fclose(history_file) || failed) { | ||
MP_ERR(mpctx, "Failed to write to %s: %s\n", history_path, | ||
mp_strerror(errno)); | ||
} | ||
|
||
done: | ||
talloc_free(ctx); | ||
} | ||
|
||
// Start playing the current playlist entry. | ||
// Handle initialization and deinitialization. | ||
static void play_current_file(struct MPContext *mpctx) | ||
|
@@ -1772,6 +1832,8 @@ static void play_current_file(struct MPContext *mpctx) | |
if (watch_later) | ||
mp_delete_watch_later_conf(mpctx, mpctx->filename); | ||
|
||
append_to_watch_history(mpctx); | ||
|
||
if (mpctx->max_frames == 0) { | ||
if (!mpctx->stop_play) | ||
mpctx->stop_play = PT_NEXT_ENTRY; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the file format should be documented.