9 #include "gmyth_backendinfo.h"
10 #include "gmyth_scheduler.h"
11 #include "gmyth_util.h"
12 #include "gmyth_epg.h"
16 GMythBackendInfo *b_info;
17 gboolean list_channels;
23 ls_options_t *options = g_new0(ls_options_t, 1);
24 options->b_info = gmyth_backend_info_new();
30 _ls_options_free(ls_options_t * options)
32 g_return_if_fail(options != NULL);
35 g_object_unref(options->b_info);
39 _parse_args(int argc, char *argv[], ls_options_t * options)
42 GOptionContext *context;
44 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, "Mythtv backend port",
57 {"list_channels", 'c', 0, G_OPTION_ARG_NONE, &list_channels,
61 {"username", 'u', 0, G_OPTION_ARG_STRING, &username,
62 "Mysql database username. Default: mythtv" "Mysql user", "MYSQL_USER"},
64 {"password", 'w', 0, G_OPTION_ARG_STRING, &password,
65 "Mysql database password. Default: mythtv" "Mysql password",
71 g_return_val_if_fail(options != NULL, FALSE);
75 ("- list recorded programs and channels from a mythtv backend\n");
76 g_option_context_add_main_entries(context, entries, NULL);
77 g_option_context_parse(context, &argc, &argv, &error);
78 g_option_context_set_help_enabled(context, TRUE);
80 g_option_context_free(context);
82 if ((!host_ip) || (host_port == 0))
88 gmyth_backend_info_set_hostname(options->b_info, host_ip);
89 gmyth_backend_info_set_port(options->b_info, host_port);
92 gmyth_backend_info_set_username(options->b_info, username);
94 gmyth_backend_info_set_username(options->b_info, "mythtv");
97 gmyth_backend_info_set_password(options->b_info, password);
99 gmyth_backend_info_set_password(options->b_info, "mythtv");
101 gmyth_backend_info_set_db_name(options->b_info, "mythconverg");
103 options->list_channels = list_channels;
111 _ls_recorded_files(ls_options_t * options)
113 GMythScheduler *scheduler;
117 g_return_val_if_fail(options != NULL, FALSE);
118 g_return_val_if_fail(options->b_info != NULL, FALSE);
120 scheduler = gmyth_scheduler_new();
122 if (gmyth_scheduler_connect_with_timeout(scheduler,
123 options->b_info, 10) == FALSE)
125 g_warning("Could not connect to backend db");
126 g_object_unref(scheduler);
130 res = gmyth_scheduler_get_recorded_list(scheduler, &list);
133 gmyth_scheduler_disconnect(scheduler);
134 g_object_unref(scheduler);
135 g_warning("Could not retrieve recorded list");
139 gmyth_scheduler_disconnect(scheduler);
143 g_print("None file was found in the backend.\n");
144 gmyth_scheduler_disconnect(scheduler);
145 g_object_unref(scheduler);
152 RecordedInfo *recorded_info = (RecordedInfo *) iter->data;
154 if (gmyth_util_file_exists
155 (options->b_info, recorded_info->basename->str))
157 g_print("%s\n", recorded_info->basename->str);
159 gmyth_recorded_info_free(recorded_info);
160 iter = g_list_next(iter);
165 gmyth_scheduler_disconnect(scheduler);
166 g_object_unref(scheduler);
172 _ls_channels(ls_options_t * options)
178 g_return_val_if_fail(options != NULL, FALSE);
179 g_return_val_if_fail(options->b_info != NULL, FALSE);
182 epg = gmyth_epg_new();
183 if (!gmyth_epg_connect(epg, options->b_info))
189 length = gmyth_epg_get_channel_list(epg, &clist);
190 for (ch = clist; ch != NULL; ch = ch->next)
192 GMythChannelInfo *info = (GMythChannelInfo *) ch->data;
194 if ((info->channel_name == NULL) || (info->channel_num == NULL))
199 g_print("%s\t\t%s\n", info->channel_num->str, info->channel_name->str);
202 gmyth_free_channel_list(clist);
203 gmyth_epg_disconnect(epg);
210 main(int argc, char *argv[])
212 gboolean res = FALSE;
213 ls_options_t *options;
218 options = _ls_options_new();
219 res = _parse_args(argc, argv, options);
222 g_printerr("Argument invalid. Type --help\n");
226 if (options->list_channels)
227 res = _ls_channels(options);
229 res = _ls_recorded_files(options);
231 _ls_options_free(options);