move more tag processing into plugin_common
authorJosh Coalson <jcoalson@users.sourceforce.net>
Fri, 30 Aug 2002 05:41:56 +0000 (05:41 +0000)
committerJosh Coalson <jcoalson@users.sourceforce.net>
Fri, 30 Aug 2002 05:41:56 +0000 (05:41 +0000)
src/plugin_xmms/wrap_id3.c

index e9ecb42..cb69790 100644 (file)
 #include "charset.h"
 #include "configure.h"
 
-static FLAC__bool local__get_id3v1_tag_as_canonical(const char *filename, FLAC_Plugin__CanonicalTag *tag);
+/*
+ * Function local__extname (filename)
+ *
+ *    Return pointer within filename to its extenstion, or NULL if
+ *    filename has no extension.
+ *
+ */
+static char *local__extname(const char *filename)
+{
+       char *ext = strrchr(filename, '.');
 
-static char *local__extname(const char *filename);
-static char* local__getstr(char* str);
-static int local__getnum(char* str);
+       if (ext != NULL)
+               ++ext;
+
+       return ext;
+}
+
+static char *local__getstr(char* str)
+{
+       if (str && strlen(str) > 0)
+               return str;
+       return NULL;
+}
 
-static int local__vcentry_matches(const char *field_name, const FLAC__StreamMetadata_VorbisComment_Entry *entry);
-static void local__vcentry_parse_value(const FLAC__StreamMetadata_VorbisComment_Entry *entry, char **dest);
+static int local__getnum(char* str)
+{
+       if (str && strlen(str) > 0)
+               return atoi(str);
+       return 0;
+}
 
 /*
  * Function flac_format_song_title (tag, filename)
@@ -54,56 +76,11 @@ char *flac_format_song_title(char *filename)
 {
        char *ret = NULL;
        TitleInput *input = NULL;
-       FLAC_Plugin__CanonicalTag tag, id3v1_tag, id3v2_tag;
+       FLAC_Plugin__CanonicalTag tag;
 
        FLAC_plugin__canonical_tag_init(&tag);
-       FLAC_plugin__canonical_tag_init(&id3v1_tag);
-       FLAC_plugin__canonical_tag_init(&id3v2_tag);
-
-       /* first, parse vorbis comments if they exist */
-       {
-               FLAC__Metadata_SimpleIterator *iterator = FLAC__metadata_simple_iterator_new();
-               if(0 != iterator) {
-                       FLAC__bool got_vorbis_comments = false;
-                       do {
-                               if(FLAC__metadata_simple_iterator_get_block_type(iterator) == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
-                                       FLAC__StreamMetadata *block = FLAC__metadata_simple_iterator_get_block(iterator);
-                                       if(0 != block) {
-                                               unsigned i;
-                                               const FLAC__StreamMetadata_VorbisComment *vc = &block->data.vorbis_comment;
-                                               for(i = 0; i < vc->num_comments; i++) {
-                                                       if(local__vcentry_matches("artist", &vc->comments[i]))
-                                                               local__vcentry_parse_value(&vc->comments[i], &tag.composer);
-                                                       else if(local__vcentry_matches("performer", &vc->comments[i]))
-                                                               local__vcentry_parse_value(&vc->comments[i], &tag.performer);
-                                                       else if(local__vcentry_matches("album", &vc->comments[i]))
-                                                               local__vcentry_parse_value(&vc->comments[i], &tag.album);
-                                                       else if(local__vcentry_matches("title", &vc->comments[i]))
-                                                               local__vcentry_parse_value(&vc->comments[i], &tag.title);
-                                                       else if(local__vcentry_matches("tracknumber", &vc->comments[i]))
-                                                               local__vcentry_parse_value(&vc->comments[i], &tag.track_number);
-                                                       else if(local__vcentry_matches("genre", &vc->comments[i]))
-                                                               local__vcentry_parse_value(&vc->comments[i], &tag.genre);
-                                                       else if(local__vcentry_matches("description", &vc->comments[i]))
-                                                               local__vcentry_parse_value(&vc->comments[i], &tag.comment);
-                                               }
-                                               FLAC__metadata_object_delete(block);
-                                               got_vorbis_comments = true;
-                                       }
-                               }
-                       } while (!got_vorbis_comments && FLAC__metadata_simple_iterator_next(iterator));
-                       FLAC__metadata_simple_iterator_delete(iterator);
-               }
-       }
-
-       (void)FLAC_plugin__id3v2_tag_get(filename, &id3v2_tag);
-       (void)local__get_id3v1_tag_as_canonical(filename, &id3v1_tag);
 
-       XMMS_NEW_TITLEINPUT(input);
-
-       /* 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_get_combined(filename, &tag);
 
        if(flac_cfg.convert_char_set) {
                convert_from_file_to_user_in_place(&tag.title);
@@ -118,6 +95,8 @@ char *flac_format_song_title(char *filename)
                convert_from_file_to_user_in_place(&tag.comment);
        }
 
+       XMMS_NEW_TITLEINPUT(input);
+
        input->performer = local__getstr(tag.performer);
        input->album_name = local__getstr(tag.album);
        input->track_name = local__getstr(tag.title);
@@ -142,73 +121,5 @@ char *flac_format_song_title(char *filename)
        }
 
        FLAC_plugin__canonical_tag_clear(&tag);
-       FLAC_plugin__canonical_tag_clear(&id3v1_tag);
-       FLAC_plugin__canonical_tag_clear(&id3v2_tag);
        return ret;
 }
-
-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;
-}
-
-/*
- * Function local__extname (filename)
- *
- *    Return pointer within filename to its extenstion, or NULL if
- *    filename has no extension.
- *
- */
-char *local__extname(const char *filename)
-{
-       char *ext = strrchr(filename, '.');
-
-       if (ext != NULL)
-               ++ext;
-
-       return ext;
-}
-
-char* local__getstr(char* str)
-{
-       if (str && strlen(str) > 0)
-               return str;
-       return NULL;
-}
-
-int local__getnum(char* str)
-{
-       if (str && strlen(str) > 0)
-               return atoi(str);
-       return 0;
-}
-
-int local__vcentry_matches(const char *field_name, const FLAC__StreamMetadata_VorbisComment_Entry *entry)
-{
-       const FLAC__byte *eq = memchr(entry->entry, '=', entry->length);
-       const unsigned field_name_length = strlen(field_name);
-       return (0 != eq && (unsigned)(eq-entry->entry) == field_name_length && 0 == strncasecmp(field_name, entry->entry, field_name_length));
-}
-
-void local__vcentry_parse_value(const FLAC__StreamMetadata_VorbisComment_Entry *entry, char **dest)
-{
-       const FLAC__byte *eq = memchr(entry->entry, '=', entry->length);
-
-       if(0 == eq)
-               return;
-       else {
-               const unsigned value_length = entry->length - (unsigned)((++eq) - entry->entry);
-
-               *dest = g_malloc(value_length + 1);
-               if(0 != *dest) {
-                       memcpy(*dest, eq, value_length);
-                       (*dest)[value_length] = '\0';
-               }
-       }
-}