Skip to content

Commit

Permalink
Fix ID3v1 comments, genre
Browse files Browse the repository at this point in the history
  • Loading branch information
andygrundman committed Mar 22, 2009
1 parent 8d84aeb commit 21427ef
Show file tree
Hide file tree
Showing 7 changed files with 397 additions and 9 deletions.
339 changes: 339 additions & 0 deletions COPYING

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Changes
COPYING
lib/Audio/Scan.pm
Makefile.PL
MANIFEST This list of files
Expand Down
3 changes: 3 additions & 0 deletions lib/Audio/Scan.pm
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ Some of the file format parsing code was derived from the mt-daapd project,
and adapted by Netgear. It has been heavily rewritten to fix bugs and add
more features.
The source to the original Netgear C scanner for SqueezeCenter is located
at L<http://svn.slimdevices.com/repos/slim/7.3/trunk/platforms/readynas/contrib/scanner>
=head1 AUTHOR
Andy Grundman, E<lt>[email protected]E<gt>
Expand Down
18 changes: 17 additions & 1 deletion t/05mp3.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use strict;

use File::Spec::Functions;
use FindBin ();
use Test::More tests => 41;
use Test::More tests => 47;

use Audio::Scan;

Expand Down Expand Up @@ -175,6 +175,22 @@ use Audio::Scan;
is( $info->{song_length_ms}, 1071, 'VBRI duration ok' );
}

### ID3 tag tests

# ID3v1
{
my $s = Audio::Scan->scan_tags( _f('v1.mp3') );

my $tags = $s->{tags};

is( $tags->{TPE1}, 'Artist Name', 'ID3v1 artist ok' );
is( $tags->{TIT2}, 'Track Title', 'ID3v1 title ok' );
is( $tags->{TALB}, 'Album Name', 'ID3v1 album ok' );
is( $tags->{TDRC}, 2009, 'ID3v1 year ok' );
is( $tags->{TCON}, 'Ambient', 'ID3v1 genre ok' );
is( $tags->{COMM}, 'This is a comment', 'ID3v1 comment ok' );
}

sub _f {
return catfile( $FindBin::Bin, 'mp3', shift );
}
Binary file modified t/mp3/v1.mp3
Binary file not shown.
38 changes: 37 additions & 1 deletion tagutils-mp3.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,26 @@ get_mp3tags(char *file, HV *tags)
}
}

// Special handling for TCON genre frame, lookup the genre string
else if ( !strcmp(pid3frame->id, "TCON") ) {
char *genre_string;

utf8_value = (char *)id3_ucs4_utf8duplicate( id3_field_getstrings(&pid3frame->fields[1], 0) );

if ( isdigit(utf8_value[0]) ) {
// Convert to genre string
genre_string = (char *)id3_ucs4_utf8duplicate( id3_genre_name( id3_field_getstrings(&pid3frame->fields[1], 0) ) );
hv_store( tags, pid3frame->id, strlen(pid3frame->id), newSVpv( genre_string, 0 ), 0 );
free(genre_string);
}
// XXX support '(23) Ambient'
else {
hv_store( tags, pid3frame->id, strlen(pid3frame->id), newSVpv( utf8_value, 0 ), 0 );
}

free(utf8_value);
}

// All other frames
else {
if (pid3frame->nfields == 1) {
Expand All @@ -160,6 +180,7 @@ get_mp3tags(char *file, HV *tags)
hv_store( tags, pid3frame->id, strlen(pid3frame->id), bin, 0 );
}
else if (pid3frame->nfields == 2) {
//fprintf(stderr, " type %d\n", pid3frame->fields[1].type);
switch (pid3frame->fields[1].type) {
case ID3_FIELD_TYPE_STRINGLIST:
nstrings = id3_field_getnstrings(&pid3frame->fields[1]);
Expand Down Expand Up @@ -195,8 +216,23 @@ get_mp3tags(char *file, HV *tags)
}
}
else {
// special handling for COMM
if ( !strcmp(pid3frame->id, "COMM") ) {
switch (pid3frame->fields[3].type) {
case ID3_FIELD_TYPE_STRINGFULL:
utf8_value = (char *)id3_ucs4_utf8duplicate( id3_field_getfullstring(&pid3frame->fields[3]) );
hv_store( tags, pid3frame->id, strlen(pid3frame->id), newSVpv( utf8_value, 0 ), 0 );
free(utf8_value);
break;

default:
fprintf(stderr, "Unsupported COMM type %d\n", pid3frame->fields[3].type);
break;
}
}

// special handling for APIC
if ( !strcmp(pid3frame->id, "APIC") ) {
else if ( !strcmp(pid3frame->id, "APIC") ) {
// XXX: also save other info
bin = newSVpvn( pid3frame->fields[4].binary.data, pid3frame->fields[4].binary.length );
hv_store( tags, pid3frame->id, strlen(pid3frame->id), bin, 0 );
Expand Down
7 changes: 0 additions & 7 deletions tagutils-mp3.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
//=========================================================================
// FILENAME : tagutils-mp3.h
// DESCRIPTION : MP3 metadata reader
//=========================================================================
// Copyright (c) 2008- NETGEAR, Inc. All Rights Reserved.
//=========================================================================

/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down

0 comments on commit 21427ef

Please sign in to comment.