/** * Try decoding a stream, using the fallback plugin. */ static bool decoder_run_stream_fallback(struct decoder *decoder, struct input_stream *is) { const struct decoder_plugin *plugin; plugin = decoder_plugin_from_name("mad"); return plugin != NULL && plugin->stream_decode != NULL && decoder_stream_decode(plugin, decoder, is); }
int main(int argc, char **argv) { const char *decoder_name, *path; const struct decoder_plugin *plugin; struct tag *tag; bool empty; if (argc != 3) { g_printerr("Usage: read_tags DECODER FILE\n"); return 1; } decoder_name = argv[1]; path = argv[2]; input_stream_global_init(); decoder_plugin_init_all(); plugin = decoder_plugin_from_name(decoder_name); if (plugin == NULL) { g_printerr("No such decoder: %s\n", decoder_name); return 1; } tag = decoder_plugin_tag_dup(plugin, path); decoder_plugin_deinit_all(); input_stream_global_finish(); if (tag == NULL) { g_printerr("Failed to read tags\n"); return 1; } print_tag(tag); empty = tag_is_empty(tag); tag_free(tag); if (empty) { tag = tag_ape_load(path); if (tag == NULL) tag = tag_id3_load(path); if (tag != NULL) { print_tag(tag); tag_free(tag); } } return 0; }
int main(int argc, char **argv) { GError *error = NULL; const char *decoder_name; struct decoder decoder; if (argc != 3) { g_printerr("Usage: run_decoder DECODER URI >OUT\n"); return 1; } decoder_name = argv[1]; decoder.uri = argv[2]; g_log_set_default_handler(my_log_func, NULL); tag_pool_init(); if (!input_stream_global_init(&error)) { g_warning("%s", error->message); g_error_free(error); return 2; } decoder_plugin_init_all(); decoder.plugin = decoder_plugin_from_name(decoder_name); if (decoder.plugin == NULL) { g_printerr("No such decoder: %s\n", decoder_name); return 1; } decoder.initialized = false; if (decoder.plugin->file_decode != NULL) { decoder_plugin_file_decode(decoder.plugin, &decoder, decoder.uri); } else if (decoder.plugin->stream_decode != NULL) { struct input_stream *is = input_stream_open(decoder.uri, &error); if (is == NULL) { if (error != NULL) { g_warning("%s", error->message); g_error_free(error); } else g_printerr("input_stream_open() failed\n"); return 1; } decoder_plugin_stream_decode(decoder.plugin, &decoder, is); input_stream_close(is); } else { g_printerr("Decoder plugin is not usable\n"); return 1; } decoder_plugin_deinit_all(); input_stream_global_finish(); if (!decoder.initialized) { g_printerr("Decoding failed\n"); return 1; } tag_pool_deinit(); return 0; }
int main(int argc, char **argv) { GError *error = NULL; const char *decoder_name, *path; const struct decoder_plugin *plugin; struct tag *tag; bool empty; #ifdef HAVE_LOCALE_H /* initialize locale */ setlocale(LC_CTYPE,""); #endif if (argc != 3) { g_printerr("Usage: read_tags DECODER FILE\n"); return 1; } decoder_name = argv[1]; path = argv[2]; tag_pool_init(); if (!input_stream_global_init(&error)) { g_warning("%s", error->message); g_error_free(error); return 2; } decoder_plugin_init_all(); plugin = decoder_plugin_from_name(decoder_name); if (plugin == NULL) { g_printerr("No such decoder: %s\n", decoder_name); return 1; } tag = decoder_plugin_tag_dup(plugin, path); if (tag == NULL && plugin->stream_tag != NULL) { struct input_stream *is = input_stream_open(path, &error); if (is == NULL) { g_printerr("Failed to open %s: %s\n", path, error->message); g_error_free(error); return 1; } tag = decoder_plugin_stream_tag(plugin, is); input_stream_close(is); } decoder_plugin_deinit_all(); input_stream_global_finish(); if (tag == NULL) { g_printerr("Failed to read tags\n"); return 1; } print_tag(tag); empty = tag_is_empty(tag); tag_free(tag); if (empty) { tag = tag_ape_load(path); if (tag == NULL) tag = tag_id3_load(path); if (tag != NULL) { print_tag(tag); tag_free(tag); } } tag_pool_deinit(); return 0; }