1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
/*
Copyright (C) 2010 Bastien Nocera <hadess@hadess.net>
The Gnome Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the Gnome Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA.
Author: Bastien Nocera <hadess@hadess.net>
*/
#include "config.h"
#include <string.h>
#include <glib.h>
#ifndef TOTEM_PL_PARSER_MINI
#include "totem-disc.h"
#endif /* !TOTEM_PL_PARSER_MINI */
#ifdef HAVE_QUVI
#include <quvi/quvi.h>
#endif /* HAVE_QUVI */
#include "totem-pl-parser-mini.h"
#include "totem-pl-parser-videosite.h"
#include "totem-pl-parser-private.h"
gboolean
totem_pl_parser_is_videosite (const char *uri, gboolean debug)
{
#ifdef HAVE_QUVI
quvi_t handle;
QUVIcode rc;
if (quvi_init (&handle) != QUVI_OK)
return FALSE;
rc = quvi_supported(handle, (char *) uri);
quvi_close (&handle);
if (debug)
g_print ("Checking videosite for URI '%s' returned %d (%s)\n",
uri, rc, (rc == QUVI_OK) ? "true" : "false");
return (rc == QUVI_OK);
#else
return FALSE;
#endif /* HAVE_QUVI */
}
#ifndef TOTEM_PL_PARSER_MINI
#define getprop(prop, p) \
if (quvi_getprop (v, prop, &p) != QUVI_OK) \
p = NULL;
TotemPlParserResult
totem_pl_parser_add_videosite (TotemPlParser *parser,
GFile *file,
GFile *base_file,
TotemPlParseData *parse_data,
gpointer data)
{
#ifdef HAVE_QUVI
QUVIcode rc;
quvi_t handle;
quvi_media_t v;
char *uri;
/* properties */
const char *video_uri;
double length;
char *length_str;
const char *title;
const char *id;
const char *page_uri;
const char *starttime;
const char *content_type;
const char *thumb_url;
double duration;
char *duration_str;
if (quvi_init (&handle) != QUVI_OK)
return TOTEM_PL_PARSER_RESULT_ERROR;
quvi_setopt(handle, QUVIOPT_NOVERIFY, TRUE);
quvi_setopt(handle, QUVIOPT_FORMAT, "best");
uri = g_file_get_uri (file);
rc = quvi_parse(handle, uri, &v);
if (rc != QUVI_OK) {
if (totem_pl_parser_is_debugging_enabled (parser))
g_print ("quvi_parse for '%s' returned %d\n", uri, rc);
g_free (uri);
quvi_close (&handle);
if (rc == QUVI_NOSUPPORT)
return TOTEM_PL_PARSER_RESULT_UNHANDLED;
return TOTEM_PL_PARSER_RESULT_ERROR;
}
getprop (QUVIPROP_MEDIAURL, video_uri);
if (quvi_getprop (v, QUVIPROP_MEDIACONTENTLENGTH, &length) == QUVI_OK && length)
length_str = g_strdup_printf ("%f", length);
else
length_str = NULL;
getprop (QUVIPROP_PAGETITLE, title);
getprop (QUVIPROP_MEDIAID, id);
getprop (QUVIPROP_PAGEURL, page_uri);
getprop (QUVIPROP_STARTTIME, starttime);
getprop (QUVIPROP_MEDIACONTENTTYPE, content_type);
getprop (QUVIPROP_MEDIATHUMBNAILURL, thumb_url);
if (quvi_getprop (v, QUVIPROP_MEDIADURATION, &duration) == QUVI_OK && duration)
duration_str = g_strdup_printf ("%f", duration);
else
duration_str = NULL;
if (video_uri != NULL)
totem_pl_parser_add_uri (parser,
TOTEM_PL_PARSER_FIELD_TITLE, title,
TOTEM_PL_PARSER_FIELD_ID, id,
TOTEM_PL_PARSER_FIELD_MOREINFO, page_uri,
TOTEM_PL_PARSER_FIELD_URI, video_uri,
TOTEM_PL_PARSER_FIELD_FILESIZE, length_str,
TOTEM_PL_PARSER_FIELD_STARTTIME, starttime,
TOTEM_PL_PARSER_FIELD_CONTENT_TYPE, content_type,
TOTEM_PL_PARSER_FIELD_IMAGE_URI, thumb_url,
TOTEM_PL_PARSER_FIELD_DURATION, duration_str,
NULL);
g_free (uri);
g_free (length_str);
g_free (duration_str);
quvi_parse_close (&v);
quvi_close (&handle);
return TOTEM_PL_PARSER_RESULT_SUCCESS;
#else
return TOTEM_PL_PARSER_RESULT_UNHANDLED;
#endif /* !HAVE_QUVI */
}
#endif /* !TOTEM_PL_PARSER_MINI */
|