aboutsummaryrefslogtreecommitdiffstats
path: root/src/cue
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-04-01 15:36:24 +0200
committerMax Kellermann <max@duempel.org>2009-04-01 15:36:24 +0200
commita3823c7657e486b371577e669c3171becb1678b7 (patch)
tree7e04d76f368c29c4cdbb3b12017d16664b3a335a /src/cue
parent85cecbddde93aa4bcb7821473ea95ccad150ce4c (diff)
parent4bfbdfe5c522011a695c804cfccf190eb4500e9a (diff)
downloadmpd-a3823c7657e486b371577e669c3171becb1678b7.tar.gz
mpd-a3823c7657e486b371577e669c3171becb1678b7.tar.xz
mpd-a3823c7657e486b371577e669c3171becb1678b7.zip
Merge branch 'master' of git://git.musicpd.org/jrk/mpd
Diffstat (limited to 'src/cue')
-rw-r--r--src/cue/cue_tag.c276
-rw-r--r--src/cue/cue_tag.h20
2 files changed, 296 insertions, 0 deletions
diff --git a/src/cue/cue_tag.c b/src/cue/cue_tag.c
new file mode 100644
index 000000000..ce8202a81
--- /dev/null
+++ b/src/cue/cue_tag.c
@@ -0,0 +1,276 @@
+#include "cue_tag.h"
+
+static struct tag*
+cue_tag_cd(struct Cdtext* cdtext, struct Rem* rem)
+{
+ char* tmp = NULL;
+ struct tag* tag = NULL;
+
+ //if (cdtext == NULL)
+ //return NULL;
+
+ tag = tag_new();
+
+ tag_begin_add(tag);
+
+ { /* TAG_ITEM_ALBUM_ARTIST */
+ if ((tmp = cdtext_get(PTI_PERFORMER, cdtext)) != NULL)
+ tag_add_item(tag, TAG_ITEM_ALBUM_ARTIST, tmp);
+
+ else if ((tmp = cdtext_get(PTI_SONGWRITER, cdtext)) != NULL)
+ tag_add_item(tag, TAG_ITEM_ALBUM_ARTIST, tmp);
+
+ else if ((tmp = cdtext_get(PTI_COMPOSER, cdtext)) != NULL)
+ tag_add_item(tag, TAG_ITEM_ALBUM_ARTIST, tmp);
+
+ else if ((tmp = cdtext_get(PTI_ARRANGER, cdtext)) != NULL)
+ tag_add_item(tag, TAG_ITEM_ALBUM_ARTIST, tmp);
+ /* TAG_ITEM_ALBUM_ARTIST */ }
+
+ { /* TAG_ITEM_ARTIST */
+ if ((tmp = cdtext_get(PTI_PERFORMER, cdtext)) != NULL)
+ tag_add_item(tag, TAG_ITEM_ARTIST, tmp);
+
+ else if ((tmp = cdtext_get(PTI_SONGWRITER, cdtext)) != NULL)
+ tag_add_item(tag, TAG_ITEM_ARTIST, tmp);
+
+ else if ((tmp = cdtext_get(PTI_COMPOSER, cdtext)) != NULL)
+ tag_add_item(tag, TAG_ITEM_ARTIST, tmp);
+
+ else if ((tmp = cdtext_get(PTI_ARRANGER, cdtext)) != NULL)
+ tag_add_item(tag, TAG_ITEM_ARTIST, tmp);
+ /* TAG_ITEM_ARTIST */ }
+
+ /* TAG_ITEM_PERFORMER */
+ if ((tmp = cdtext_get(PTI_PERFORMER, cdtext)) != NULL)
+ tag_add_item(tag, TAG_ITEM_PERFORMER, tmp);
+
+ /* TAG_ITEM_COMPOSER */
+ if ((tmp = cdtext_get(PTI_COMPOSER, cdtext)) != NULL)
+ tag_add_item(tag, TAG_ITEM_COMPOSER, tmp);
+
+ /* TAG_ITEM_ALBUM */
+ if ((tmp = cdtext_get(PTI_TITLE, cdtext)) != NULL)
+ tag_add_item(tag, TAG_ITEM_ALBUM, tmp);
+
+ /* TAG_ITEM_GENRE */
+ if ((tmp = cdtext_get(PTI_GENRE, cdtext)) != NULL)
+ tag_add_item(tag, TAG_ITEM_GENRE, tmp);
+
+ /* TAG_ITEM_DATE */
+ if ((tmp = rem_get(REM_DATE, rem)) != NULL)
+ tag_add_item(tag, TAG_ITEM_DATE, tmp);
+
+ /* TAG_ITEM_COMMENT */
+ if ((tmp = cdtext_get(PTI_MESSAGE, cdtext)) != NULL)
+ tag_add_item(tag, TAG_ITEM_COMMENT, tmp);
+
+ /* TAG_ITEM_DISC */
+ if ((tmp = cdtext_get(PTI_DISC_ID, cdtext)) != NULL)
+ tag_add_item(tag, TAG_ITEM_DISC, tmp);
+
+ /* stream name, usually empty
+ * tag_add_item(tag, TAG_ITEM_NAME,);
+ */
+
+ /* REM MUSICBRAINZ entry?
+ tag_add_item(tag, TAG_MUSICBRAINZ_ARTISTID,);
+ tag_add_item(tag, TAG_MUSICBRAINZ_ALBUMID,);
+ tag_add_item(tag, TAG_MUSICBRAINZ_ALBUMARTISTID,);
+ tag_add_item(tag, TAG_MUSICBRAINZ_TRACKID,);
+ */
+
+ tag_end_add(tag);
+
+ if (tag != NULL)
+ {
+ if (tag_is_empty(tag))
+ {
+ tag_free(tag);
+ return NULL;
+ }
+ else
+ return tag;
+ }
+ else
+ return NULL;
+}
+
+static struct tag*
+cue_tag_track(struct Cdtext* cdtext, struct Rem* rem)
+{
+ char* tmp = NULL;
+ struct tag* tag = NULL;
+
+ //if (cdtext == NULL)
+ //return NULL;
+
+ tag = tag_new();
+
+ tag_begin_add(tag);
+
+ { /* TAG_ITEM_ARTIST */
+ if ((tmp = cdtext_get(PTI_PERFORMER, cdtext)) != NULL)
+ tag_add_item(tag, TAG_ITEM_ARTIST, tmp);
+
+ else if ((tmp = cdtext_get(PTI_SONGWRITER, cdtext)) != NULL)
+ tag_add_item(tag, TAG_ITEM_ARTIST, tmp);
+
+ else if ((tmp = cdtext_get(PTI_COMPOSER, cdtext)) != NULL)
+ tag_add_item(tag, TAG_ITEM_ARTIST, tmp);
+
+ else if ((tmp = cdtext_get(PTI_ARRANGER, cdtext)) != NULL)
+ tag_add_item(tag, TAG_ITEM_ARTIST, tmp);
+ /* TAG_ITEM_ARTIST */ }
+
+ /* TAG_ITEM_TITLE */
+ if ((tmp = cdtext_get(PTI_TITLE, cdtext)) != NULL)
+ tag_add_item(tag, TAG_ITEM_TITLE, tmp);
+
+ /* TAG_ITEM_GENRE */
+ if ((tmp = cdtext_get(PTI_GENRE, cdtext)) != NULL)
+ tag_add_item(tag, TAG_ITEM_GENRE, tmp);
+
+ /* TAG_ITEM_DATE */
+ if ((tmp = rem_get(REM_DATE, rem)) != NULL)
+ tag_add_item(tag, TAG_ITEM_DATE, tmp);
+
+ /* TAG_ITEM_COMPOSER */
+ if ((tmp = cdtext_get(PTI_COMPOSER, cdtext)) != NULL)
+ tag_add_item(tag, TAG_ITEM_COMPOSER, tmp);
+
+ /* TAG_ITEM_PERFORMER */
+ if ((tmp = cdtext_get(PTI_PERFORMER, cdtext)) != NULL)
+ tag_add_item(tag, TAG_ITEM_PERFORMER, tmp);
+
+ /* TAG_ITEM_COMMENT */
+ if ((tmp = cdtext_get(PTI_MESSAGE, cdtext)) != NULL)
+ tag_add_item(tag, TAG_ITEM_COMMENT, tmp);
+
+ /* TAG_ITEM_DISC */
+ if ((tmp = cdtext_get(PTI_DISC_ID, cdtext)) != NULL)
+ tag_add_item(tag, TAG_ITEM_DISC, tmp);
+
+ tag_end_add(tag);
+
+ if (tag != NULL)
+ {
+ if (tag_is_empty(tag))
+ {
+ tag_free(tag);
+ return NULL;
+ }
+ else
+ return tag;
+ }
+ else
+ return NULL;
+}
+
+struct tag*
+cue_tag_file( FILE* fp,
+ const unsigned int tnum)
+{
+ struct tag* cd_tag = NULL;
+ struct tag* track_tag = NULL;
+ struct tag* merge_tag = NULL;
+ struct Cd* cd = NULL;
+
+ if (tnum > 256)
+ return NULL;
+
+ if (fp == NULL)
+ return NULL;
+ else
+ cd = cue_parse_file(fp);
+
+ if (cd == NULL)
+ return NULL;
+ else
+ {
+ /* tag from CDtext info */
+ cd_tag = cue_tag_cd( cd_get_cdtext(cd),
+ cd_get_rem(cd));
+
+ /* tag from TRACKtext info */
+ track_tag = cue_tag_track( track_get_cdtext( cd_get_track(cd, tnum)),
+ track_get_rem( cd_get_track(cd, tnum)));
+
+ cd_delete(cd);
+ }
+
+ if ((cd_tag != NULL) && (track_tag != NULL))
+ {
+ merge_tag = tag_merge(cd_tag, track_tag);
+ tag_free(cd_tag);
+ tag_free(track_tag);
+ return merge_tag;
+ }
+
+ else if (cd_tag != NULL)
+ {
+ return cd_tag;
+ }
+
+ else if (track_tag != NULL)
+ {
+ return track_tag;
+ }
+
+ else
+ return NULL;
+}
+
+struct tag*
+cue_tag_string( char* str,
+ const unsigned int tnum)
+{
+ struct tag* cd_tag = NULL;
+ struct tag* track_tag = NULL;
+ struct tag* merge_tag = NULL;
+ struct Cd* cd = NULL;
+
+ if (tnum > 256)
+ return NULL;
+
+ if (str == NULL)
+ return NULL;
+ else
+ cd = cue_parse_string(str);
+
+ if (cd == NULL)
+ return NULL;
+ else
+ {
+ /* tag from CDtext info */
+ cd_tag = cue_tag_cd( cd_get_cdtext(cd),
+ cd_get_rem(cd));
+
+ /* tag from TRACKtext info */
+ track_tag = cue_tag_track( track_get_cdtext( cd_get_track(cd, tnum)),
+ track_get_rem( cd_get_track(cd, tnum)));
+
+ cd_delete(cd);
+ }
+
+ if ((cd_tag != NULL) && (track_tag != NULL))
+ {
+ merge_tag = tag_merge(cd_tag, track_tag);
+ tag_free(cd_tag);
+ tag_free(track_tag);
+ return merge_tag;
+ }
+
+ else if (cd_tag != NULL)
+ {
+ return cd_tag;
+ }
+
+ else if (track_tag != NULL)
+ {
+ return track_tag;
+ }
+
+ else
+ return NULL;
+}
diff --git a/src/cue/cue_tag.h b/src/cue/cue_tag.h
new file mode 100644
index 000000000..adc4c466e
--- /dev/null
+++ b/src/cue/cue_tag.h
@@ -0,0 +1,20 @@
+#ifndef MPD_CUE_TAG_H
+#define MPD_CUE_TAG_H
+
+#include "config.h"
+
+#ifdef HAVE_CUE /* libcue */
+
+#include <libcue/libcue.h>
+#include "../tag.h"
+
+struct tag*
+cue_tag_file( FILE*,
+ const unsigned int);
+
+struct tag*
+cue_tag_string( char*,
+ const unsigned int);
+
+#endif /* libcue */
+#endif