Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
std::map<std::string,std::string> query_pt4::support() const
{
  quvi_setopt(_quvi, QUVIOPT_CATEGORY, QUVIPROTO_HTTP);

  std::map<std::string,std::string> r;
  char *a, *b;

  while (quvi_next_supported_website(_quvi, &a, &b) == QUVI_OK)
    {
      r[a] = b;
      quvi_free(a);
      quvi_free(b);
    }
  return r;
}
Ejemplo n.º 3
0
static gint _cleanup(const gint r)
{
  sigwinch_reset(&sao);
  linput_free(&linput);
  quvi_free(q);
  return (r);
}
Ejemplo n.º 4
0
static void test_scan_userdata()
{
  static const gchar URL[] = "http://is.gd/yUeWit";

  struct user_data_s u;
  quvi_scan_t qs;
  quvi_t q;

  if (chk_internet() == FALSE || chk_skip(__func__) == TRUE)
    return;

  q = new_q();
  u.n = 0;

  quvi_set(q, QUVI_OPTION_CALLBACK_STATUS, (quvi_callback_status) status_cb);
  quvi_set(q, QUVI_OPTION_CALLBACK_STATUS_USERDATA, &u);

  g_assert_cmpint(u.n, ==, 0);
  qs = quvi_scan_new(q, URL);
  g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
  g_assert(qs != NULL);

  quvi_scan_free(qs);
  quvi_free(q);

  g_assert_cmpint(u.n, >, 0);
}
Ejemplo n.º 5
0
static gboolean
supports_uri (const char *uri)
{
	quvi_t q;
	QuviBoolean r;

	q = quvi_new ();
	r = quvi_supports (q, uri, QUVI_SUPPORTS_MODE_OFFLINE, QUVI_SUPPORTS_TYPE_ANY);
	quvi_free (q);

	return r;
}
Ejemplo n.º 6
0
std::string query_pt4::streams(const std::string& url,
                               const quvi::options& opts) const
{
  _configure(opts);

  char *fmts;

  const QUVIcode qc =
    quvi_query_formats(_quvi, const_cast<char*>(url.c_str()), &fmts);

  if (qc != QUVI_OK)
    throw error(_quvi, qc);

  std::string r = fmts;
  quvi_free(fmts);

  return r;
}
Ejemplo n.º 7
0
static void test_scan_noresults()
{
  static const gchar URL[] = "http://example.com/";

  quvi_scan_t qs;
  quvi_t q;

  if (chk_internet() == FALSE || chk_skip(__func__) == TRUE)
    return;

  q = new_q();

  qs = quvi_scan_new(q, URL);
  g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
  g_assert(qs != NULL);
  g_assert(quvi_scan_next_media_url(qs) == NULL);

  quvi_scan_free(qs);
  quvi_free(q);
}
Ejemplo n.º 8
0
static void test_scan_short()
{
  static const gchar URL[] = "http://is.gd/yUeWit";

  quvi_scan_t qs;
  quvi_t q;

  if (chk_internet() == FALSE || chk_skip(__func__) == TRUE)
    return;

  q = new_q();

  qs = quvi_scan_new(q, URL);
  g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
  g_assert(qs != NULL);
  chk_results(qs);

  quvi_scan_free(qs);
  quvi_free(q);
}
Ejemplo n.º 9
0
static void test_scan_core()
{
  static const gchar URL[] =
    "http://screenrant.com/superman-man-steel-trailer/";

  quvi_scan_t qs;
  quvi_t q;

  if (chk_internet() == FALSE || chk_skip(__func__) == TRUE)
    return;

  q = new_q();

  qs = quvi_scan_new(q, URL);
  g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
  g_assert(qs != NULL);
  chk_results(qs);

  quvi_scan_free(qs);
  quvi_free(q);
}
Ejemplo n.º 10
0
static void
parse_videosite (const char *uri)
{
	quvi_t q;
	quvi_media_t qm;
	/* properties */
	const char *video_uri;
	const char *title;
	const char *id;
	const char *content_type;
	const char *thumb_url;
	const char *container;
	double duration;
	double starttime;
	char *duration_str = NULL;
	char *starttime_str = NULL;

	if (!supports_uri (uri)) {
		g_print ("XPLAYER_PL_PARSER_RESULT_UNHANDLED");
		return;
	}

	q = quvi_new ();
	qm = quvi_media_new (q, uri);

	/* Empty results list? */
	if (quvi_media_stream_next(qm) != QUVI_TRUE) {
		if (debug)
			g_print ("Parsing '%s' failed with error: %s\n",
				 uri, quvi_errmsg (q));
		g_print ("XPLAYER_PL_PARSER_RESULT_ERROR");
		goto out;
	}

	/* Choose the best stream */
	quvi_media_stream_choose_best (qm);

	quvi_media_get (qm, QUVI_MEDIA_PROPERTY_TITLE, &title);
	quvi_media_get (qm, QUVI_MEDIA_PROPERTY_ID, &id);
	quvi_media_get (qm, QUVI_MEDIA_PROPERTY_THUMBNAIL_URL, &thumb_url);
	quvi_media_get (qm, QUVI_MEDIA_PROPERTY_DURATION_MS, &duration);
	if (duration)
		duration_str = g_strdup_printf ("%f", duration);
	quvi_media_get (qm, QUVI_MEDIA_STREAM_PROPERTY_URL, &video_uri);
	quvi_media_get (qm, QUVI_MEDIA_PROPERTY_START_TIME_MS, &starttime);
	if (starttime)
		starttime_str = g_strdup_printf ("%f", starttime);

	quvi_media_get (qm, QUVI_MEDIA_STREAM_PROPERTY_CONTAINER, &container);
	content_type = container_to_content_type (container);

	if (video_uri != NULL) {
		print (XPLAYER_PL_PARSER_FIELD_TITLE, title);
		print (XPLAYER_PL_PARSER_FIELD_ID, id);
		print (XPLAYER_PL_PARSER_FIELD_MOREINFO, uri);
		print (XPLAYER_PL_PARSER_FIELD_URI, video_uri);
		print (XPLAYER_PL_PARSER_FIELD_STARTTIME, starttime_str);
		print (XPLAYER_PL_PARSER_FIELD_CONTENT_TYPE, content_type);
		print (XPLAYER_PL_PARSER_FIELD_IMAGE_URI, thumb_url);
		print (XPLAYER_PL_PARSER_FIELD_DURATION, duration_str);
	}

	g_free (starttime_str);
	g_free (duration_str);

out:
	quvi_media_free (qm);
	quvi_free (q);
}