9 #include "gmyth_backendinfo.h"
10 #include "gmyth_scheduler.h"
11 #include "gmyth_util.h"
12 #include "gmyth_epg.h"
15 GMythBackendInfo *b_info;
16 gboolean list_channels;
22 ls_options_t *options = g_new0(ls_options_t, 1);
23 options->b_info = gmyth_backend_info_new();
29 _ls_options_free(ls_options_t * options)
31 g_return_if_fail(options != NULL);
34 g_object_unref(options->b_info);
38 _parse_args(int argc, char *argv[], ls_options_t * options)
41 GOptionContext *context;
43 gchar *host_ip = NULL;
46 gboolean list_channels = FALSE;
47 gchar *username = NULL;
48 gchar *password = NULL;
50 GOptionEntry entries[] = {
51 {"hostname", 'h', 0, G_OPTION_ARG_STRING, &host_ip,
52 "Mythtv backend hostname or " "IP address", "IP_ADDRESS"},
54 {"port", 'p', 0, G_OPTION_ARG_INT, &host_port,
55 "Mythtv backend port",
58 {"list_channels", 'c', 0, G_OPTION_ARG_NONE, &list_channels,
62 {"username", 'u', 0, G_OPTION_ARG_STRING, &username,
63 "Mysql database username. Default: mythtv",
66 {"password", 'w', 0, G_OPTION_ARG_STRING, &password,
67 "Mysql database password. Default: mythtv",
70 {"db_port", 'P', 0, G_OPTION_ARG_STRING, &db_port,
71 "Mysql database port. Default: 0",
77 g_return_val_if_fail(options != NULL, FALSE);
81 ("- list recorded programs and channels from a mythtv backend\n");
82 g_option_context_add_main_entries(context, entries, NULL);
83 g_option_context_parse(context, &argc, &argv, &error);
84 g_option_context_set_help_enabled(context, TRUE);
86 g_option_context_free(context);
88 if ((!host_ip) || (host_port == 0)) {
93 gmyth_backend_info_set_hostname(options->b_info, host_ip);
94 gmyth_backend_info_set_port(options->b_info, host_port);
97 gmyth_backend_info_set_username(options->b_info, username);
99 gmyth_backend_info_set_username(options->b_info, "mythtv");
102 gmyth_backend_info_set_password(options->b_info, password);
104 gmyth_backend_info_set_password(options->b_info, "mythtv");
106 gmyth_backend_info_set_db_name(options->b_info, "mythconverg");
108 options->list_channels = list_channels;
116 _ls_recorded_files(ls_options_t * options)
118 GMythScheduler *scheduler;
124 g_return_val_if_fail(options != NULL, FALSE);
125 g_return_val_if_fail(options->b_info != NULL, FALSE);
127 scheduler = gmyth_scheduler_new();
129 if (gmyth_scheduler_connect_with_timeout(scheduler,
130 options->b_info, 10) == FALSE)
132 g_print("Could not connect to database server.\n");
133 g_object_unref(scheduler);
137 res = gmyth_scheduler_get_recorded_list(scheduler, &list);
139 gmyth_scheduler_disconnect(scheduler);
140 g_object_unref(scheduler);
143 g_print("Could not retrieve list of recorded programs.\n");
149 RecordedInfo *recorded_info = (RecordedInfo *) iter->data;
151 if (gmyth_util_file_exists
152 (options->b_info, recorded_info->basename->str)) {
154 g_print("%s\n", recorded_info->basename->str);
156 gmyth_recorded_info_free(recorded_info);
157 iter = g_list_next(iter);
161 g_print("No recorded programs.\n");
169 _ls_channels(ls_options_t * options)
176 g_return_val_if_fail(options != NULL, FALSE);
177 g_return_val_if_fail(options->b_info != NULL, FALSE);
180 epg = gmyth_epg_new();
181 if (!gmyth_epg_connect(epg, options->b_info)) {
186 length = gmyth_epg_get_channel_list(epg, &clist);
187 for (ch = clist; ch != NULL; ch = ch->next) {
188 GMythChannelInfo *info = (GMythChannelInfo *) ch->data;
190 if ((info->channel_name == NULL) || (info->channel_num == NULL)) {
194 g_print("%s\t\t%s\n", info->channel_num->str,
195 info->channel_name->str);
198 gmyth_free_channel_list(clist);
199 gmyth_epg_disconnect(epg);
206 main(int argc, char *argv[])
208 gboolean res = FALSE;
209 ls_options_t *options;
214 options = _ls_options_new();
215 res = _parse_args(argc, argv, options);
217 g_printerr("Argument invalid. Type --help\n");
221 if (options->list_channels)
222 res = _ls_channels(options);
224 res = _ls_recorded_files(options);
226 _ls_options_free(options);