FIX: lutil_quvi_init: Pass handle value to quvi_errmsg
[quvi-tool.git] / src / setup.c
blobcfc89723870e9575ca484351d39addae97f78399
1 /* quvi
2 * Copyright (C) 2012,2013 Toni Gundogdu <legatvs@gmail.com>
4 * This file is part of quvi <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/>.
21 #include "config.h"
23 #include <stdlib.h>
24 #include <string.h>
25 #include <glib.h>
26 #include <quvi.h>
28 #include "linput.h"
29 #include "lutil.h"
30 #include "lopts.h"
31 #include "setup.h"
32 #include "opts.h"
34 extern QuviError cb_status(glong, gpointer);
35 extern struct opts_s opts;
37 gint setup_opts(gint argc, gchar **argv, lopts_t lopts)
39 memset(lopts, 0, sizeof(struct lopts_s));
41 lopts->cb.set_post_parse_defaults = cb_set_post_parse_defaults;
42 lopts->cb.cmdline_validate_values = cb_cmdline_validate_values;
43 lopts->cb.parse_keyfile_values = cb_parse_keyfile_values;
44 lopts->cb.get_config_fpath = cb_get_config_fpath;
46 lopts->entries = option_entries;
47 lopts->argc = argc;
48 lopts->argv = argv;
50 if (lopts_new(lopts) != EXIT_SUCCESS)
51 return (EXIT_FAILURE);
53 if (g_strcmp0(opts.core.verbosity, "debug") ==0)
54 lopts_print_config_values(lopts);
56 return (EXIT_SUCCESS);
59 gint setup_quvi(quvi_t *q)
61 struct lutil_net_opts_s o;
62 lutilVerbosityLevel v;
63 gint r;
65 v = lutil_setup_verbosity_level(opts.core.verbosity);
66 memset(&o, 0, sizeof(struct lutil_net_opts_s));
68 o.verbose = (v == UTIL_VERBOSITY_LEVEL_DEBUG) ? 1:0;
69 o.throttle_ki_s = opts.get.throttle;
71 r = lutil_quvi_init(q, &o);
72 if (r == EXIT_SUCCESS)
74 quvi_set(*q, QUVI_OPTION_USER_AGENT, opts.http.user_agent);
75 quvi_set(*q, QUVI_OPTION_CALLBACK_STATUS, cb_status);
77 return (r);
80 #define _reverse(p)\
81 do {\
82 if (p != NULL)\
83 p = g_slist_reverse(p);\
84 } while (0)
86 static void _reverse_input_url_order(lutil_check_support_t css)
88 _reverse(css->url.playlist);
89 _reverse(css->url.subtitle);
90 _reverse(css->url.media);
93 #undef _reverse
95 gint setup_query(setup_query_t sq)
97 struct lutil_query_properties_s qps;
98 struct lutil_check_support_s css;
100 g_assert(sq != NULL);
101 g_assert(sq->activity.playlist != NULL);
102 g_assert(sq->activity.subtitle != NULL);
103 g_assert(sq->activity.media != NULL);
104 g_assert(sq->linput != NULL);
105 g_assert(sq->xperr != NULL);
106 g_assert(sq->perr != NULL);
107 g_assert(sq->q != NULL);
109 /* check {media,playlist,subtitle} URL support. */
111 memset(&css, 0, sizeof(struct lutil_check_support_s));
113 css.flags.force_offline_mode = opts.core.check_mode_offline;
114 css.flags.force_subtitle_mode = sq->force_subtitle_mode;
116 css.exit_status = EXIT_SUCCESS;
117 css.xperr = sq->xperr;
118 css.perr = sq->perr;
119 css.q = sq->q;
121 g_slist_foreach(sq->linput->url.input, lutil_check_support, &css);
123 if (css.exit_status != EXIT_SUCCESS)
125 lutil_check_support_free(&css);
126 return (css.exit_status);
130 * The "check support" facility prepends to the lists. Reverse the order
131 * to restore the input order.
133 _reverse_input_url_order(&css);
135 /* query {playlist,media} properties. */
137 memset(&qps, 0, sizeof(struct lutil_query_properties_s));
139 qps.activity = sq->activity.playlist;
140 qps.exit_status = EXIT_SUCCESS;
141 qps.xperr = sq->xperr;
142 qps.perr = sq->perr;
143 qps.q = sq->q;
145 g_slist_foreach(css.url.playlist, lutil_query_playlist, &qps);
147 if (qps.exit_status == EXIT_SUCCESS)
149 if (css.flags.force_subtitle_mode == TRUE)
151 qps.activity = sq->activity.subtitle;
152 g_slist_foreach(css.url.subtitle, lutil_query_subtitle, &qps);
154 else
156 qps.activity = sq->activity.media;
157 g_slist_foreach(css.url.media, lutil_query_media, &qps);
160 lutil_check_support_free(&css);
161 return (qps.exit_status);
164 /* vim: set ts=2 sw=2 tw=72 expandtab: */