karaoke archiver

Just talk about kJams stuff with each other, describe things you did that worked, talk about your setup, anything that doesn't fit into the other forums!
DeusExMachina
Posts: 1293
Joined: Sun Apr 20, 2008 9:57 am
Location: Pittsburgh, PA
Contact:

karaoke archiver

Post by DeusExMachina »

I wrote a small BASH and Perl script utility that takes folders from the Finder and goes through them and puts pairs of CD-G and MP3s together and zips them, saving space. I wrapped it in an automator workflow that can be added to the contextual menu for folder actions, so you can use it anywhere, or it can be used as an application to which you just drag folders. Alternately, if you run it with a group of folders selected in the Finder, it will run on them.
If anyone is interested, let me know and I'll figure out a way of posting it somewhere.

dave
Site Admin
Posts: 6688
Joined: Sun Sep 18, 2005 8:02 am
Location: Seattle
Contact:

:)

Post by dave »

kJams will eventually have this ability built in. :)
to zip all unzipped songs
and to "consolidate" the library too!

:)

DeusExMachina
Posts: 1293
Joined: Sun Apr 20, 2008 9:57 am
Location: Pittsburgh, PA
Contact:

gratis

Post by DeusExMachina »

Well, here is the code if it helps anyone.

#!/usr/bin/perl
use strict;
use warnings;
if(0 == @ARGV) {
print "Usage: convert2zip dir1 dir2 dir3 etc\n";
exit(1);
}
my $arg;
foreach $arg (@ARGV) {
chdir($arg);
print "Processing directory $arg\n";
my $basename;
my %cdgfilemap;
my %mp3filemap;
foreach (<*>) {
if( $_ =~ /.cdg/i ) {
$basename = $_;
$basename =~ s/.cdg//i;
$cdgfilemap{$basename} = $_
}
elsif( $_ =~ /.mp3/i ) {
$basename = $_;
$basename =~ s/.mp3//i;
$mp3filemap{$basename} = $_;
}
}
foreach $basename (keys %mp3filemap) {
if(exists($cdgfilemap{$basename})) {
print "zipping $mp3filemap{$basename} $cdgfilemap{$basename} into $basename.zip\n";
print "zip \"$basename.zip\" \"$mp3filemap{$basename}\" \"$cdgfilemap{$basename}\"\n";
system "zip -j -m \"$basename.zip\" \"$mp3filemap{$basename}\" \"$cdgfilemap{$basename}\"";
delete $cdgfilemap{$basename};
}
else {
print ".mp3 file $mp3filemap{$basename} is missing a corresponding .cdg file\n";
}
}
foreach $basename (keys %cdgfilemap) {
print ".cdg file $cdgfilemap{$basename} is missing a corresponding .mp3 file\n";
}
}

dave
Site Admin
Posts: 6688
Joined: Sun Sep 18, 2005 8:02 am
Location: Seattle
Contact:

:)

Post by dave »

note: if you want to run this, you must do it BEFORE you add your songs to kJams. if you run it AFTER, you will royally screw up your library and cause kJams to lose your songs.

DeusExMachina
Posts: 1293
Joined: Sun Apr 20, 2008 9:57 am
Location: Pittsburgh, PA
Contact:

Post by DeusExMachina »

I have it set to leave the originals alone and not to create a new Library entry, so things run smoothly for me, but in general I always run this upon first getting files in .mp3/CDG format, so as to save space, prior to importing them. This way kJams can serve as a backup check to make sure the archiving process left functional, working files.

dave
Site Admin
Posts: 6688
Joined: Sun Sep 18, 2005 8:02 am
Location: Seattle
Contact:

:)

Post by dave »

8)

pdw
Posts: 4
Joined: Mon Jan 26, 2009 11:11 am

Re: karaoke archiver

Post by pdw »

Dave-

Anxiously waiting for this in KJams Lite! In the meantime how do I run this script. I feel I am Mac savy on most things, but haven't run scripts before. I tried this one in my script editor, but didn't work. Also downloaded recent PERL app, but that didn't help.

Can you walk me thru how to get this script to work? I would really like to automate my cdg/mp3 files to zip(before adding to KJAMS).

Thanks,

Paul

DeusExMachina
Posts: 1293
Joined: Sun Apr 20, 2008 9:57 am
Location: Pittsburgh, PA
Contact:

Re: karaoke archiver

Post by DeusExMachina »

Not sure how much Dave can help you, as I am the one who wrote the script! :)

Anyway, the easiest way is simply to wrap it in an Automator workflow. Just launch automator and drag the appropriate actions from the library to the stage. IIRC, first go to "files and folders" and drag "Get Selected Finder Items" onto the stage. Next, drag "Get Folder Contents", selecting "Repeat for each subfolder found" if desired. Finally switch from "Files & Folders" to Utilities and drag "Run Shell Script" over. Paste the code into the appropriate field, and select "usr/bin/perl" from the pop up menu. If you want you can also drag over "Show Growl Notification" to add a little finesse!

Save as an application, or a Finder plug in, or both, and you should be set. Keep in mind this is off the top of my head, as I am not at the machine where I saved my copy, so I don't have access to my original file. If this doesn't work, let me know and I'll track it down.

Mark

pdw
Posts: 4
Joined: Mon Jan 26, 2009 11:11 am

Re: karaoke archiver

Post by pdw »

Thanks Mark-

I have gotten it to work. I created a folder for converting(on my desktop - where I will drag my disc folders for processing).

Here is the order I put into automator:

1) Get Selected Finder Items

2) Get Specified Finder Items
That is where I specified the folder on my desktop.

3) Get Folder Contents
I didn't check repeat for each subfolder, because it wouldn't work with it checked. Doesn't seem right, since I have several folders inside the main desktop folder, but unchecked it worked and converted all folders inside main one.

4) Run Shell Script
I pasted your code, selected from the menu--/usr/bin/perl , and then selected---as arguments

I only went thru all the steps in case someone on the forum, is looking to do it too, and has no automator experience. I may even tinker with it if I have the chance. To be able to drag the folder to an Icon, have it convert, and then automatically place the new converted folder in the "My Karaoke" folder, next to the KJam folder would be nice.

Thanks again Mark for the code. Without it, this wouldn't been possible.

Paul

pdw
Posts: 4
Joined: Mon Jan 26, 2009 11:11 am

Re: karaoke archiver

Post by pdw »

To continue my automator sequence...

I figured out how to move the converted folders to "My Karaoke" folder...

Just add this after the steps above...

5) Get Selected Finder Items

6) Get Specified Finder Items
This specifies again my folder on desktop, that holds the sub-folders I want to convert

7) Get Folder Contents

8) Move Finder Items
I pick "Other" and then point it to the "My Karaoke" folder.

Thats it!!!

DeusExMachina
Posts: 1293
Joined: Sun Apr 20, 2008 9:57 am
Location: Pittsburgh, PA
Contact:

Re: karaoke archiver

Post by DeusExMachina »

I am not sure why you are doing both "get selected finder item" as well as "get specified finder items." You just need the first one. Using both just replicates the results from the first as the results of the second. Using get selected gives the function more flexibility over get specified, where you must hard code a location.
It also then can be saved as a contextual menu plug in, where you simply right-click a folder and select "More>Automator>nameOfYouWorkflow." You can the use Get specified to get a path to your location, or you can use "Ask for finder items" to bring up a selection box.

dave
Site Admin
Posts: 6688
Joined: Sun Sep 18, 2005 8:02 am
Location: Seattle
Contact:

Re: karaoke archiver

Post by dave »

note: don't do this if your songs are already in kJams.
did you see this?

dizzidecazz
Posts: 22
Joined: Wed Feb 17, 2010 8:00 pm

Re: karaoke archiver

Post by dizzidecazz »

Hi Mark,

I tried your instructions, saving both as an app and menu plug-in but nothings happening. Ummm, help? Maybe if someone has a working version, they could attach it and share.

Damien

DeusExMachina
Posts: 1293
Joined: Sun Apr 20, 2008 9:57 am
Location: Pittsburgh, PA
Contact:

Re: karaoke archiver

Post by DeusExMachina »

OK, SL broke some of the automator script. Give me a few minutes and I'll post an update.

DeusExMachina
Posts: 1293
Joined: Sun Apr 20, 2008 9:57 am
Location: Pittsburgh, PA
Contact:

Re: karaoke archiver

Post by DeusExMachina »

OK fixed. Here's the thing. It totally works, and is currently set to dig through subfolders and find all instances of CD+G/MP3 pairs, and zip them together.
HOWEVER,
When there are no subfolders, everything works fine, all files are processed, and on completion the application gives both a growl as well as a verbal notification.
If there ARE subfolders, it still works, but the script is not happy with the fact that it is trying to process the subfolders as files, so you get an error message and no notifications. It DOES still zip all the files, it just errors out instead of exiting gracefully. I will try to fix that, but in the meantime, here it is, so you can use it now.

Also of note is that this is a different script now, using BASH, not Perl.
Attachments
Karaoke Archiver.zip
(228.06 KiB) Downloaded 430 times

Post Reply