path: root/stream
diff options
authorwm4 <>2012-03-02 20:24:34 +0100
committerwm4 <>2012-07-28 22:05:34 +0200
commit7a06095dc3e5a3590f489aad3619dc6023a5b0f5 (patch)
tree961037d9f4542b5d42e30ab67b8766e1ea6cc464 /stream
parent42c3a300082f5dfbbd09818d149331ff45fd5892 (diff)
Add support for playing video from streaming sites with libquvi
This enables playing URLs from libquvi supported streaming sites directly, e.g. "mplayer" Anything opened with mplayer is checked with libquvi. If it looks like a URL of a supported streaming site, libquvi is used to extract the media URL, which is then passed to the lower level mplayer code instead of the HTML URL. Hopefully the libquvi URL checker works well enough that it doesn't cause any problems with normal URLs, files, or whatever else mplayer's stream layer accepts. Add the --libquvi-format option. the option value is directly passed to libquvi as requested format. The only values that seem to work for any streaming site seem to be "best" (best quality) and "default" (lowest quality). The mplayer option defaults to "best" (overriding libquvi's default). Outstanding issues: - Does libquvi checking every opened file really not cause problems? Should there be a runtime option to disable libquvi use? (Probably not an issue.) - Should we check/set the supported protocol? By default libquvi has support for all protocols enabled. In the worst case, it might return an URL using a protocol not supported by mplayer, even though it could extract URLs with other protocols too. (Probably not an issue.) - Somehow export metadata (like media title) to the mplayer frontend?
Diffstat (limited to 'stream')
1 files changed, 69 insertions, 2 deletions
diff --git a/stream/open.c b/stream/open.c
index ce0a415ceb..91e9ae2956 100644
--- a/stream/open.c
+++ b/stream/open.c
@@ -26,12 +26,14 @@
#include "config.h"
#include "mp_msg.h"
+#include "talloc.h"
#ifdef __FreeBSD__
#include <sys/cdrio.h>
#include "m_option.h"
+#include "options.h"
#include "stream.h"
#include "libmpdemux/demuxer.h"
@@ -42,6 +44,62 @@ char* cdrom_device=NULL;
char* dvd_device=NULL;
int dvd_title=0;
+#include <quvi/quvi.h>
+static const char *resolve_quvi(const char *url, struct MPOpts *opts)
+ char *media_title, *media_url;
+ quvi_media_t m;
+ 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");
+ 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;
+ }
+ quvi_getprop(m, QUVIPROP_PAGETITLE, &media_title);
+ quvi_getprop(m, QUVIPROP_MEDIAURL, &media_url);
+ mp_msg(MSGT_OPEN, MSGL_INFO, "[quvi] Site media title: '%s'\n",
+ media_title);
+ media_url = talloc_strdup(NULL, media_url);
+ quvi_parse_close(&m);
+ quvi_close(&q);
+ return media_url;
// Open a new stream (stdin/file/vcd/url)
stream_t* open_stream(const char *filename, struct MPOpts *options,
@@ -59,7 +117,16 @@ if(!filename) {
return NULL;
-//============ Open STDIN or plain FILE ============
+ const char *resolved = NULL;
+ resolved = resolve_quvi(filename, options);
+ if (resolved)
+ filename = resolved;
- return open_stream_full(filename,STREAM_READ,options,file_format);
+ stream_t *res = open_stream_full(filename,STREAM_READ,options,file_format);
+ talloc_free((void *)resolved);
+ return res;