struct mp_resolve_result *mp_resolve_quvi(const char *url, struct MPOpts *opts) { quvi_t q = quvi_new(); if (quvi_ok(q) == QUVI_FALSE) 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_supports(q, (char *) url, QUVI_SUPPORTS_MODE_OFFLINE, QUVI_SUPPORTS_TYPE_ANY) == QUVI_FALSE) { quvi_free(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_media_t m = quvi_media_new(q, (char *) url); if (quvi_ok(q) == QUVI_FALSE) { mp_msg(MSGT_OPEN, MSGL_ERR, "[quvi] %s\n", quvi_errmsg(q)); quvi_free(q); return NULL; } quvi_media_stream_select(m, opts->quvi_format); if (quvi_ok(q) == QUVI_FALSE) { mp_msg(MSGT_OPEN, MSGL_ERR, "[quvi] %s\n", quvi_errmsg(q)); quvi_free(q); return NULL; } struct mp_resolve_result *result = talloc_zero(NULL, struct mp_resolve_result); char *val; quvi_media_get(m, QUVI_MEDIA_STREAM_PROPERTY_URL, &val); if (quvi_ok(q) == QUVI_TRUE) result->url = talloc_strdup(result, val); quvi_media_get(m, QUVI_MEDIA_PROPERTY_TITLE, &val); if (quvi_ok(q) == QUVI_TRUE) result->title = talloc_strdup(result, val); quvi_media_free(m); quvi_free(q); if (!result->url) { talloc_free(result); result = NULL; } return result; }
gint main(gint argc, gchar **argv) { gint i,r; gchar *s; g_assert(qm == NULL); g_assert(q == NULL); memset(&opts, 0, sizeof(struct _opts_s)); setlocale(LC_ALL, ""); r = opts_new(argc, argv); if (r != EXIT_SUCCESS) return (r); q = quvi_new(); examples_exit_if_error(); if (opts.autoproxy == TRUE) examples_enable_autoproxy(); if (opts.verbose == TRUE) examples_enable_verbose(); quvi_set(q, QUVI_OPTION_CALLBACK_STATUS, (qcs) examples_status); for (i=0; opts.url[i] != NULL; ++i) { qm = quvi_media_new(q, opts.url[i]); examples_exit_if_error(); quvi_media_get(qm, QUVI_MEDIA_PROPERTY_TITLE, &s); g_print("[%s]\n title='%s'\n", __func__, s); if (opts.best == TRUE) { quvi_media_stream_choose_best(qm); dump_stream(); } else if (opts.stream != NULL) { quvi_media_stream_select(qm, opts.stream); examples_exit_if_error(); dump_stream(); } else dump_streams(); quvi_media_free(qm); qm = NULL; } opts_free(); examples_cleanup(); g_assert(qm == NULL); g_assert(q == NULL); return (r); }
/* Choose a stream from the available streams. */ gint lutil_choose_stream(const quvi_t q, const quvi_media_t qm, const gchar *stream, const lutil_cb_printerr xperr) { g_assert(stream != NULL); g_assert(xperr != NULL); g_assert(qm != NULL); g_assert(q != NULL); quvi_media_stream_select(qm, stream); if (quvi_ok(q) == QUVI_FALSE) { xperr(_("libquvi: while selecting stream: %s"), quvi_errmsg(q)); return (EXIT_FAILURE); } return (EXIT_SUCCESS); }