mirror of
https://github.com/mpv-player/mpv
synced 2025-02-03 05:31:34 +00:00
screenshot: add format specifiers to get file directory path
Useful if you want to put the screenshot into the same directory as the file that is being played.
This commit is contained in:
parent
3e6fdc94d6
commit
59c6fa2201
@ -1970,6 +1970,12 @@ OPTIONS
|
||||
Filename of the currently played video.
|
||||
``%F``
|
||||
Same as ``%f``, but strip the file extension, including the dot.
|
||||
``%x``
|
||||
Directory path of the currently played video. If the video is not on
|
||||
the filesystem (but e.g. ``http://``), this expand to an empty string.
|
||||
``%X{fallback}``
|
||||
Same as ``%x``, but if the video file is not on the filesystem, return
|
||||
the fallback string inside the ``{...}``.
|
||||
``%p``
|
||||
Current playback time, in the same format as used in the OSD. The
|
||||
result is a string of the form "HH:MM:SS". For example, if the video is
|
||||
|
@ -178,6 +178,27 @@ static char *create_fname(struct MPContext *mpctx, char *template,
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'x':
|
||||
case 'X': {
|
||||
char *fallback = "";
|
||||
if (fmt == 'X') {
|
||||
if (template[0] != '{')
|
||||
goto error_exit;
|
||||
char *end = strchr(template, '}');
|
||||
if (!end)
|
||||
goto error_exit;
|
||||
fallback = talloc_strndup(res, template + 1, end - template - 1);
|
||||
template = end + 1;
|
||||
}
|
||||
if (!mpctx->filename || mp_is_url(bstr0(mpctx->filename))) {
|
||||
res = talloc_strdup_append(res, fallback);
|
||||
} else {
|
||||
bstr dir = mp_dirname(mpctx->filename);
|
||||
if (!bstr_equals0(dir, "."))
|
||||
res = talloc_asprintf_append(res, "%.*s", BSTR_P(dir));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'p':
|
||||
case 'P': {
|
||||
char *t = mp_format_time(get_current_time(mpctx), fmt == 'P');
|
||||
|
Loading…
Reference in New Issue
Block a user