2 * Copyright (C) 2012-2013 Toni Gundogdu <legatvs@gmail.com>
4 * This file is part of libquvi <http://quvi.sourceforge.net/>.
6 * This program is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU Affero General Public
8 * License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General
17 * Public License along with this program. If not, see
18 * <http://www.gnu.org/licenses/>.
37 static struct _opts_s opts
;
39 static const GOptionEntry entries
[] =
42 "property", 'p', 0, G_OPTION_ARG_STRING_ARRAY
, &opts
.property
,
43 "Script property to output", "PROPERTY"
46 "type", 't', 0, G_OPTION_ARG_STRING
, &opts
.type
,
49 {NULL
, 0, 0, 0, NULL
, NULL
, NULL
}
52 struct _property_lookup_s
54 QuviScriptProperty to
;
58 static const struct _property_lookup_s property_conv
[] =
60 {QUVI_SCRIPT_PROPERTY_EXPORT_FORMAT
, "export.format"},
61 {QUVI_SCRIPT_PROPERTY_FILEPATH
, "filepath"},
62 {QUVI_SCRIPT_PROPERTY_FILENAME
, "filename"},
63 {QUVI_SCRIPT_PROPERTY_DOMAINS
, "domains"},
64 {QUVI_SCRIPT_PROPERTY_SHA1
, "sha1"},
68 static void dump_script(QuviScriptType type
)
70 QuviScriptProperty qsp
;
74 for (i
=0; opts
.property
[i
] != NULL
; ++i
)
76 const gchar
*p
= opts
.property
[i
];
77 for (j
=0; property_conv
[j
].from
!= NULL
; ++j
)
79 if (g_strcmp0(p
, property_conv
[j
].from
) == 0)
81 qsp
= property_conv
[j
].to
;
85 quvi_script_get(q
, type
, qsp
, &s
);
87 g_print("[%s]\n", __func__
);
88 g_print(" %s=%s\n", p
, s
);
92 static gchar
**property_sv()
98 while (property_conv
[i
].from
!= NULL
) ++i
;
99 r
= g_new(gchar
*, i
+1);
102 while (property_conv
[j
].from
!= NULL
)
103 r
[i
++] = g_strdup(property_conv
[j
++].from
);
109 static gboolean
chk_property_values()
115 r
= examples_chk_val_sv(opts
.property
, v
, &s
);
119 "error: invalid value (`%s') for the option `--property'\n", s
);
125 struct _type_lookup_s
131 static const struct _type_lookup_s type_conv
[] =
133 {QUVI_SCRIPT_TYPE_SUBTITLE_EXPORT
, "subtitle.export"},
134 {QUVI_SCRIPT_TYPE_SUBTITLE
, "subtitle"},
135 {QUVI_SCRIPT_TYPE_PLAYLIST
, "playlist"},
136 {QUVI_SCRIPT_TYPE_MEDIA
, "media"},
137 {QUVI_SCRIPT_TYPE_SCAN
, "scan"},
141 static gchar
**type_sv()
147 while (type_conv
[i
].from
!= NULL
) ++i
;
148 r
= g_new(gchar
*, i
+1);
151 while (type_conv
[j
].from
!= NULL
)
152 r
[i
++] = g_strdup(type_conv
[j
++].from
);
158 static gboolean
chk_type_values()
164 r
= examples_chk_val_s(opts
.type
, v
, &s
);
168 "error: invalid value (`%s') for the option `--type'\n", s
);
177 static QuviScriptType
type_n()
180 for (i
=0; type_conv
[i
].from
!= NULL
; ++i
)
182 if (g_strcmp0(opts
.type
, type_conv
[i
].from
) == 0)
183 return (type_conv
[i
].to
);
185 return (QUVI_SCRIPT_TYPE_MEDIA
);
188 static gint
opts_new(gint argc
, gchar
**argv
)
194 c
= g_option_context_new(NULL
);
198 g_option_context_set_help_enabled(c
, TRUE
);
199 g_option_context_add_main_entries(c
, entries
, NULL
);
201 if (g_option_context_parse(c
, &argc
, &argv
, &e
) == FALSE
)
203 g_printerr("error: %s\n", e
->message
);
207 g_option_context_free(c
);
209 /* Set the defaults. */
211 if (opts
.property
== NULL
)
213 gchar
*v
[] = {"filename", "domains", NULL
};
214 opts
.property
= g_strdupv(v
);
217 if (opts
.type
== NULL
)
218 opts
.type
= g_strdup("media");
222 if (chk_property_values() == FALSE
)
223 return (EXIT_FAILURE
);
225 if (chk_type_values() == FALSE
)
226 return (EXIT_FAILURE
);
231 static void opts_free()
233 g_strfreev(opts
.property
);
234 opts
.property
= NULL
;
240 gint
main(gint argc
, gchar
**argv
)
245 setlocale(LC_ALL
, "");
247 memset(&opts
, 0, sizeof(struct _opts_s
));
250 r
= opts_new(argc
, argv
);
251 if (r
!= EXIT_SUCCESS
)
255 examples_exit_if_error();
259 gchar
*p
= g_strjoinv(",", opts
.property
);
260 g_printerr("[%s] type=%s (0x%x), property=%s\n",
261 __func__
, opts
.type
, type
, p
);
265 while (quvi_script_next(q
, type
) == QUVI_TRUE
)
275 /* vim: set ts=2 sw=2 tw=72 expandtab: */