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; }
bool song_file_update(struct song *song) { const char *suffix; char *path_fs; const struct decoder_plugin *plugin; struct stat st; struct input_stream *is = NULL; assert(song_is_file(song)); /* check if there's a suffix and a plugin */ suffix = uri_get_suffix(song->uri); if (suffix == NULL) return false; plugin = decoder_plugin_from_suffix(suffix, NULL); if (plugin == NULL) return false; path_fs = map_song_fs(song); if (path_fs == NULL) return false; if (song->tag != NULL) { tag_free(song->tag); song->tag = NULL; } if (stat(path_fs, &st) < 0 || !S_ISREG(st.st_mode)) { g_free(path_fs); return false; } song->mtime = st.st_mtime; do { /* load file tag */ song->tag = decoder_plugin_tag_dup(plugin, path_fs); if (song->tag != NULL) break; /* fall back to stream tag */ if (plugin->stream_tag != NULL) { /* open the input_stream (if not already open) */ if (is == NULL) is = input_stream_open(path_fs, NULL); /* now try the stream_tag() method */ if (is != NULL) { song->tag = decoder_plugin_stream_tag(plugin, is); if (song->tag != NULL) break; input_stream_seek(is, 0, SEEK_SET, NULL); } } plugin = decoder_plugin_from_suffix(suffix, plugin); } while (plugin != NULL); if (is != NULL) input_stream_close(is); if (song->tag != NULL && tag_is_empty(song->tag)) song->tag = tag_fallback(path_fs, song->tag); g_free(path_fs); return song->tag != NULL; }
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; }