From 9c1598bafdd4c31157a4bcd46ddad798eb5437ff Mon Sep 17 00:00:00 2001 From: Ross Burton Date: Tue, 22 Jan 2008 20:46:34 +0000 Subject: Look for album titles with "(disc X)" in and extract the disc number. 2008-01-22 Ross Burton * libjuicer/sj-metadata-musicbrainz.c: Look for album titles with "(disc X)" in and extract the disc number. * src/sj-main.c: Update the UI from the disk number if it is set. #510439, thanks to Matthew Martin. svn path=/trunk/; revision=1996 --- libjuicer/sj-metadata-musicbrainz.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'libjuicer') diff --git a/libjuicer/sj-metadata-musicbrainz.c b/libjuicer/sj-metadata-musicbrainz.c index 254ed56..f980ad5 100644 --- a/libjuicer/sj-metadata-musicbrainz.c +++ b/libjuicer/sj-metadata-musicbrainz.c @@ -58,6 +58,7 @@ struct SjMetadataMusicbrainzPrivate { /* TODO: remove and use an async queue? */ GList *albums; GError *error; + GRegex *disc_regex; }; #define GET_PRIVATE(o) \ @@ -330,6 +331,7 @@ lookup_cd (SjMetadata *metadata) SjMetadataMusicbrainzPrivate *priv; GList *albums = NULL; GList *al, *tl; + GMatchInfo *info; char data[256]; int num_albums, i, j; NautilusBurnMediaType type; @@ -421,6 +423,22 @@ lookup_cd (SjMetadata *metadata) album->title = g_strdup (_("Unknown Title")); } + if (g_regex_match (priv->disc_regex, album->title, 0, &info)) { + int pos = 0; + char *s; + + g_match_info_fetch_pos (info, 1, &pos, NULL); + if (pos) { + g_free (album->title); + album->title = g_strndup (album->title, pos); + } + + s = g_match_info_fetch (info, 2); + album->disc_number = atoi (s); + g_free (s); + } + g_match_info_free (info); + { int num_releases; num_releases = mb_GetResultInt (priv->mb, MBE_AlbumGetNumReleaseDates); @@ -633,6 +651,8 @@ sj_metadata_musicbrainz_init (SjMetadataMusicbrainz *self) if (g_getenv("MUSICBRAINZ_DEBUG")) { mb_SetDebug (self->priv->mb, TRUE); } + + self->priv->disc_regex = g_regex_new (".+( \\(disc (\\d+).*)", 0, 0, NULL); } static void @@ -698,6 +718,7 @@ sj_metadata_musicbrainz_finalize (GObject *object) g_free (priv->http_proxy); g_free (priv->cdrom); + g_regex_unref (priv->disc_regex); mb_Delete (priv->mb); G_OBJECT_CLASS (sj_metadata_musicbrainz_parent_class)->finalize (object); -- cgit v1.2.3