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;
18 gboolean list_upcoming;
24 ls_options_t *options = g_new0(ls_options_t, 1);
25 options->b_info = gmyth_backend_info_new();
31 _ls_options_free(ls_options_t * options)
33 g_return_if_fail(options != NULL);
36 g_object_unref(options->b_info);
40 _parse_args(int argc, char *argv[], ls_options_t * options)
43 GOptionContext *context;
45 gchar *host_ip = NULL;
46 gint host_port = 6543;
48 gchar *username = NULL;
49 gchar *password = NULL;
51 GOptionEntry entries[] = {
52 {"hostname", 'h', 0, G_OPTION_ARG_STRING, &host_ip,
53 "Mythtv backend hostname or " "IP address", "IP_ADDRESS"},
55 {"port", 'p', 0, G_OPTION_ARG_INT, &host_port,
56 "Mythtv backend port",
59 {"list_channels", 'c', 0, G_OPTION_ARG_NONE, &options->list_channels,
60 "List channels", NULL},
62 {"list_rules", 'r', 0, G_OPTION_ARG_NONE, &options->list_rules,
63 "List recording rules", NULL},
65 {"list_upcoming", 'u', 0, G_OPTION_ARG_NONE, &options->list_upcoming,
66 "List upcoming recordings", NULL},
68 {"username", 'n', 0, G_OPTION_ARG_STRING, &username,
69 "Mysql database username. Default: mythtv",
72 {"password", 'w', 0, G_OPTION_ARG_STRING, &password,
73 "Mysql database password. Default: mythtv",
76 {"db_port", 'P', 0, G_OPTION_ARG_STRING, &db_port,
77 "Mysql database port. Default: 0",
83 g_return_val_if_fail(options != NULL, FALSE);
85 context = g_option_context_new("- list mythtv recorded programs etc.");
86 g_option_context_add_main_entries(context, entries, NULL);
87 g_option_context_parse(context, &argc, &argv, &error);
89 g_option_context_free(context);
92 g_printerr("%s.\n", error->message);
98 if (!!options->list_channels + !!options->list_rules +
99 !!options->list_upcoming > 1) {
100 g_printerr("Only one --list option may be given.\n");
105 gmyth_backend_info_set_hostname(options->b_info,
106 host_ip ? host_ip : "localhost");
107 gmyth_backend_info_set_port(options->b_info, host_port);
110 gmyth_backend_info_set_username(options->b_info, username);
112 gmyth_backend_info_set_username(options->b_info, "mythtv");
115 gmyth_backend_info_set_password(options->b_info, password);
117 gmyth_backend_info_set_password(options->b_info, "mythtv");
119 gmyth_backend_info_set_db_name(options->b_info, "mythconverg");
127 _ls_recording_rules(ls_options_t * options)
129 GMythScheduler *scheduler;
135 g_return_val_if_fail(options != NULL, FALSE);
136 g_return_val_if_fail(options->b_info != NULL, FALSE);
138 scheduler = gmyth_scheduler_new();
140 if (gmyth_scheduler_connect_with_timeout(scheduler,
141 options->b_info, 10) == FALSE)
143 g_print("Could not connect to database server.\n");
144 g_object_unref(scheduler);
148 res = gmyth_scheduler_get_schedule_list(scheduler, &list);
150 gmyth_scheduler_disconnect(scheduler);
151 g_object_unref(scheduler);
154 g_print("Could not retrieve list of recording rules.\n");
160 ScheduleInfo *schedule_info = (ScheduleInfo *) iter->data;
163 g_print("%s\n", schedule_info->title->str);
164 gmyth_schedule_info_free(schedule_info);
165 iter = g_list_next(iter);
169 g_print("No recording rules.\n");
177 _ls_upcoming_recordings(ls_options_t * options)
187 g_return_val_if_fail(options != NULL, FALSE);
188 g_return_val_if_fail(options->b_info != NULL, FALSE);
190 list = gmyth_util_get_all_pending(options->b_info, &conflicts);
194 GMythProgramInfo *program = (GMythProgramInfo *) iter->data;
196 if (program->recstatus == GMYTH_REC_STATUS_RECORDING ||
197 program->recstatus == GMYTH_REC_STATUS_WILL_RECORD) {
199 recstart = program->recstartts->tv_sec;
200 tm = localtime(&recstart);
201 strftime(buffer, sizeof(buffer), "%F %R", tm);
202 g_print("%s %s", buffer, program->title->str);
203 if (program->subtitle->len)
204 g_print(": %s", program->subtitle->str);
208 g_object_unref(program);
209 iter = g_slist_next(iter);
213 g_print("No upcoming recordings.\n");
215 g_print("Conflicts found.\n");
217 g_print("No conflicts found.\n");
225 _ls_recorded_files(ls_options_t * options)
227 GMythScheduler *scheduler;
234 GMythProgramInfo *program;
236 g_return_val_if_fail(options != NULL, FALSE);
237 g_return_val_if_fail(options->b_info != NULL, FALSE);
239 scheduler = gmyth_scheduler_new();
241 if (gmyth_scheduler_connect_with_timeout(scheduler,
242 options->b_info, 10) == FALSE)
244 g_print("Could not connect to database server.\n");
245 g_object_unref(scheduler);
249 res = gmyth_scheduler_get_recorded_list(scheduler, &list);
251 gmyth_scheduler_disconnect(scheduler);
252 g_object_unref(scheduler);
255 g_print("Could not retrieve list of recorded programs.\n");
260 socket = gmyth_backend_info_get_connected_socket(options->b_info);
262 RecordedInfo *recorded_info = (RecordedInfo *) iter->data;
264 program = gmyth_program_info_new();
265 program->pathname = g_string_new(recorded_info->basename->str);
266 program->channel_id = recorded_info->channel_id;
267 program->recstartts = g_memdup(recorded_info->start_time,
268 sizeof(*program->startts));
269 path = gmyth_util_check_file_from_socket(socket, program);
272 g_print("%s\n", recorded_info->basename->str);
273 g_string_free(path, TRUE);
275 gmyth_recorded_info_free(recorded_info);
276 g_object_unref(program);
277 iter = g_list_next(iter);
279 g_object_unref(socket);
282 g_print("No recorded programs.\n");
290 _ls_channels(ls_options_t * options)
297 g_return_val_if_fail(options != NULL, FALSE);
298 g_return_val_if_fail(options->b_info != NULL, FALSE);
301 epg = gmyth_epg_new();
302 if (!gmyth_epg_connect(epg, options->b_info)) {
307 length = gmyth_epg_get_channel_list(epg, &clist);
308 for (ch = clist; ch != NULL; ch = ch->next) {
309 GMythChannelInfo *info = (GMythChannelInfo *) ch->data;
311 if ((info->channel_name == NULL) || (info->channel_num == NULL)) {
315 g_print("%s\t\t%s\n", info->channel_num->str,
316 info->channel_name->str);
319 gmyth_free_channel_list(clist);
320 gmyth_epg_disconnect(epg);
327 main(int argc, char *argv[])
329 gboolean res = FALSE;
330 ls_options_t *options;
335 options = _ls_options_new();
336 res = _parse_args(argc, argv, options);
338 g_printerr("Argument invalid. Type --help\n");
342 if (options->list_channels)
343 res = _ls_channels(options);
344 else if (options->list_rules)
345 res = _ls_recording_rules(options);
346 else if (options->list_upcoming)
347 res = _ls_upcoming_recordings(options);
349 res = _ls_recorded_files(options);
351 _ls_options_free(options);