Example #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;
}
Example #2
0
/* Choose subtitle language from the available languages. */
gint lutil_choose_subtitle(const quvi_t q, const quvi_subtitle_t qsub,
                           const gchar *lang, const lutil_cb_printerr xperr,
                           quvi_subtitle_lang_t *l,
                           const gboolean fail_if_none)
{
  g_assert(xperr != NULL);
  g_assert(lang != NULL);
  g_assert(qsub != NULL);
  g_assert(q != NULL);

  *l = quvi_subtitle_select(qsub, lang);
  if (quvi_ok(q) == QUVI_FALSE)
    {
      xperr(_("libquvi: while selecting subtitle: %s"), quvi_errmsg(q));
      return (EXIT_FAILURE);
    }
  else
    {
      if (*l == NULL && fail_if_none == TRUE)
        {
          xperr(_("libquvi: failed to find any subtitles"));
          return (EXIT_FAILURE);
        }
      return (EXIT_SUCCESS);
    }
}
Example #3
0
static gint _copy_subtitle(const gchar *mfpath, const gchar *url,
                           lutil_cb_printerr xperr)
{
  quvi_subtitle_lang_t ql;
  quvi_subtitle_t qsub;
  gint r;

  if (opts.core.subtitle_language == NULL)
    return (EXIT_SUCCESS);

  qsub = quvi_subtitle_new(q, url);
  if (quvi_ok(q) == FALSE)
    {
      xperr(_("libquvi: while querying subtitles: %s"), quvi_errmsg(q));
      return (EXIT_FAILURE);
    }

  _dump_languages(qsub);

  r = lutil_choose_subtitle(q, qsub, opts.core.subtitle_language,
                            xperr, &ql, FALSE);
  if (r == EXIT_SUCCESS)
    {
      if (ql != NULL)
        {
          quvi_subtitle_export_t qse;

          qse = quvi_subtitle_export_new(ql, opts.core.subtitle_export_format);
          if (quvi_ok(q) == TRUE)
            r = _write_subtitle(ql, qse, mfpath, xperr);
          else
            xperr(_("libquvi: while exporting subtitle: %s"), quvi_errmsg(q));

          quvi_subtitle_export_free(qse);
        }
      else
        g_print(_("skip <transfer>: subtitle extraction\n"));
    }
  quvi_subtitle_free(qsub);

  return (r);
}
Example #4
0
/* 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);
}
Example #5
0
static glong _support(const lutil_check_support_t css, const gchar *url,
                      const QuviSupportsType type)
{
  glong qc;

  if (quvi_supports(css->q, url, css->mode, type) == QUVI_TRUE)
    return (QUVI_OK);

  qc = quvi_errcode(css->q);
  if (qc != QUVI_ERROR_NO_SUPPORT)
    {
      css->xperr(_("libquvi: while checking for support: %s"),
                 quvi_errmsg(css->q));
    }
  return (qc);
}
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);
}
Example #7
0
/* Test media properties. The 'e' parameter may be NULL, in which case
 * the test for exact values (e.g. title and ID) will be skipped. */
void qm_test(const gchar *func, const gchar *url,
             const qm_test_exact_t e, const qm_test_opts_t o)
{
  quvi_media_t qm;
  quvi_t q;

  if (chk_skip(func) == TRUE)
    return;

  q = quvi_new();
  g_assert(q != NULL);
  g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);

  chk_verbose(q);

  qm = quvi_media_new(q, url);
  g_test_message("errmsg=%s", quvi_errmsg(q));
  g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
  g_assert(qm != NULL);

  if (chk_complete())
    {
      gint c;

      g_test_message("TEST_LEVEL=complete");

      /* Exact values. */

      if (e != NULL)
        {
          if (e->title != NULL)
            qm_cmp_s(QUVI_MEDIA_PROPERTY_TITLE, e->title);

          if (e->id != NULL)
            qm_cmp_s(QUVI_MEDIA_PROPERTY_ID, e->id);
        }

      /* Thumbnail, expected, but check length only. */

      qm_chk_l(QUVI_MEDIA_PROPERTY_THUMBNAIL_URL);

      /* Optional. */

      if (o->gt0.duration_ms == TRUE)
        qm_chk_gt0(QUVI_MEDIA_PROPERTY_DURATION_MS);

      if (o->gt0.start_time_ms== TRUE)
        qm_chk_gt0(QUVI_MEDIA_PROPERTY_START_TIME_MS);

      /* Streams. */

      for (c=0; quvi_media_stream_next(qm) == QUVI_TRUE; ++c);
      g_assert_cmpint(c, >, 0);

      while (quvi_media_stream_next(qm) == QUVI_TRUE)
        {
          qm_chk_l(QUVI_MEDIA_STREAM_PROPERTY_URL);

          if (c >1) /* Must have a stream ID, when there are >1 streams. */
            qm_chk_l(QUVI_MEDIA_STREAM_PROPERTY_ID);

          /* Optional. */

          if (o->s_len_gt0.stream.container == TRUE)
            qm_chk_l(QUVI_MEDIA_STREAM_PROPERTY_CONTAINER);

          /* Optional: Video. */

          if (o->gt0.stream.video.bitrate_kbit_s == TRUE)
            qm_chk_gt0(QUVI_MEDIA_STREAM_PROPERTY_VIDEO_BITRATE_KBIT_S);

          if (o->gt0.stream.video.height == TRUE)
            qm_chk_gt0(QUVI_MEDIA_STREAM_PROPERTY_VIDEO_HEIGHT);

          if (o->gt0.stream.video.width == TRUE)
            qm_chk_gt0(QUVI_MEDIA_STREAM_PROPERTY_VIDEO_WIDTH);

          if (o->s_len_gt0.stream.video.encoding == TRUE)
            qm_chk_l(QUVI_MEDIA_STREAM_PROPERTY_VIDEO_ENCODING);

          /* Optional: Audio. */

          if (o->gt0.stream.audio.bitrate_kbit_s == TRUE)
            qm_chk_gt0(QUVI_MEDIA_STREAM_PROPERTY_AUDIO_BITRATE_KBIT_S);

          if (o->s_len_gt0.stream.audio.encoding == TRUE)
            qm_chk_l(QUVI_MEDIA_STREAM_PROPERTY_AUDIO_ENCODING);
        }
    }
  else
    {