~ubuntu-branches/ubuntu/wily/totem-pl-parser/wily-proposed

« back to all changes in this revision

Viewing changes to .pc/totem-pl-parser-use-old-quvi.patch/plparse/videosite-parser.c

  • Committer: Package Import Robot
  • Author(s): Emilio Pozuelo Monfort
  • Date: 2014-05-31 11:46:29 UTC
  • mfrom: (1.5.21 sid)
  • Revision ID: package-import@ubuntu.com-20140531114629-mman7sq28lb2owj6
Tags: 3.10.2-3
* debian/control.in:
  + Let libtotem-plparser-dev depend on libquvi-dev, needed by the
    pkg-config file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   Copyright (C) 2013 Bastien Nocera <hadess@hadess.net>
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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.
 
18
 
 
19
   Author: Bastien Nocera <hadess@hadess.net>
 
20
 */
 
21
 
 
22
#include "config.h"
 
23
 
 
24
#include <locale.h>
 
25
 
 
26
#include <glib.h>
 
27
#include <quvi.h>
 
28
#include "totem-pl-parser.h"
 
29
 
 
30
#define BASE 20
 
31
 
 
32
static char *url = NULL;
 
33
static gboolean check = FALSE;
 
34
static gboolean debug = FALSE;
 
35
 
 
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 },
 
40
        { NULL }
 
41
};
 
42
 
 
43
static gboolean
 
44
supports_uri (const char *uri)
 
45
{
 
46
        quvi_t q;
 
47
        QuviBoolean r;
 
48
 
 
49
        q = quvi_new ();
 
50
        r = quvi_supports (q, uri, QUVI_SUPPORTS_MODE_OFFLINE, QUVI_SUPPORTS_TYPE_ANY);
 
51
        quvi_free (q);
 
52
 
 
53
        return r;
 
54
}
 
55
 
 
56
static struct {
 
57
        const char *container;
 
58
        const char *content_type;
 
59
} containers [] = {
 
60
        { "webm", "video/webm" },
 
61
};
 
62
 
 
63
static const char *
 
64
container_to_content_type (const char *container)
 
65
{
 
66
        guint i;
 
67
 
 
68
        if (container == NULL)
 
69
                return 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;
 
73
        }
 
74
        return NULL;
 
75
}
 
76
 
 
77
static void
 
78
print (const char *name,
 
79
       const char *value)
 
80
{
 
81
        g_return_if_fail (name != NULL);
 
82
 
 
83
        if (value == NULL)
 
84
                return;
 
85
 
 
86
        g_print ("%s=%s\n", name, value);
 
87
}
 
88
 
 
89
static void
 
90
parse_videosite (const char *uri)
 
91
{
 
92
        quvi_t q;
 
93
        quvi_media_t qm;
 
94
        /* properties */
 
95
        const char *video_uri;
 
96
        const char *title;
 
97
        const char *id;
 
98
        const char *content_type;
 
99
        const char *thumb_url;
 
100
        const char *container;
 
101
        double duration;
 
102
        double starttime;
 
103
        char *duration_str = NULL;
 
104
        char *starttime_str = NULL;
 
105
 
 
106
        if (!supports_uri (uri)) {
 
107
                g_print ("TOTEM_PL_PARSER_RESULT_UNHANDLED");
 
108
                return;
 
109
        }
 
110
 
 
111
        q = quvi_new ();
 
112
        qm = quvi_media_new (q, uri);
 
113
 
 
114
        /* Empty results list? */
 
115
        if (quvi_media_stream_next(qm) != QUVI_TRUE) {
 
116
                if (debug)
 
117
                        g_print ("Parsing '%s' failed with error: %s\n",
 
118
                                 uri, quvi_errmsg (q));
 
119
                g_print ("TOTEM_PL_PARSER_RESULT_ERROR");
 
120
                goto out;
 
121
        }
 
122
 
 
123
        /* Choose the best stream */
 
124
        quvi_media_stream_choose_best (qm);
 
125
 
 
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);
 
130
        if (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);
 
134
        if (starttime)
 
135
                starttime_str = g_strdup_printf ("%f", starttime);
 
136
 
 
137
        quvi_media_get (qm, QUVI_MEDIA_STREAM_PROPERTY_CONTAINER, &container);
 
138
        content_type = container_to_content_type (container);
 
139
 
 
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);
 
149
        }
 
150
 
 
151
        g_free (starttime_str);
 
152
        g_free (duration_str);
 
153
 
 
154
out:
 
155
        quvi_media_free (qm);
 
156
        quvi_free (q);
 
157
}
 
158
 
 
159
int main (int argc, char **argv)
 
160
{
 
161
        GOptionContext *context;
 
162
 
 
163
        setlocale (LC_ALL, "");
 
164
 
 
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);
 
169
 
 
170
        if (url == NULL) {
 
171
                char *txt;
 
172
 
 
173
                txt = g_option_context_get_help (context, FALSE, NULL);
 
174
                g_print ("%s", txt);
 
175
                g_free (txt);
 
176
 
 
177
                g_option_context_free (context);
 
178
 
 
179
                return 1;
 
180
        }
 
181
        g_option_context_free (context);
 
182
 
 
183
        if (check) {
 
184
                g_print ("%s", supports_uri (url) ? "TRUE" : "FALSE");
 
185
                return 0;
 
186
        }
 
187
 
 
188
        parse_videosite (url);
 
189
 
 
190
        return 0;
 
191
}