Improve parsing of cddb information
authorArnold Metselaar <arnold.metselaar@planet.nl>
Wed, 13 Aug 2008 17:33:05 +0100
changeset 9548827afe1c3777
parent 9547 1354753f6eca
child 9549 17f8ed16524b
Improve parsing of cddb information

Date: Thu, 1 May 2008 21:09:25 +0200
This patch improves the parsing of cddb information:
* Disc and track titles can now contain '='.
* If a track title is of the form <track-artist> / <track-title> the
meta-info will contain the track-artist rather than the disc-artist.

I have tested these changes together with my get_dir patch with the
sources from debian testing/security and both Amarok and gxine now
show the right artists for tracks on a compilation album.
src/input/input_cdda.c
     1.1 --- a/src/input/input_cdda.c	Wed Aug 13 17:33:05 2008 +0100
     1.2 +++ b/src/input/input_cdda.c	Wed Aug 13 17:33:05 2008 +0100
     1.3 @@ -1475,7 +1475,7 @@
     1.4  	    if (sscanf(buffer, "DTITLE=%s", &buf[0]) == 1) {
     1.5  	      char *pt, *artist, *title;
     1.6  
     1.7 -	      pt = strrchr(buffer, '=');
     1.8 +	      pt = strchr(buffer, '=');
     1.9  	      if (pt) {
    1.10  		pt++;
    1.11  
    1.12 @@ -1515,7 +1515,7 @@
    1.13  	    else if (sscanf(buffer, "TTITLE%d=%s", &tnum, &buf[0]) == 2) {
    1.14  	      char *pt;
    1.15  
    1.16 -	      pt = strrchr(buffer, '=');
    1.17 +	      pt = strchr(buffer, '=');
    1.18  	      if (pt)
    1.19  		pt++;
    1.20  	      if (this->cddb.track[tnum].title == NULL)
    1.21 @@ -2465,15 +2465,31 @@
    1.22    }
    1.23  
    1.24    if(this->cddb.track[this->track].title) {
    1.25 -    lprintf("Track %d Title: %s\n", this->track+1, this->cddb.track[this->track].title);
    1.26 -
    1.27 -    _x_meta_info_set_utf8(this->stream, XINE_META_INFO_TITLE, this->cddb.track[this->track].title);
    1.28 -  }
    1.29 +    /* Check for track 'titles' of the form <artist> / <title>. */ 
    1.30 +    char *pt;
    1.31 +    pt = strstr(this->cddb.track[this->track].title, " / ");
    1.32 +    if (pt != NULL) {
    1.33 +      char *track_artist;
    1.34 +      track_artist = strdup(this->cddb.track[this->track].title);
    1.35 +      track_artist[pt - this->cddb.track[this->track].title] = 0;
    1.36 +      lprintf("Track %d Artist: %s\n", this->track+1, track_artist);
    1.37 +
    1.38 +      _x_meta_info_set_utf8(this->stream, XINE_META_INFO_ARTIST, track_artist);
    1.39 +      free(track_artist);
    1.40 +      pt += 3;
    1.41 +    }
    1.42 +    else {
    1.43 +      if(this->cddb.disc_artist) {
    1.44 +	lprintf("Disc Artist: %s\n", this->cddb.disc_artist);
    1.45 +	
    1.46 +	_x_meta_info_set_utf8(this->stream, XINE_META_INFO_ARTIST, this->cddb.disc_artist);
    1.47 +      }
    1.48    
    1.49 -  if(this->cddb.disc_artist) {
    1.50 -    lprintf("Disc Artist: %s\n", this->cddb.disc_artist);
    1.51 -
    1.52 -    _x_meta_info_set_utf8(this->stream, XINE_META_INFO_ARTIST, this->cddb.disc_artist);
    1.53 +      pt = this->cddb.track[this->track].title;
    1.54 +    }
    1.55 +    lprintf("Track %d Title: %s\n", this->track+1, pt);
    1.56 +
    1.57 +    _x_meta_info_set_utf8(this->stream, XINE_META_INFO_TITLE, pt);
    1.58    }
    1.59    
    1.60    if(this->cddb.disc_category) {