struct tag *tag_id3_import(struct id3_tag * tag) { struct tag *ret = tag_new(); tag_id3_import_text(ret, tag, ID3_FRAME_ARTIST, TAG_ARTIST); tag_id3_import_text(ret, tag, ID3_FRAME_ALBUM_ARTIST, TAG_ALBUM_ARTIST); tag_id3_import_text(ret, tag, ID3_FRAME_ARTIST_SORT, TAG_ARTIST_SORT); tag_id3_import_text(ret, tag, ID3_FRAME_ALBUM_ARTIST_SORT, TAG_ALBUM_ARTIST_SORT); tag_id3_import_text(ret, tag, ID3_FRAME_TITLE, TAG_TITLE); tag_id3_import_text(ret, tag, ID3_FRAME_ALBUM, TAG_ALBUM); tag_id3_import_text(ret, tag, ID3_FRAME_TRACK, TAG_TRACK); tag_id3_import_text(ret, tag, ID3_FRAME_YEAR, TAG_DATE); tag_id3_import_text(ret, tag, ID3_FRAME_GENRE, TAG_GENRE); tag_id3_import_text(ret, tag, ID3_FRAME_COMPOSER, TAG_COMPOSER); tag_id3_import_text(ret, tag, "TPE3", TAG_PERFORMER); tag_id3_import_text(ret, tag, "TPE4", TAG_PERFORMER); tag_id3_import_comment(ret, tag, ID3_FRAME_COMMENT, TAG_COMMENT); tag_id3_import_text(ret, tag, ID3_FRAME_DISC, TAG_DISC); tag_id3_import_musicbrainz(ret, tag); tag_id3_import_ufid(ret, tag); if (tag_is_empty(ret)) { tag_free(ret); ret = NULL; } return ret; }
struct tag *tag_id3_import(struct id3_tag * tag) { struct tag *ret = tag_new(); getID3Info(tag, ID3_FRAME_ARTIST, TAG_ITEM_ARTIST, ret); getID3Info(tag, ID3_FRAME_ALBUM_ARTIST, TAG_ITEM_ALBUM_ARTIST, ret); getID3Info(tag, ID3_FRAME_ALBUM_ARTIST_SORT, TAG_ITEM_ALBUM_ARTIST, ret); getID3Info(tag, ID3_FRAME_TITLE, TAG_ITEM_TITLE, ret); getID3Info(tag, ID3_FRAME_ALBUM, TAG_ITEM_ALBUM, ret); getID3Info(tag, ID3_FRAME_TRACK, TAG_ITEM_TRACK, ret); getID3Info(tag, ID3_FRAME_YEAR, TAG_ITEM_DATE, ret); getID3Info(tag, ID3_FRAME_GENRE, TAG_ITEM_GENRE, ret); getID3Info(tag, ID3_FRAME_COMPOSER, TAG_ITEM_COMPOSER, ret); getID3Info(tag, ID3_FRAME_PERFORMER, TAG_ITEM_PERFORMER, ret); getID3Info(tag, ID3_FRAME_COMMENT, TAG_ITEM_COMMENT, ret); getID3Info(tag, ID3_FRAME_DISC, TAG_ITEM_DISC, ret); tag_id3_import_musicbrainz(ret, tag); if (tag_is_empty(ret)) { tag_free(ret); ret = NULL; } return ret; }
struct tag * vorbis_comments_to_tag(char **comments) { struct tag *tag = tag_new(); vorbis_comments_scan(comments, &add_tag_handler, tag); if (tag_is_empty(tag)) { tag_free(tag); tag = NULL; } return tag; }
static void flac_decoder_loop(struct flac_data *data, FLAC__StreamDecoder *flac_dec, FLAC__uint64 t_start, FLAC__uint64 t_end) { struct decoder *decoder = data->decoder; enum decoder_command cmd; data->first_frame = t_start; while (true) { if (data->tag != NULL && !tag_is_empty(data->tag)) { cmd = decoder_tag(data->decoder, data->input_stream, data->tag); tag_free(data->tag); data->tag = tag_new(); } else cmd = decoder_get_command(decoder); if (cmd == DECODE_COMMAND_SEEK) { FLAC__uint64 seek_sample = t_start + decoder_seek_where(decoder) * data->audio_format.sample_rate; if (seek_sample >= t_start && (t_end == 0 || seek_sample <= t_end) && FLAC__stream_decoder_seek_absolute(flac_dec, seek_sample)) { data->next_frame = seek_sample; data->position = 0; decoder_command_finished(decoder); } else decoder_seek_error(decoder); } else if (cmd == DECODE_COMMAND_STOP || FLAC__stream_decoder_get_state(flac_dec) == FLAC__STREAM_DECODER_END_OF_STREAM) break; if (t_end != 0 && data->next_frame >= t_end) /* end of this sub track */ break; if (!FLAC__stream_decoder_process_single(flac_dec)) { cmd = decoder_get_command(decoder); if (cmd != DECODE_COMMAND_SEEK) break; } } if (cmd != DECODE_COMMAND_STOP) { flacPrintErroredState(FLAC__stream_decoder_get_state(flac_dec)); FLAC__stream_decoder_finish(flac_dec); } }
bool song_file_update(struct song *song) { const char *suffix; char *path_fs; const struct decoder_plugin *plugin; struct stat st; assert(song_is_file(song)); /* check if there's a suffix and a plugin */ suffix = uri_get_suffix(song->url); if (suffix == NULL) return false; plugin = decoder_plugin_from_suffix(suffix, false); 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 { song->tag = plugin->tag_dup(path_fs); if (song->tag != NULL) break; plugin = decoder_plugin_from_suffix(suffix, true); } while (plugin != NULL); 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) { 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; }
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; GMutex *mutex = NULL; GCond *cond; #if !GCC_CHECK_VERSION(4, 2) /* work around "may be used uninitialized in this function" false positive */ cond = NULL; #endif do { /* load file tag */ song->tag = tag_new(); if (decoder_plugin_scan_file(plugin, path_fs, &full_tag_handler, song->tag)) break; tag_free(song->tag); song->tag = NULL; /* fall back to stream tag */ if (plugin->scan_stream != NULL) { /* open the input_stream (if not already open) */ if (is == NULL) { mutex = g_mutex_new(); cond = g_cond_new(); is = input_stream_open(path_fs, mutex, cond, NULL); } /* now try the stream_tag() method */ if (is != NULL) { song->tag = tag_new(); if (decoder_plugin_scan_stream(plugin, is, &full_tag_handler, song->tag)) break; tag_free(song->tag); song->tag = NULL; input_stream_lock_seek(is, 0, SEEK_SET, NULL); } } plugin = decoder_plugin_from_suffix(suffix, plugin); } while (plugin != NULL); if (is != NULL) input_stream_close(is); if (mutex != NULL) { g_cond_free(cond); g_mutex_free(mutex); } if (song->tag != NULL && tag_is_empty(song->tag)) tag_scan_fallback(path_fs, &full_tag_handler, song->tag); g_free(path_fs); return song->tag != NULL; }