Home of the Squeezebox™ & Transporter® network music players.
Results 1 to 10 of 10
  1. #1
    Senior Member maggior's Avatar
    Join Date
    Dec 2006
    Location
    nj
    Posts
    2,123

    Automatically add artwork to mp3 files from cover.jpg

    My library is set up with artwork in the album directory as cover.jpg. For portability, I'd like to embed the artwork in my mp3 files too.

    Does anybody know of a way to do this with a script/batch? I'd rather not have to go through album by album with a tool like Media Monkey doing this.

    Thanks!
    Rich
    ---------
    Setup: 2 SB3s, 4 Booms, 1 Duet, 1 Receiver, 1 Touch, iPeng on iPod Touch, SqueezeCommander, OrangeSqueeze, and SqueezePlayer on Xoom and Galaxy Player 4.2. CentOS 6.3 Server running LogitechMediaServer 7.7.2 and SqueezeSlave.
    Current library stats: 40,810 songs, 3,153 albums, 582 artists.
    http://www.last.fm/user/maggior

  2. #2
    Former Squeezebox Guy andyg's Avatar
    Join Date
    Jan 2006
    Location
    Pittsburgh, PA
    Posts
    7,395
    Here's a script I wrote a while ago that I use for adding covers to my mp3 mirrored directory so they display on my iPhone. It uses Audio::TagLib which is somewhat hard to compile, and I wouldn't choose if I was writing this today, but it works well enough.

    Code:
    #!/usr/bin/perl
    #
    # Insert cover.jpg into mp3 files that don't already have cover art
    
    use strict;
    
    use File::Find::Rule;
    use File::Path;
    use File::Slurp qw(read_file);
    use File::Spec::Functions;
    use Audio::TagLib;
    
    $|++;
    
    my %missing;
    
    my $dir = shift || die "Usage: $0 directory\n";
    
    # Now look for files in the given directory
    my @mp3_files = File::Find::Rule->file()->name('*.mp3', '*.MP3')->in($dir);
    
    for my $file ( @mp3_files ) {
            next if $file =~ /\.AppleDouble/;
    
            # Look for a cover.jpg file
            my ( $src_volume, $src_directories, $src_file ) = File::Spec->splitpath($file);
            my $cover_file = catfile( $src_directories, 'cover.jpg' );
            unless ( -r $cover_file ) {
                    #print "no cover file found, skipping\n";
                    $missing{$src_directories} = 1;
                    next;
            }
    
            # Check if the file already has embedded artwork
            my $f = Audio::TagLib::MPEG::File->new($file);
            my $id3v2 = $f->ID3v2Tag() || next;
            my $frameListMap = $id3v2->frameListMap();
            my $bv = Audio::TagLib::ByteVector->new('APIC');
            if ( $frameListMap->contains($bv) ) {
                    print "already contains APIC ($file)\n";
                    next;
            }
    
            # Add cover to APIC
            my $jpg = read_file($cover_file) or die "Unable to read cover file: $cover_file ($!)";
    
            my $apic = Audio::TagLib::ID3v2::AttachedPictureFrame->new();
            $apic->setType( 'FrontCover' );
            $apic->setMimeType( Audio::TagLib::String->new( 'image/jpeg' ) );
    
            my $pic = Audio::TagLib::ByteVector->new();
            $pic->setData( $jpg, length($jpg) );
            $apic->setPicture( $pic );
    
            $id3v2->addFrame( $apic );
            $f->save();
    
            print "$file: added cover to tags\n";
    }
    
    # Log missing covers
    open my $fh, '>', 'missing-covers.txt';
    
    for my $dir ( sort keys %missing ) {
            print $fh "$dir\n";
    }
    
    close $fh;

  3. #3
    Senior Member maggior's Avatar
    Join Date
    Dec 2006
    Location
    nj
    Posts
    2,123
    Awesome...thanks Andy. Substitute "iPod Nano 5G" for "iPone", and I'm in the exact situation you were in.

    I had looked at that library thinking I could cook up some perl code to do it, but as usual, somebody else has solved the problem already! :-).

    Thanks a bunch.
    Rich
    ---------
    Setup: 2 SB3s, 4 Booms, 1 Duet, 1 Receiver, 1 Touch, iPeng on iPod Touch, SqueezeCommander, OrangeSqueeze, and SqueezePlayer on Xoom and Galaxy Player 4.2. CentOS 6.3 Server running LogitechMediaServer 7.7.2 and SqueezeSlave.
    Current library stats: 40,810 songs, 3,153 albums, 582 artists.
    http://www.last.fm/user/maggior

  4. #4
    Senior Member maggior's Avatar
    Join Date
    Dec 2006
    Location
    nj
    Posts
    2,123
    Quote Originally Posted by andyg View Post
    It uses Audio::TagLib which is somewhat hard to compile, and I wouldn't choose if I was writing this today, but it works well enough.
    Andy -

    If you were to do this again today, what would you use? Just curious.

    Thanks!
    Rich
    ---------
    Setup: 2 SB3s, 4 Booms, 1 Duet, 1 Receiver, 1 Touch, iPeng on iPod Touch, SqueezeCommander, OrangeSqueeze, and SqueezePlayer on Xoom and Galaxy Player 4.2. CentOS 6.3 Server running LogitechMediaServer 7.7.2 and SqueezeSlave.
    Current library stats: 40,810 songs, 3,153 albums, 582 artists.
    http://www.last.fm/user/maggior

  5. #5
    Senior Member
    Join Date
    May 2008
    Location
    United States
    Posts
    11,022
    I believe mp3tag can do this as well in large batches.

  6. #6
    Former Squeezebox Guy andyg's Avatar
    Join Date
    Jan 2006
    Location
    Pittsburgh, PA
    Posts
    7,395
    I would probably use MP3::Tag, after first doing some tests to feel comfortable it wouldn't screw up my files. At the time I wrote this script I was investigating Audio::TagLib for use in SBS, so that's probably why I chose it.

  7. #7
    Senior Member
    Join Date
    Sep 2006
    Location
    Danmark
    Posts
    1,361
    While I admire anyone fluent in russian and/or perl, I went for a slightly lower tech solution. If you have access to the CLI-tagger eyeD3,

    http://eyed3.nicfit.net/

    I simply did:

    'find . -name *.mp3 -execdir eyeD3 --add-image=folder.jpg '{}' \;'

    (or something to that effect - its been a while so do a test-run first)

    The tools are apt-get'able in Ubuntu 9.10

  8. #8
    Senior Member JJZolx's Avatar
    Join Date
    Apr 2005
    Location
    Colorado
    Posts
    11,462
    Mp3tag has a simple action, "Import cover from file" that can easily do this. If you use it, make sure you check "Delete existing cover art" or you can end up importing multiple copies of the same cover.jpg.

  9. #9
    Senior Member
    Join Date
    Sep 2006
    Location
    Danmark
    Posts
    1,361
    Andy,

    Quote Originally Posted by andyg View Post
    my mp3 mirrored directory so they display on my iPhone.
    are you familiar with the media-server, Subsonic (remote streaming using an embedded flash player)? The cool thing is that there is an iPhone-app for accessing a server. The server supports transcoding on the fly - like slimserver. The app is rather rudimentary, but works nicely. The server is open source and free. The app costs about 10$.

    Subsonic (server):

    http://www.subsonic.org/pages/index.jsp

    z-subsonic (app):

    http://appshopper.com/entertainment/z-subsonic

  10. #10
    Junior Member
    Join Date
    Mar 2017
    Posts
    1
    Quote Originally Posted by maggior View Post
    My library is set up with artwork in the album directory as cover.jpg. For portability, I'd like to embed the artwork in my mp3 files too.

    Does anybody know of a way to do this with a script/batch? I'd rather not have to go through album by album with a tool like Media Monkey doing this.

    Thanks!
    Taghycardia can use corresponding cover.jpg (or folder.jpg, or other specified) files to embed automatically in every mp3 file in an entire folder tree of music albums. It also can remove embedded images from multiple mp3s in the same easy manner.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •