File: gmyth_test_epg.c

package info (click to toggle)
gmyth 1%3A0.7.1-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 2,256 kB
  • ctags: 1,230
  • sloc: ansic: 11,662; sh: 8,936; makefile: 222
file content (133 lines) | stat: -rw-r--r-- 3,481 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133

#include <gmyth/gmyth_backendinfo.h>
#include <gmyth/gmyth_epg.h>

#include "common.h"

static          gboolean
test_epg_connection(GMythBackendInfo * backend_info)
{
    GMythEPG       *epg = gmyth_epg_new();
    gboolean        res = FALSE;

    res = gmyth_epg_connect(epg, backend_info);

    gmyth_epg_disconnect(epg);
    if (epg != NULL)
        g_object_unref(epg);

    return res;
}


static          gboolean
test_epg_get_channels(GMythBackendInfo * backend_info)
{
    GMythEPG       *epg = gmyth_epg_new();
    GList          *clist;
    gint            i,
                    length;

    if (!gmyth_epg_connect(epg, backend_info)) {
        return FALSE;
    }

    length = gmyth_epg_get_channel_list(epg, &clist);
    g_debug("==== %d channels found in the EPG ====\n", length);
    for (i = 0; i < length; i++) {
        GMythChannelInfo *channel_info =
            (GMythChannelInfo *) g_list_nth_data(clist, i);

        gmyth_channel_info_print(channel_info);
    }

    g_list_free(clist);
    gmyth_epg_disconnect(epg);
    if (epg != NULL)
        g_object_unref(epg);
}

static          gboolean
test_epg_get_channel_icon(GMythBackendInfo * backend_info)
{
    GMythEPG       *epg = gmyth_epg_new();
    GList          *clist;
    gint            i,
                    length;

    if (!gmyth_epg_connect(epg, backend_info)) {
        return FALSE;
    }

    length = gmyth_epg_get_channel_list(epg, &clist);
    g_debug("==== %d channels found in the EPG ====\n", length);
    for (i = 0; i < length; i++) {
        GMythChannelInfo *channel_info =
            (GMythChannelInfo *) g_list_nth_data(clist, i);

        if (gmyth_epg_channel_has_icon(epg, channel_info)) {
            gchar          *icon_name =
                g_strdup_printf("%s.jpg", channel_info->channel_name->str);
            guint8         *icon_data = NULL;
            guint           icon_length;

            g_debug("Channel %s has icon %s\n",
                    channel_info->channel_name->str,
                    channel_info->channel_icon->str);

            if (gmyth_epg_channel_get_icon
                (epg, channel_info, &icon_data, &icon_length)) {
                FILE           *outfile = fopen(icon_name, "w+");
                if (fwrite(icon_data, icon_length, 1, outfile) ==
                    icon_length)
                    g_debug("\tIcon saved as %s", icon_name);
                else
                    g_debug
                        ("\tError while downloading the file or writing it");

                g_free(icon_data);
            }
            g_free(icon_name);

        } else {
            g_debug("Channel %s does not have icon\n",
                    channel_info->channel_name->str);
        }
        gmyth_channel_info_print(channel_info);
    }

    g_list_free(clist);
    gmyth_epg_disconnect(epg);
    g_object_unref(epg);

    return TRUE;
}

int
main(int args, const char **argv)
{

    GMythBackendInfo *backend_info;
    g_type_init();
    g_thread_init(NULL);

    if (args < 2) {
        g_debug("Type %s myth://hostname:port/?mythconverg\n", argv[0]);
        return -1;
    }

    backend_info = gmyth_backend_info_new_with_uri(argv[1]);

    fprintf(stdout, SYNC_STRING);
    fflush(NULL);
    getchar();

    test_epg_connection(backend_info);
    test_epg_get_channels(backend_info);
    test_epg_get_channel_icon(backend_info);

    if (backend_info != NULL)
        g_object_unref(backend_info);

    return (0);
}