2 * Copyright (C) 2003-2010 The Music Player Daemon Project
3 * http://www.musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "input_init.h"
22 #include "input_stream.h"
28 #include "archive_list.h"
36 my_log_func(const gchar
*log_domain
, G_GNUC_UNUSED GLogLevelFlags log_level
,
37 const gchar
*message
, G_GNUC_UNUSED gpointer user_data
)
39 if (log_domain
!= NULL
)
40 g_printerr("%s: %s\n", log_domain
, message
);
42 g_printerr("%s\n", message
);
46 dump_input_stream(struct input_stream
*is
)
53 /* wait until the stream becomes ready */
56 int ret
= input_stream_buffer(is
, &error
);
59 g_warning("%s", error
->message
);
65 /* nothing was buffered - wait */
72 g_printerr("MIME type: %s\n", is
->mime
);
74 /* read data and tags from the stream */
76 while (!input_stream_eof(is
)) {
77 struct tag
*tag
= input_stream_tag(is
);
79 g_printerr("Received a tag:\n");
80 tag_save(stderr
, tag
);
84 num_read
= input_stream_read(is
, buffer
, sizeof(buffer
),
88 g_warning("%s", error
->message
);
95 num_written
= write(1, buffer
, num_read
);
103 int main(int argc
, char **argv
)
105 GError
*error
= NULL
;
106 struct input_stream
*is
;
110 g_printerr("Usage: run_input URI\n");
114 /* initialize GLib */
117 g_log_set_default_handler(my_log_func
, NULL
);
122 config_global_init();
124 #ifdef ENABLE_ARCHIVE
125 archive_plugin_init_all();
128 if (!input_stream_global_init(&error
)) {
129 g_warning("%s", error
->message
);
134 /* open the stream and dump it */
136 is
= input_stream_open(argv
[1], &error
);
138 ret
= dump_input_stream(is
);
139 input_stream_close(is
);
142 g_warning("%s", error
->message
);
145 g_printerr("input_stream_open() failed\n");
149 /* deinitialize everything */
151 input_stream_global_finish();
153 #ifdef ENABLE_ARCHIVE
154 archive_plugin_deinit_all();
157 config_global_finish();