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
38 static struct _opts_s opts
;
40 static const GOptionEntry entries
[] =
43 "property", 'p', 0, G_OPTION_ARG_STRING_ARRAY
, &opts
.property
,
44 "Script property to output", "PROPERTY"
47 "type", 't', 0, G_OPTION_ARG_STRING
, &opts
.type
,
51 "autoproxy", 'a', 0, G_OPTION_ARG_NONE
, &opts
.autoproxy
,
52 "Enable the autoproxy feature", NULL
55 "verbose", 'v', 0, G_OPTION_ARG_NONE
, &opts
.verbose
,
56 "Verbose libcurl output", NULL
58 {NULL
, 0, 0, 0, NULL
, NULL
, NULL
}
61 struct _property_lookup_s
63 QuviScriptProperty to
;
67 static const struct _property_lookup_s property_conv
[] =
69 {QUVI_SCRIPT_PROPERTY_FILEPATH
, "filepath"},
70 {QUVI_SCRIPT_PROPERTY_FILENAME
, "filename"},
71 {QUVI_SCRIPT_PROPERTY_DOMAINS
, "domains"},
72 {QUVI_SCRIPT_PROPERTY_SHA1
, "sha1"},
76 static void dump_script(QuviScriptType type
)
78 QuviScriptProperty qsp
;
82 for (i
=0; opts
.property
[i
] != NULL
; ++i
)
84 const gchar
*p
= opts
.property
[i
];
85 for (j
=0; property_conv
[j
].from
!= NULL
; ++j
)
87 if (g_strcmp0(p
, property_conv
[j
].from
) == 0)
89 qsp
= property_conv
[j
].to
;
93 quvi_script_get(q
, type
, qsp
, &s
);
95 g_print("[%s]\n", __func__
);
96 g_print(" %s=%s\n", p
, s
);
100 static gchar
**property_sv()
106 while (property_conv
[i
].from
!= NULL
) ++i
;
107 r
= g_new(gchar
*, i
+1);
110 while (property_conv
[j
].from
!= NULL
)
111 r
[i
++] = g_strdup(property_conv
[j
++].from
);
117 static gboolean
chk_property_values()
123 r
= examples_chk_val_sv(opts
.property
, v
, &s
);
127 "error: invalid value (`%s') for the option `--property'\n", s
);
136 struct _type_lookup_s
142 static const struct _type_lookup_s type_conv
[] =
144 {QUVI_SCRIPT_TYPE_PLAYLIST
, "playlist"},
145 {QUVI_SCRIPT_TYPE_MEDIA
, "media"},
146 {QUVI_SCRIPT_TYPE_SCAN
, "scan"},
150 static gchar
**type_sv()
156 while (type_conv
[i
].from
!= NULL
) ++i
;
157 r
= g_new(gchar
*, i
+1);
160 while (type_conv
[j
].from
!= NULL
)
161 r
[i
++] = g_strdup(type_conv
[j
++].from
);
167 static gboolean
chk_type_values()
173 r
= examples_chk_val_s(opts
.type
, v
, &s
);
177 "error: invalid value (`%s') for the option `--type'\n", s
);
186 static QuviScriptType
type_n()
189 for (i
=0; type_conv
[i
].from
!= NULL
; ++i
)
191 if (g_strcmp0(opts
.type
, type_conv
[i
].from
) == 0)
192 return (type_conv
[i
].to
);
194 return (QUVI_SCRIPT_TYPE_MEDIA
);
197 static gint
opts_new(gint argc
, gchar
**argv
)
204 c
= g_option_context_new(NULL
);
209 g_option_context_set_help_enabled(c
, TRUE
);
210 g_option_context_add_main_entries(c
, entries
, NULL
);
212 if (g_option_context_parse(c
, &argc
, &argv
, &e
) == FALSE
)
214 g_printerr("error: %s\n", e
->message
);
220 g_option_context_free(c
);
223 /* Set the defaults. */
225 if (opts
.property
== NULL
)
227 gchar
*v
[] = {"filename", "domains", NULL
};
228 opts
.property
= g_strdupv(v
);
231 if (opts
.type
== NULL
)
232 opts
.type
= g_strdup("media");
236 if (chk_property_values() == FALSE
)
237 return (EXIT_FAILURE
);
239 if (chk_type_values() == FALSE
)
240 return (EXIT_FAILURE
);
245 static void opts_free()
247 g_strfreev(opts
.property
);
248 opts
.property
= NULL
;
254 typedef quvi_callback_status qcs
;
256 gint
main(gint argc
, gchar
**argv
)
261 setlocale(LC_ALL
, "");
263 memset(&opts
, 0, sizeof(struct _opts_s
));
266 r
= opts_new(argc
, argv
);
267 if (r
!= EXIT_SUCCESS
)
271 examples_exit_if_error();
273 if (opts
.autoproxy
== TRUE
)
274 examples_enable_autoproxy();
276 if (opts
.verbose
== TRUE
)
277 examples_enable_verbose();
282 gchar
*p
= g_strjoinv(",", opts
.property
);;
283 g_printerr("[%s] type=%s (0x%x), property=%s\n",
284 __func__
, opts
.type
, type
, p
);
289 while (quvi_script_next(q
, type
) == QUVI_TRUE
)
299 /* vim: set ts=2 sw=2 tw=72 expandtab: */