Note that this Wiki is a work in progress, items may not be updated or may disappear entirely as the pages are updated.
Condition album covers
From SpacialAudio
Simply follow the instructions in the PAL script.
{
Don't be a loser. Leave this here.
Album cover conditioning script by FesterHead (aka Steve Kunitzer)
$Id: condition-album-covers-v1.pal,v 1.1 2007/12/01 21:49:11 FesterHead Exp $
What this PAL does:
* Condenses albums down to one cover per artist/album
* Renames album covers to "Artist-Album.jpg" with special and other character replacement
What is configurable:
* List of invalid characters
* Replacement character
* SAM album cover directory
* SAM song table name
* Limiter to prevent SAM locking
WARNING!
This script is not recommended for:
SAM newbies;
Those of weak heart, mind, and soul;
Those who can't take responsibility for their own actions;
When running, please use the "Show Desktop" feature of Windows
The script will run MUCH faster.
Example (your machine specs may vary results):
250 songs with SAM visible can take 5 minutes
250 songs with SAM hidden can take 40 seconds
I cannot stress this enough.
Run the script, accept the disclaimer, then use the "Show Desktop" feature of Windows
I keep "Show Desktop" as the first item in the Quick Launch bar.
This script is not meant to be run via the Event Scheduler nor some loop
Run it manually after adding new songs to SAM
PAL built to run manually:
* Switch to a desktop with the 'PAL Scripts' window visible
*OR*
Make the ES visible by Clicking the 'Window' menu item and selecting 'PAL Scripts'
* Click '+' (Add new PAL script)
* Uncheck the 'Automatically start script' box
* Click the folder icon and navigate to this script
* Click 'OK'
* Run by highlighting PAL
* Clicking 'Start selected PAL script' (VCR type play button)
OR
* Pressing F9
* Save settings by clicking the 'File' menu item and selecting 'Save Configuration'
WARNING!
IF YOU DON'T CONFIGURE THE SCRIPT, DON'T EXPECT IT TO WORK PROPERLY!
I built this PAL for my station using my station configuration
Your results and mileage may vary
}
// Make the PAL run fast!
PAL.LockExecution;
{
**************************
* START OF CONFIGURABLES *
**************************
}
{
List of invalid characters.
'\', '/', ':', '*', '?', '"', '<', '>', '|' are invalid for filenames.
'''', '&', ' ', '_' are to make life easier.
}
var illegalCharacters : Array of String = ['\', '/', ':', '*', '?', '"', '<', '>', '|', '''', '&', ' ', '_'];
{
Replacement character.
}
var replacementCharacter : String = '-';
{
SAM picture directory.
Highly suggested to make a copy of the directory to test against first!
}
var pictureDir : String = '\\Webserver\Apache\htdocs\albumcovers\';
{
Table name.
Highly suggested to make a copy of songlist to test against first!
}
var tableName : String = 'songlist';
{
Limiter.
Suggest to do 250 at a time to prevent locking SAM.
}
var limitString : String = 'limit 250';
{
Is this cool or what?
var cool : Boolean = true;
}
{
************************
* END OF CONFIGURABLES *
************************
}
// IF YOU EDIT BELOW HERE, MAKE DARN SURE YOU KNOW WHAT'S GOING ON
// Declare/Initialize variables
var theSongs : TDataSet;
var newPictureName : String;
var outerLoop : Integer = 0;
var innerLoop : Integer = 0;
var didUpdate : Integer = 0;
var processed : Integer = 0;
// Removal of the following line by any means constitutes acceptance
var disclaimer : Boolean = OkCancelDlg('I understand the consequences of this PAL and hold myself responsible for the results.');
if (disclaimer) then
begin
// All SAM album covers have _ in them by default.
// This restriction allows the limiter to not select the same songs.
theSongs := Query('select id, artist, album, picture from ' + tableName + ' where picture like ' + QuotedStr('%\_%') + ' ' + limitString, [], true);
// Move pointer to first song
theSongs.First;
// While we still got songs to process...
while (not theSongs.EOF) do
begin
// Build the new picture name
newPictureName := theSongs['artist'] + '-' + theSongs['album'] + '.jpg';
// Here's the meat of the work
// Loop through it and replace invalid characters with the replacement
for outerLoop := 0 to (Length(newPictureName) - 1) do
begin
// Gotta check each character
for innerLoop := 0 to (illegalCharacters.length - 1) do
begin
if (CharAt(newPictureName, outerLoop) = illegalCharacters[innerLoop]) then
begin
SetCharAt(newPictureName, outerLoop, replacementCharacter);
end;
end;
end;
// Only process if the new picture name differs from the database value
if (not (newPictureName = theSongs['picture'])) then
begin
// Only rename the file if it doesn't exist
if (not (FileExists(pictureDir + newPictureName))) then
begin
// Rename and check for error
if (not (RenameFile(pictureDir + theSongs['picture'], pictureDir + newPictureName))) then
begin
ErrorDlg('Unable to rename ' + pictureDir + theSongs['picture'] + ' to ' + pictureDir + newPictureName);
end;
end;
// Only delete the old file if it exists
if (FileExists(pictureDir + theSongs['picture'])) then
begin
// Delete and check for error
if (not (DeleteFile(pictureDir + theSongs['picture']))) then
begin
ErrorDlg('Unable to delete ' + pictureDir + theSongs['picture']);
end;
end;
// Reset update checker.
// ExecSQL returns the number of rows processed.
didUpdate := 0;
// Do the update and check for error
didUpdate := ExecSQL('update ' + tableName + ' set picture = ' + QuotedStr(newPictureName) + ' where id = ' + IntToStr(theSongs['id']), []);
if (didUpdate <> 1) then
begin
ErrorDlg('Unable to update ' + tableName + ' from ' + theSongs['picture'] + ' to ' + newPictureName);
end;
// Increment processed
processed := processed + 1;
end;
// Move pointer to next song
theSongs.Next;
end;
end;
WriteLn('Processed ' + IntToStr(processed) + ' songs');
PAL.UnlockExecution;
// Be nice and free up the data structures
theSongs.Free;
