Discussion:
[PATCH] pass MusicBrainz Track ID to status_display_programs
Johannes Weißl
2011-09-03 17:55:02 UTC
Permalink
The track ID is an optional parameter for the AudioScrobbler protocol,
otherwise status_display_programs have to read this themselves from the
audio files.
---
comment.c | 2 ++
id3.c | 20 ++++++++++++++++++++
id3.h | 1 +
ui_curses.c | 3 ++-
4 files changed, 25 insertions(+), 1 deletions(-)

diff --git a/comment.c b/comment.c
index e72a7eb..b2795a5 100644
--- a/comment.c
+++ b/comment.c
@@ -165,6 +165,7 @@ static const char *interesting[] = {
"replaygain_track_peak",
"replaygain_album_gain",
"replaygain_album_peak",
+ "musicbrainz_trackid",
"comment",
NULL
};
@@ -181,6 +182,7 @@ static struct {
{ "WM/ArtistSortOrder", "artistsort" },
{ "WM/AlbumArtistSortOrder", "albumartistsort" },
{ "WM/OriginalReleaseYear", "originaldate" },
+ { "MusicBrainz Track Id", "musicbrainz_trackid" },
{ NULL, NULL }
};

diff --git a/id3.c b/id3.c
index 73d79b3..e5c8f05 100644
--- a/id3.c
+++ b/id3.c
@@ -254,6 +254,7 @@ const char * const id3_key_names[NUM_ID3_KEYS] = {
"replaygain_album_gain",
"replaygain_album_peak",
"comment",
+ "musicbrainz_trackid",
};

static int utf16_is_lsurrogate(uchar uch)
@@ -935,6 +936,22 @@ static void decode_rva2(struct id3tag *id3, const char *buf, int len)
id3_debug("gain %s, peak %s\n", gain_str, peak_str ? peak_str : "none");
}

+static void decode_ufid(struct id3tag *id3, const char *buf, int len)
+{
+ char *ufid;
+ size_t ufid_len = len - 22 - 1;
+
+ if (strcmp(buf, "http://musicbrainz.org") != 0)
+ return;
+
+ ufid = xnew(char, ufid_len + 1);
+ memmove(ufid, buf + len - ufid_len, ufid_len);
+ ufid[ufid_len] = '\0';
+
+ id3_debug("%s: %s\n", buf, ufid);
+ add_v2(id3, ID3_MUSICBRAINZ_TRACKID, ufid);
+}
+

static void v2_add_frame(struct id3tag *id3, struct v2_frame_header *fh, const char *buf)
{
@@ -945,6 +962,9 @@ static void v2_add_frame(struct id3tag *id3, struct v2_frame_header *fh, const c
if (!strncmp(fh->id, "RVA2", 4)) {
decode_rva2(id3, buf, fh->size);
return;
+ } else if (!strncmp(fh->id, "UFID", 4)) {
+ decode_ufid(id3, buf, fh->size);
+ return;
}

encoding = *buf++;
diff --git a/id3.h b/id3.h
index 3e83dc6..3516204 100644
--- a/id3.h
+++ b/id3.h
@@ -41,6 +41,7 @@ enum id3_key {
ID3_RG_ALBUM_GAIN,
ID3_RG_ALBUM_PEAK,
ID3_COMMENT,
+ ID3_MUSICBRAINZ_TRACKID,

NUM_ID3_KEYS
};
diff --git a/ui_curses.c b/ui_curses.c
index 98236ad..b052ef9 100644
--- a/ui_curses.c
+++ b/ui_curses.c
@@ -1671,7 +1671,8 @@ static void spawn_status_program(void)
argv[i++] = xstrdup(player_status_names[status]);
if (player_info.ti) {
static const char *keys[] = {
- "artist", "album", "discnumber", "tracknumber", "title", "date", NULL
+ "artist", "album", "discnumber", "tracknumber", "title", "date",
+ "musicbrainz_trackid", NULL
};
int j;
--
1.7.6
Gregory Petrosyan
2011-09-03 19:24:13 UTC
Permalink
Post by Johannes Weißl
+static void decode_ufid(struct id3tag *id3, const char *buf, int len)
+{
+ char *ufid;
+ size_t ufid_len = len - 22 - 1;
I've added a BUG_ON(len < 23) here, do you agree with it?

Pushed to pu -- thanks, as always!

Gregory
Gregory Petrosyan
2011-09-03 19:25:56 UTC
Permalink
On Sat, Sep 3, 2011 at 11:24 PM, Gregory Petrosyan
Post by Gregory Petrosyan
Post by Johannes Weißl
+static void decode_ufid(struct id3tag *id3, const char *buf, int len)
+{
+     char *ufid;
+     size_t ufid_len = len - 22 - 1;
I've added a BUG_ON(len < 23) here, do you agree with it?
Oh, of course 'return' is better...

                Gregory
Johannes Weißl
2011-09-03 19:34:04 UTC
Permalink
Hi Gregory,
Post by Gregory Petrosyan
Post by Gregory Petrosyan
Post by Johannes Weißl
+static void decode_ufid(struct id3tag *id3, const char *buf, int len)
+{
+     char *ufid;
+     size_t ufid_len = len - 22 - 1;
I've added a BUG_ON(len < 23) here, do you agree with it?
Oh, of course 'return' is better...
Yes, return is better, it would be great if you could add it!

Thanks for merging,
Johannes

Loading...