2
Copyright (C) 2013 Bastien Nocera <hadess@hadess.net>
4
The Gnome Library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public License as
6
published by the Free Software Foundation; either version 2 of the
7
License, or (at your option) any later version.
9
The Gnome Library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Library General Public License for more details.
14
You should have received a copy of the GNU Library General Public
15
License along with the Gnome Library; see the file COPYING.LIB. If not,
16
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
Boston, MA 02110-1301 USA.
19
Author: Bastien Nocera <hadess@hadess.net>
28
#include "totem-pl-parser.h"
32
static char *url = NULL;
33
static gboolean check = FALSE;
34
static gboolean debug = FALSE;
36
const GOptionEntry options[] = {
37
{ "url", 'u', 0, G_OPTION_ARG_FILENAME, &url, "URL of the video site page", NULL },
38
{ "check", 'c', 0, G_OPTION_ARG_NONE, &check, "Check whether this URL is supported", NULL },
39
{ "debug", 'd', 0, G_OPTION_ARG_NONE, &debug, "Turn on debug mode", NULL },
44
supports_uri (const char *uri)
50
r = quvi_supports (q, uri, QUVI_SUPPORTS_MODE_OFFLINE, QUVI_SUPPORTS_TYPE_ANY);
57
const char *container;
58
const char *content_type;
60
{ "webm", "video/webm" },
64
container_to_content_type (const char *container)
68
if (container == NULL)
70
for (i = 0; i < G_N_ELEMENTS (containers); i++) {
71
if (g_str_equal (container, containers[i].container))
72
return containers[i].content_type;
78
print (const char *name,
81
g_return_if_fail (name != NULL);
86
g_print ("%s=%s\n", name, value);
90
parse_videosite (const char *uri)
95
const char *video_uri;
98
const char *content_type;
99
const char *thumb_url;
100
const char *container;
103
char *duration_str = NULL;
104
char *starttime_str = NULL;
106
if (!supports_uri (uri)) {
107
g_print ("TOTEM_PL_PARSER_RESULT_UNHANDLED");
112
qm = quvi_media_new (q, uri);
114
/* Empty results list? */
115
if (quvi_media_stream_next(qm) != QUVI_TRUE) {
117
g_print ("Parsing '%s' failed with error: %s\n",
118
uri, quvi_errmsg (q));
119
g_print ("TOTEM_PL_PARSER_RESULT_ERROR");
123
/* Choose the best stream */
124
quvi_media_stream_choose_best (qm);
126
quvi_media_get (qm, QUVI_MEDIA_PROPERTY_TITLE, &title);
127
quvi_media_get (qm, QUVI_MEDIA_PROPERTY_ID, &id);
128
quvi_media_get (qm, QUVI_MEDIA_PROPERTY_THUMBNAIL_URL, &thumb_url);
129
quvi_media_get (qm, QUVI_MEDIA_PROPERTY_DURATION_MS, &duration);
131
duration_str = g_strdup_printf ("%f", duration);
132
quvi_media_get (qm, QUVI_MEDIA_STREAM_PROPERTY_URL, &video_uri);
133
quvi_media_get (qm, QUVI_MEDIA_PROPERTY_START_TIME_MS, &starttime);
135
starttime_str = g_strdup_printf ("%f", starttime);
137
quvi_media_get (qm, QUVI_MEDIA_STREAM_PROPERTY_CONTAINER, &container);
138
content_type = container_to_content_type (container);
140
if (video_uri != NULL) {
141
print (TOTEM_PL_PARSER_FIELD_TITLE, title);
142
print (TOTEM_PL_PARSER_FIELD_ID, id);
143
print (TOTEM_PL_PARSER_FIELD_MOREINFO, uri);
144
print (TOTEM_PL_PARSER_FIELD_URI, video_uri);
145
print (TOTEM_PL_PARSER_FIELD_STARTTIME, starttime_str);
146
print (TOTEM_PL_PARSER_FIELD_CONTENT_TYPE, content_type);
147
print (TOTEM_PL_PARSER_FIELD_IMAGE_URI, thumb_url);
148
print (TOTEM_PL_PARSER_FIELD_DURATION, duration_str);
151
g_free (starttime_str);
152
g_free (duration_str);
155
quvi_media_free (qm);
159
int main (int argc, char **argv)
161
GOptionContext *context;
163
setlocale (LC_ALL, "");
165
context = g_option_context_new (NULL);
166
g_option_context_set_summary (context, "totem-pl-parser libquvi Helper");
167
g_option_context_add_main_entries (context, options, NULL);
168
g_option_context_parse (context, &argc, &argv, NULL);
173
txt = g_option_context_get_help (context, FALSE, NULL);
177
g_option_context_free (context);
181
g_option_context_free (context);
184
g_print ("%s", supports_uri (url) ? "TRUE" : "FALSE");
188
parse_videosite (url);