2 * Copyright (C) 2012 Toni Gundogdu <legatvs@gmail.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This 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 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
39 static struct _opts_s opts
;
41 static const GOptionEntry entries
[] =
44 "type", 't', 0, G_OPTION_ARG_STRING
, &opts
.type
,
48 "online", 's', 0, G_OPTION_ARG_NONE
, &opts
.online
,
52 "autoproxy", 'a', 0, G_OPTION_ARG_NONE
, &opts
.autoproxy
,
53 "Enable the autoproxy feature", NULL
56 "verbose", 'v', 0, G_OPTION_ARG_NONE
, &opts
.verbose
,
57 "Verbose libcurl output", NULL
60 G_OPTION_REMAINING
, 0, 0, G_OPTION_ARG_STRING_ARRAY
, &opts
.url
, "URL"
62 {NULL
, 0, 0, 0, NULL
, NULL
, NULL
}
71 static const struct _type_lookup_s type_conv
[] =
73 {QUVI_SUPPORTS_TYPE_PLAYLIST
, "playlist"},
74 {QUVI_SUPPORTS_TYPE_MEDIA
, "media"},
75 {QUVI_SUPPORTS_TYPE_ANY
, "any"},
79 static gchar
**type_sv()
85 while (type_conv
[i
].from
!= NULL
) ++i
;
86 r
= g_new(gchar
*, i
+1);
89 while (type_conv
[j
].from
!= NULL
)
90 r
[i
++] = g_strdup(type_conv
[j
++].from
);
96 static gboolean
chk_type_values()
102 r
= examples_chk_val_s(opts
.type
, v
, &s
);
106 "error: invalid value (`%s') for the option `--type'\n", s
);
115 static QuviSupportsType
type_n()
118 for (i
=0; type_conv
[i
].from
!= NULL
; ++i
)
120 if (g_strcmp0(opts
.type
, type_conv
[i
].from
) == 0)
121 return (type_conv
[i
].to
);
123 return (QUVI_SCRIPT_TYPE_MEDIA
);
126 static gint
opts_new(gint argc
, gchar
**argv
)
133 c
= g_option_context_new("URL");
138 g_option_context_set_help_enabled(c
, TRUE
);
139 g_option_context_add_main_entries(c
, entries
, NULL
);
141 if (g_option_context_parse(c
, &argc
, &argv
, &e
) == FALSE
)
143 g_printerr("error: %s\n", e
->message
);
149 g_option_context_free(c
);
152 /* Set default values. */
154 if (opts
.type
== NULL
)
155 opts
.type
= g_strdup("any");
159 if (chk_type_values() == FALSE
)
160 return (EXIT_FAILURE
);
162 if (opts
.url
== NULL
)
164 g_printerr("error: no input URL\n");
165 return (EXIT_FAILURE
);
171 static void opts_free()
173 g_strfreev(opts
.url
);
180 static QuviSupportsMode mode
= QUVI_SUPPORTS_MODE_OFFLINE
;
181 static QuviSupportsType type
= QUVI_SUPPORTS_TYPE_ANY
;
183 static void chk_support(const gchar
*url
)
185 const QuviBoolean r
= quvi_supports(q
, url
, mode
, type
);
187 /* Always check for any network errors with QUVI_SUPPORTS_MODE_ONLINE. */
188 if (r
== FALSE
&& mode
== QUVI_SUPPORTS_MODE_ONLINE
)
191 quvi_get(q
, QUVI_INFO_ERROR_CODE
, &ec
);
193 if (ec
!= QUVI_ERROR_NO_SUPPORT
)
195 g_printerr("\nerror: %s\n", quvi_errmsg(q
));
199 g_print("%s: %s\n", url
, (r
== QUVI_TRUE
) ? "yes":"no");
202 typedef quvi_callback_status qcs
;
204 gint
main(gint argc
, gchar
**argv
)
210 memset(&opts
, 0, sizeof(struct _opts_s
));
211 setlocale(LC_ALL
, "");
213 r
= opts_new(argc
, argv
);
214 if (r
!= EXIT_SUCCESS
)
218 examples_exit_if_error();
220 if (opts
.autoproxy
== TRUE
)
221 examples_enable_autoproxy();
223 if (opts
.verbose
== TRUE
)
224 examples_enable_verbose();
226 if (opts
.online
== TRUE
)
227 mode
= QUVI_SUPPORTS_MODE_ONLINE
;
229 quvi_set(q
, QUVI_OPTION_CALLBACK_STATUS
, (qcs
) examples_status
);
232 g_printerr("[%s] type=%s (0x%x), mode=0x%x\n",
233 __func__
, opts
.type
, type
, mode
);
235 for (i
=0; opts
.url
[i
] != NULL
; ++i
)
236 chk_support(opts
.url
[i
]);
245 /* vim: set ts=2 sw=2 tw=72 expandtab: */