add function for getting a combined tag
authorJosh Coalson <jcoalson@users.sourceforce.net>
Fri, 30 Aug 2002 05:43:45 +0000 (05:43 +0000)
committerJosh Coalson <jcoalson@users.sourceforce.net>
Fri, 30 Aug 2002 05:43:45 +0000 (05:43 +0000)
src/plugin_common/canonical_tag.c
src/plugin_common/canonical_tag.h

index e476352..03adf49 100644 (file)
 #include <stdio.h>
 
 #include "canonical_tag.h"
+#include "id3v2.h"
+#include "vorbiscomment.h"
 #include "FLAC/assert.h"
+#include "FLAC/metadata.h"
 
 static void local__safe_free(void *object)
 {
@@ -44,6 +47,17 @@ static void local__copy_field(char **dest, const char *src, unsigned n)
                *dest = 0;
 }
 
+static FLAC__bool local__get_id3v1_tag_as_canonical(const char *filename, FLAC_Plugin__CanonicalTag *tag)
+{
+       FLAC_Plugin__Id3v1_Tag id3v1_tag;
+
+       if(FLAC_plugin__id3v1_tag_get(filename, &id3v1_tag)) {
+               FLAC_plugin__canonical_tag_convert_from_id3v1(tag, &id3v1_tag);
+               return true;
+       }
+       return false;
+}
+
 FLAC_Plugin__CanonicalTag *FLAC_plugin__canonical_tag_new()
 {
        FLAC_Plugin__CanonicalTag *object = (FLAC_Plugin__CanonicalTag*)malloc(sizeof(FLAC_Plugin__CanonicalTag));
@@ -133,3 +147,23 @@ void FLAC_plugin__canonical_tag_convert_from_id3v1(FLAC_Plugin__CanonicalTag *ob
 
        object->genre = strdup(FLAC_plugin__id3v1_tag_get_genre_as_string(id3v1_tag->genre));
 }
+
+void FLAC_plugin__canonical_tag_get_combined(const char *filename, FLAC_Plugin__CanonicalTag *tag)
+{
+       FLAC_Plugin__CanonicalTag id3v1_tag, id3v2_tag;
+
+       FLAC_plugin__vorbiscomment_get(filename, tag);
+
+       FLAC_plugin__canonical_tag_init(&id3v2_tag);
+       (void)FLAC_plugin__id3v2_tag_get(filename, &id3v2_tag);
+
+       FLAC_plugin__canonical_tag_init(&id3v1_tag);
+       (void)local__get_id3v1_tag_as_canonical(filename, &id3v1_tag);
+
+       /* merge tags, preferring, in order: vorbis comments, id3v2, id3v1 */
+       FLAC_plugin__canonical_tag_merge(tag, &id3v2_tag);
+       FLAC_plugin__canonical_tag_merge(tag, &id3v1_tag);
+
+       FLAC_plugin__canonical_tag_clear(&id3v1_tag);
+       FLAC_plugin__canonical_tag_clear(&id3v2_tag);
+}
index fd1e1e2..d0c57fd 100644 (file)
@@ -47,4 +47,9 @@ void FLAC_plugin__canonical_tag_merge(FLAC_Plugin__CanonicalTag *dest, FLAC_Plug
 
 void FLAC_plugin__canonical_tag_convert_from_id3v1(FLAC_Plugin__CanonicalTag *, const FLAC_Plugin__Id3v1_Tag *);
 
+/* Returns a merged tag based on any Vorbis comments, id3v2 tag, and id3v1.
+ * In case of overlaps the preceding precedence applies.
+ */
+void FLAC_plugin__canonical_tag_get_combined(const char *filename, FLAC_Plugin__CanonicalTag *tag);
+
 #endif