summaryrefslogtreecommitdiffstats
path: root/quvi.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-10-13 17:09:35 +0200
committerwm4 <wm4@nowhere>2012-10-14 22:26:41 +0200
commita19f197cb14a0ceec4bc1fe977502b8f8ab8f94e (patch)
treeb4de459e097301d352b6a46e5086c51dfd682231 /quvi.c
parent9dfcd3e9a24a2d88578909233e2db24863f27b89 (diff)
downloadmpv-a19f197cb14a0ceec4bc1fe977502b8f8ab8f94e.tar.bz2
mpv-a19f197cb14a0ceec4bc1fe977502b8f8ab8f94e.tar.xz
core: show quvi page title in window title, clean up libquvi handling
Clean up handling of libquvi (which resolves URLs of streaming sites into URLs to the actual media playable by mpv). Move the code out of open.c to quvi.c, and invoke it explicitly from mplayer.c, instead of trying to resolve every filename passed to open_stream(). This allows easily passing metadata from the quvi context to the frontend. Expose QUVIPROP_PAGETITLE as "media-title" property, and use that instead of "filename" for the mplayer window title. (For YouTube, this is the video title.) It's cleaner too. Handle a potential reliability issue: check quvi_getprop return values. Since open.c contains barely anything but the open_stream() stub, move that to stream.c and delete open.c.
Diffstat (limited to 'quvi.c')
-rw-r--r--quvi.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/quvi.c b/quvi.c
new file mode 100644
index 0000000000..7be5f39bea
--- /dev/null
+++ b/quvi.c
@@ -0,0 +1,83 @@
+/*
+ * This file is part of mpv.
+ *
+ * mpv is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * mpv is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with mpv; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <quvi/quvi.h>
+
+#include "talloc.h"
+#include "mp_msg.h"
+#include "options.h"
+#include "mplayer.h"
+
+struct mp_resolve_result *mp_resolve_quvi(const char *url, struct MPOpts *opts)
+{
+ QUVIcode rc;
+
+ quvi_t q;
+ rc = quvi_init(&q);
+ if (rc != QUVI_OK)
+ return NULL;
+
+ // Don't try to use quvi on an URL that's not directly supported, since
+ // quvi will do a network access anyway in order to check for HTTP
+ // redirections etc.
+ // The documentation says this will fail on "shortened" URLs.
+ if (quvi_supported(q, (char *)url) != QUVI_OK) {
+ quvi_close(&q);
+ return NULL;
+ }
+
+ mp_msg(MSGT_OPEN, MSGL_INFO, "[quvi] Checking URL...\n");
+
+ // Can use quvi_query_formats() to get a list of formats like this:
+ // "fmt05_240p|fmt18_360p|fmt34_360p|fmt35_480p|fmt43_360p|fmt44_480p"
+ // (This example is youtube specific.)
+ // That call requires an extra net access. quvi_next_media_url() doesn't
+ // seem to do anything useful. So we can't really do anything useful
+ // except pass through the user's format setting.
+ quvi_setopt(q, QUVIOPT_FORMAT, opts->quvi_format
+ ? opts->quvi_format : "best");
+
+ quvi_media_t m;
+ rc = quvi_parse(q, (char *)url, &m);
+ if (rc != QUVI_OK) {
+ mp_msg(MSGT_OPEN, MSGL_ERR, "[quvi] %s\n", quvi_strerror(q, rc));
+ quvi_close(&q);
+ return NULL;
+ }
+
+ struct mp_resolve_result *result
+ = talloc_zero(NULL, struct mp_resolve_result);
+
+ char *val;
+
+ if (quvi_getprop(m, QUVIPROP_MEDIAURL, &val) == QUVI_OK)
+ result->url = talloc_strdup(result, val);
+
+ if (quvi_getprop(m, QUVIPROP_PAGETITLE, &val) == QUVI_OK)
+ result->title = talloc_strdup(result, val);
+
+ quvi_parse_close(&m);
+ quvi_close(&q);
+
+ if (!result->url) {
+ talloc_free(result);
+ result = NULL;
+ }
+
+ return result;
+}