From 5f664d78e6e9bd5809dc7d0f12c4099e76582cb3 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 27 Jun 2013 18:21:07 +0200 Subject: core: add libquvi 0.9 support This adds support for libquvi 0.9.x, and these features: - start time (part of youtube URL) - youtube subtitles - alternative source switching ('l' and 'L' keys) - youtube playlists Note that libquvi 0.9 is still in development. Although this seems to be API stable now, it looks like there will be a 1.0 release, which is supposed to be the next stable release and the actual successor of libquvi 0.4.x. --- core/command.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) (limited to 'core/command.c') diff --git a/core/command.c b/core/command.c index 11ee73ec57..0418e7a82c 100644 --- a/core/command.c +++ b/core/command.c @@ -24,6 +24,9 @@ #include #include +#include +#include + #include "config.h" #include "talloc.h" #include "command.h" @@ -67,7 +70,6 @@ #include "core/mp_core.h" #include "mp_fifo.h" -#include "libavutil/avstring.h" static void change_video_filters(MPContext *mpctx, const char *cmd, const char *arg); @@ -464,6 +466,65 @@ static int mp_property_edition(m_option_t *prop, int action, void *arg, return M_PROPERTY_NOT_IMPLEMENTED; } +static struct mp_resolve_src *find_source(struct mp_resolve_result *res, + char *url) +{ + if (res->num_srcs == 0) + return NULL; + + int src = 0; + for (int n = 0; n < res->num_srcs; n++) { + if (strcmp(res->srcs[n]->url, res->url) == 0) { + src = n; + break; + } + } + return res->srcs[src]; +} + +static int mp_property_quvi_format(m_option_t *prop, int action, void *arg, + MPContext *mpctx) +{ + struct mp_resolve_result *res = mpctx->resolve_result; + if (!res || !res->num_srcs) + return M_PROPERTY_UNAVAILABLE; + + struct mp_resolve_src *cur = find_source(res, res->url); + if (!cur) + return M_PROPERTY_UNAVAILABLE; + + switch (action) { + case M_PROPERTY_GET: + *(char **)arg = talloc_strdup(NULL, cur->encid); + return M_PROPERTY_OK; + case M_PROPERTY_SET: { + mpctx->stop_play = PT_RESTART; + break; + } + case M_PROPERTY_SWITCH: { + struct m_property_switch_arg *sarg = arg; + int pos = 0; + for (int n = 0; n < res->num_srcs; n++) { + if (res->srcs[n] == cur) { + pos = n; + break; + } + } + pos += sarg->inc; + if (pos < 0 || pos >= res->num_srcs) { + if (sarg->wrap) { + pos = (res->num_srcs + pos) % res->num_srcs; + } else { + pos = av_clip(pos, 0, res->num_srcs); + } + } + char *arg = res->srcs[pos]->encid; + return mp_property_quvi_format(prop, M_PROPERTY_SET, &arg, mpctx); + } + } + return mp_property_generic_option(prop, action, arg, mpctx); +} + /// Number of titles in file static int mp_property_titles(m_option_t *prop, int action, void *arg, MPContext *mpctx) @@ -1523,6 +1584,7 @@ static const m_option_t mp_properties[] = { { "chapter", mp_property_chapter, CONF_TYPE_INT, M_OPT_MIN, 0, 0, NULL }, M_OPTION_PROPERTY_CUSTOM("edition", mp_property_edition), + M_OPTION_PROPERTY_CUSTOM("quvi-format", mp_property_quvi_format), { "titles", mp_property_titles, CONF_TYPE_INT, 0, 0, 0, NULL }, { "chapters", mp_property_chapters, CONF_TYPE_INT, -- cgit v1.2.3