melunko@274
|
1 |
|
rosfran@618
|
2 |
#include <gmyth/gmyth_backendinfo.h>
|
rosfran@618
|
3 |
#include <gmyth/gmyth_epg.h>
|
melunko@274
|
4 |
|
rosfran@593
|
5 |
#include "common.h"
|
rosfran@593
|
6 |
|
melunko@274
|
7 |
static gboolean
|
melunko@274
|
8 |
test_epg_connection (GMythBackendInfo *backend_info)
|
melunko@274
|
9 |
{
|
melunko@274
|
10 |
GMythEPG *epg = gmyth_epg_new ();
|
melunko@274
|
11 |
gboolean res = FALSE;
|
melunko@274
|
12 |
|
melunko@274
|
13 |
res = gmyth_epg_connect (epg, backend_info);
|
melunko@274
|
14 |
|
melunko@274
|
15 |
gmyth_epg_disconnect (epg);
|
rosfran@594
|
16 |
if ( epg != NULL )
|
rosfran@594
|
17 |
g_object_unref (epg);
|
melunko@274
|
18 |
|
melunko@274
|
19 |
return res;
|
melunko@274
|
20 |
}
|
melunko@274
|
21 |
|
melunko@274
|
22 |
|
melunko@274
|
23 |
static gboolean
|
melunko@274
|
24 |
test_epg_get_channels (GMythBackendInfo *backend_info)
|
melunko@274
|
25 |
{
|
melunko@274
|
26 |
GMythEPG *epg = gmyth_epg_new ();
|
melunko@274
|
27 |
GList *clist;
|
melunko@274
|
28 |
gint i, length;
|
melunko@274
|
29 |
|
melunko@274
|
30 |
if (!gmyth_epg_connect (epg, backend_info)) {
|
melunko@274
|
31 |
return FALSE;
|
melunko@274
|
32 |
}
|
melunko@274
|
33 |
|
melunko@274
|
34 |
length = gmyth_epg_get_channel_list (epg, &clist);
|
rosfran@594
|
35 |
g_debug ("==== %d channels found in the EPG ====\n", length);
|
melunko@274
|
36 |
for (i=0; i<length; i++) {
|
melunko@274
|
37 |
GMythChannelInfo *channel_info = (GMythChannelInfo*) g_list_nth_data (clist, i);
|
melunko@274
|
38 |
|
melunko@274
|
39 |
gmyth_channel_info_print(channel_info);
|
melunko@274
|
40 |
}
|
melunko@274
|
41 |
|
melunko@274
|
42 |
g_list_free (clist);
|
melunko@274
|
43 |
gmyth_epg_disconnect (epg);
|
rosfran@594
|
44 |
if ( epg != NULL )
|
rosfran@594
|
45 |
g_object_unref (epg);
|
melunko@274
|
46 |
}
|
melunko@274
|
47 |
|
melunko@583
|
48 |
static gboolean
|
melunko@583
|
49 |
test_epg_get_channel_icon (GMythBackendInfo *backend_info)
|
melunko@583
|
50 |
{
|
melunko@583
|
51 |
GMythEPG *epg = gmyth_epg_new ();
|
melunko@583
|
52 |
GList *clist;
|
melunko@583
|
53 |
gint i, length;
|
melunko@583
|
54 |
|
melunko@583
|
55 |
if (!gmyth_epg_connect (epg, backend_info)) {
|
melunko@583
|
56 |
return FALSE;
|
melunko@583
|
57 |
}
|
melunko@583
|
58 |
|
melunko@583
|
59 |
length = gmyth_epg_get_channel_list (epg, &clist);
|
rosfran@594
|
60 |
g_debug ("==== %d channels found in the EPG ====\n", length);
|
melunko@583
|
61 |
for (i=0; i<length; i++) {
|
melunko@583
|
62 |
GMythChannelInfo *channel_info = (GMythChannelInfo*) g_list_nth_data (clist, i);
|
melunko@583
|
63 |
|
melunko@583
|
64 |
if (gmyth_epg_channel_has_icon (epg, channel_info)) {
|
melunko@583
|
65 |
gchar *icon_name = g_strdup_printf ("%s.jpg", channel_info->channel_name->str);
|
melunko@583
|
66 |
guint8 *icon_data = NULL;
|
melunko@583
|
67 |
guint icon_length;
|
melunko@583
|
68 |
|
rosfran@594
|
69 |
g_debug ("Channel %s has icon %s\n", channel_info->channel_name->str, channel_info->channel_icon->str);
|
melunko@583
|
70 |
|
melunko@583
|
71 |
if (gmyth_epg_channel_get_icon (epg, channel_info, &icon_data, &icon_length)) {
|
melunko@583
|
72 |
FILE *outfile = fopen (icon_name, "w+");
|
melunko@583
|
73 |
if (fwrite (icon_data, icon_length, 1, outfile) == icon_length)
|
rosfran@594
|
74 |
g_debug ("\tIcon saved as %s", icon_name);
|
melunko@583
|
75 |
else
|
rosfran@594
|
76 |
g_debug ("\tError while downloading the file or writing it");
|
melunko@583
|
77 |
|
melunko@583
|
78 |
g_free (icon_data);
|
melunko@583
|
79 |
}
|
melunko@583
|
80 |
g_free (icon_name);
|
melunko@583
|
81 |
|
melunko@583
|
82 |
} else {
|
rosfran@594
|
83 |
g_debug ("Channel %s does not have icon\n", channel_info->channel_name->str);
|
melunko@583
|
84 |
}
|
melunko@583
|
85 |
gmyth_channel_info_print(channel_info);
|
melunko@583
|
86 |
}
|
melunko@583
|
87 |
|
melunko@583
|
88 |
g_list_free (clist);
|
melunko@583
|
89 |
gmyth_epg_disconnect (epg);
|
melunko@583
|
90 |
g_object_unref (epg);
|
melunko@583
|
91 |
|
melunko@583
|
92 |
return TRUE;
|
melunko@583
|
93 |
}
|
melunko@583
|
94 |
|
melunko@274
|
95 |
int
|
melunko@274
|
96 |
main (int args, const char **argv)
|
melunko@274
|
97 |
{
|
melunko@274
|
98 |
|
melunko@274
|
99 |
GMythBackendInfo *backend_info;
|
melunko@274
|
100 |
g_type_init ();
|
rosfran@564
|
101 |
g_thread_init (NULL);
|
melunko@274
|
102 |
|
melunko@583
|
103 |
if (args < 2) {
|
rosfran@594
|
104 |
g_debug ("Type %s myth://hostname:port/?mythconverg\n", argv[0]);
|
melunko@583
|
105 |
return -1;
|
melunko@583
|
106 |
}
|
melunko@583
|
107 |
|
melunko@274
|
108 |
backend_info = gmyth_backend_info_new_with_uri (argv[1]);
|
melunko@274
|
109 |
|
rosfran@593
|
110 |
fprintf(stdout, SYNC_STRING);
|
rosfran@593
|
111 |
fflush(NULL);
|
rosfran@593
|
112 |
getchar();
|
rosfran@593
|
113 |
|
melunko@274
|
114 |
test_epg_connection (backend_info);
|
melunko@274
|
115 |
test_epg_get_channels (backend_info);
|
melunko@583
|
116 |
test_epg_get_channel_icon (backend_info);
|
melunko@274
|
117 |
|
rosfran@594
|
118 |
if ( backend_info != NULL )
|
rosfran@594
|
119 |
g_object_unref( backend_info );
|
rosfran@594
|
120 |
|
rosfran@593
|
121 |
return(0);
|
melunko@274
|
122 |
}
|
melunko@274
|
123 |
|