Home of the Squeezebox™ & Transporter® network music players.
Page 1 of 3 123 LastLast
Results 1 to 10 of 25
  1. #1
    Senior Member
    Join Date
    Apr 2005
    Posts
    111

    Plugin to import a CD into the library

    Hi all,

    As I alluded to in the 3rd Party Plugins forum, I've been playing with a plugin which greatly simplifies the task of importing a CD into your SqueezeCenter music library. The idea is that, with as little user intervention as possible, it will rip, flac and tag the CD, fetch the correct coverart, add it to your music directory and trigger a rescan of just the new music.

    I've attached my current attempt. It works well enough but - be warned - this is very much early and experimental code. They say the best way to write code is to write it once, then throw it away and write it again - well this is the version that will probably get thrown away! So I'm not really interested in bug reports/beta testing at the moment (there's plenty wrong with the attached code) - I'm publishing it looking really for any comments or suggestions on the overall approach before spending time coding it properly

    It only works with SqueezeCenter v7 on Linux (I've developed it on Ubuntu Gutsy), and you will need to make sure the "cdparanoia" and "flac" commands are installed and available. The squeezecenter user needs permission to read from the CD drive (on Ubuntu, you need to add the squeezecenter user to the cdrom group) and to write to your audio directory. Obviously make sure you've got your music backed up, or use a test system! Install the plugin as usual; it appears under "Extras" on the SC web app. It also only works with /dev/cdrom at present, if you have multiple CD drives make sure you put the disc into the right one!

    Reflecting this plugin's prototype status, it has debug trace enabled by default - error handling is not entirely complete, so if it's not working, keep an eye on the server log. The ripping process does most of its work inside a directory in /tmp, so you may have to clear up in there if things go wrong. The plugin will move the ripped music files into a "cdimport" directory in your audio directory; this lets you clear out anything that's added incorrectly, and also means you don't have to mark your whole audio directory as being writable by squeezecenter. Underneath "cdimport" it uses a artist/album/trackname directory structure.

    The process of ripping seems to take 10-15 minutes for most CDs, I feel it should be quicker than that but I'm not sure why it's taking so long. If you try this, please let me know how long it takes so I can see whether it's just my system or a genuine problem.

    Tag data is obtained from Musicbrainz - if MB doesn't recognise the disc, it will currently refuse to import it. Album art comes from Amazon, using the Amazon ASID which is provided by Musicbrainz. If MB doesn't know the ASID, or Amazon doesn't have an image, then it should let you import the CD but you won't get any coverart. There's a couple of problems here: MB doesn't give us "genre" information so the tracks are tagged without any genre. Also Amazon's coverart seems to be very variable in quality. I've been looking for solutions to these problems, but haven't found anything really good yet... Finally, I've had to reverse engineer the MusicBrainz tag names by looking at some files tagged by the MB applications, and there's a couple I haven't worked out yet (see comments in CDInfo.pm).

    I'd like to be able to include MusicIP and ReplayGain tags as well, but I've not looked at these yet. Are there any other tags that could usefully be added when importing music?

    The web front end to this is a simple AJAX thing; this is the first time I've tried AJAX techniques so I'd particularly appreciate any expert reviews of this It's only tested with Firefox so far; it's pretty ugly but it's a reasonable proof-of-concept. The plugin tries to be non-blocking, so you can navigate away from the page while it's ripping and come back later.

    All time-consuming work is shipped off to other processes using Perl forking, using:
    Code:
    open "$command |"
    and IO::Select to handle non-blocking reading of the responses. This seems to work ok, but I'm concerned that forking SqueezeCenter might not be very wise. Could some kindly perl/SC expert put me at ease or suggest a better way of handling this? The foking is encapsulated in Fork.pm.

    The scan is triggered using:
    Code:
        Slim::Utils::Scanner->scanDirectory({'url'       => $albumdir,
                                             'recursive' => 0,
                                             'types'     => 'audio',
                                             'scanName'  => 'directory',
        });
    Again, this mostly works ok, but could someone please comment on whether this is the right way to do this? There's one bug - this doesn't pick up the artwork until you navigate to the album page of a newly-ripped album. Is there some other call I should be making to do this?

    Thanks for reading to the end of this long post.... any and all comments most welcome!

    Ian

  2. #2
    Senior Member mflint's Avatar
    Join Date
    Oct 2005
    Location
    UK
    Posts
    392
    Ian,

    That is a funky piece of work, nice one!

    (A great pity it's no use to me as my SqueezeCenter box doesn't have a CD drive, but...)

    Matthew

  3. #3
    Gadfly, Former Founder Slim Devices dean's Avatar
    Join Date
    Apr 2005
    Location
    San Francisco, CA
    Posts
    4,427

    Plugin to import a CD into the library

    Very nice! I'll give it a try with my Ubuntu server here...



  4. #4
    Senior Member mrfantasy's Avatar
    Join Date
    Jul 2005
    Location
    Chatham, NJ
    Posts
    390
    Cool idea!

    I've got my linux box running abcde (http://www.hispalinux.es/~data/abcde.php, although the SVN server seems to be down) and it handles the autorip, and tagging, but it doesn't do cover art or the adding to the library. So I'll give this a shot!

  5. #5
    NOT a Slim Devices Employee kdf's Avatar
    Join Date
    Apr 2005
    Posts
    9,493

    Plugin to import a CD into the library

    On 21-Jan-08, at 1:51 PM, iwp wrote:

    >
    > --------------------
    > Again, this mostly works ok, but could someone please comment on
    > whether
    > this is the right way to do this? There's one bug - this doesn't
    > pick up
    > the artwork until you navigate to the album page of a newly-ripped
    > album. Is there some other call I should be making to do this?


    Have you considered Slim::Utils::Misc::findAndScanDirectoryTree?

    This is what is called while using BMF and it handles adding artwork
    where present.
    it takes a hashref as a param, and you can use the key 'url' for the
    top level.
    -kdf

  6. #6
    Senior Member
    Join Date
    Apr 2005
    Posts
    111
    Quote Originally Posted by kdf View Post
    Have you considered Slim::Utils::Misc::findAndScanDirectoryTree?
    Thanks, kdf! I've got it working with that, but I've had to work around what I think is a problem in findAndScanDirectoryTree. If I invoke it after building the output directory in the library, nothing appears to happen. The following gets logged:

    Code:
    [08-01-22 20:19:03.3408] Plugins::CDImport::Ripper::finalize (252) Rescanning directory using URL file:///home/iwp/Music/cdimport/Muse/Showbiz
    [08-01-22 20:19:03.4572] Slim::Utils::Misc::findAndScanDirectoryTree (1013) findAndScanDirectoryTree( /home/iwp/Music/cdimport/Muse/Showbiz ): fsMTime: 1201033143, dbMTime: 1201033143
    [08-01-22 20:19:03.4617] Plugins::CDImport::Ripper::finalize (256) Done
    Looking at the findAndScanDirectoryTree code, the problem is that fsMTime==dbMTime, so it thinks there's nothing to do. I guess that, because this is the first time it's seen this directory, it's created a new 'track object' with an up-to-date timestamp; and then compared this to the timestamp of the directory on the disk.

    I've worked around it by driving findAndScanDirectoryTree before constructing the output directory, to initialize the track object; and then driving it again at the end. This works a treat, including album art.

    I'm invoking it with:
    Code:
      my $pathAsURL = Slim::Utils::Misc::fileURLFromPath($albumdir);
      Slim::Utils::Misc::findAndScanDirectoryTree({
            'url' => $pathAsURL
      });
    ...am I doing something wrong or is this a problem in findAndScanDirectoryTree?

    Thanks again,
    Ian

  7. #7
    NOT a Slim Devices Employee kdf's Avatar
    Join Date
    Apr 2005
    Posts
    9,493

    Plugin to import a CD into the library

    > ...am I doing something wrong or is this a problem in
    > findAndScanDirectoryTree?


    The problem is that this is the bit of code used by Browse Music Folder
    when collecting the folder list. This includes the check against the
    timestamps in order to trigger a scan, or not. Since this is a brand new
    folder, the timestamps do not differ and you end up not scanning, as you
    have discovered.

    This is the expected behaviour, but your use case clearly shows the
    limitation of how this is done. There isn't really any way for this
    routine to know whether or not a new folder has created a new track item
    or not. In the designed case, you'd always trigger a scan at the parent
    folder.

    Your workaround seems perfectly valid as long as it's not triggering a
    full file scan prematurely. It might be simpler to tighten one more level
    and use the objectForUrl call:
    $topLevelObj = Slim::Schema->rs('Track')->objectForUrl({
    'url' => $url,
    'create' => 1,
    'readTags' => 1,
    'commit' => 1,
    });

    If you do this when you've defined the albumdir, then the path will
    already exist in the db and should allow findAndScan to work. Another
    option would be to do this at the default top level for your album
    folders, then run the scan on that, but then you may end up scanning more
    files that you want to if they aren't always being moved away.

    -kdf



  8. #8
    Senior Member
    Join Date
    Apr 2005
    Posts
    111
    Thanks again, kdf. I'll stick to my present workaround for the time being I think - bringing knowledge of the DB schema stuff into the plugin feels like bad encapsulation; and going to the top level folder feels like overkill.

    Ian

  9. #9
    Senior Member
    Join Date
    Nov 2005
    Location
    Berlin, DE
    Posts
    1,900
    Awesome, I'm glad someone finally started working on a plugin like this. Two ideas:

    I use a lastfm plugin for MusicBrainz Picard to gather genere data which seems to work really well. I don't know how much work it would be to add that data.

    You could also grab cover art from Apple, although I don't know about the legality of that. There is code out there:
    http://avantlumiere.com/projects/i7awf/

  10. #10
    Senior Member
    Join Date
    Apr 2005
    Posts
    111
    Quote Originally Posted by SuperQ View Post
    Awesome, I'm glad someone finally started working on a plugin like this. Two ideas:

    I use a lastfm plugin for MusicBrainz Picard to gather genere data which seems to work really well. I don't know how much work it would be to add that data.

    You could also grab cover art from Apple, although I don't know about the legality of that. There is code out there:
    http://avantlumiere.com/projects/i7awf/
    Hi SuperQ,

    Many thanks for the input! I spotted the last.fm/Picard plugin a couple of days ago but haven't tried it yet. You're the second user I've seen saying that it works nicely, so I will take a closer look at how it works.

    I haven't seen the Apple code before - again this sounds like a good idea. Will take a look.

    BTW, I'm slowly going through the code making the plugin more robust. If anyone wants to play with more up to date code, see http://sourceforge.net/projects/squimport/ . (And if anyone would like to contribute some code... well there's plenty to do. I'd particularly like to find someone who understands SC skins and javascript to improve the web interface; and perhaps somebody would like to take a crack at making it work on Windows?)

    Cheers,

    Ian

Posting Permissions

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