Post subject: PAL:- Inject dedication info into Mp3 title stream
Posted: November 11th, 2004, 7:53 am
Junior User
Joined: October 25th, 2004, 3:14 am Posts: 74
*** This PAL is now complete. Please read further down for script ***
I have done a search and only found one request for this.
Not sure if it is possible to do, and if it is, if there is already a script out there.
If it is possible and there is not a script. I will try and do one. I am still very new to pal and all I have learnt is from looking at FesterHead's scripts. So I am not sure how far I will get .
I guess it would work something like this:-
Code:
On start of song Check if it's a request If it is check if there is a dedication If there is Change Title to <Artist - Title> + ~Request~ + Requested By + Dedication else Change Title to <Artist - Title> + ~Request~ Loop
It looks so simple when I look at it like this, but I guess it is not .
I have looked at FesterHead's "Title Changer" script and think that is my best bet on finding out how to do this.
If anyone has any suggestions or can help out it would be greatly appreciated.
Many thanks.
Last edited by xgeek on November 12th, 2004, 9:12 pm, edited 2 times in total.
Post subject: Re: Dedication info in Mp3 title stream
Posted: November 11th, 2004, 1:33 pm
Junior User
Joined: October 25th, 2004, 3:14 am Posts: 74
Well so for so good. I am just really stuck on retrieving the requester & message.
Still not sure if I can get it via a ActivePlayer.GetSongInfo command or if I need to use MySQL.
Other than that it works great
If anyone can advise if the ActivePlayer.GetSongInfo command can get the last bit of info I need. If not can someone help me with the MySQL part.
I know the information is in the requestlist table
And I know I need to search for (ActivePlayer.GetSongInfo['requestID']) within the ID field
Once I have found the right record I then need to assign
name to Requested_by
msg to Dedication_Message
Many thanks for any help on this.
Code:
PAL.Loop := True;
WriteLn('Waiting for next song to start'); PAL.WaitForPlayCount(1); {Wait for 1 songs to play} WriteLn('New song started');
// Not sure if I need this, but without it sometimes the injection does not happen. // Not sure if when (ActivePlayer.GetSongInfo['requestID']) gets called it is while the crossfade is happening and it gets the wrong answer PAL.WaitForTime(T['+00:00:05']); //Wait 5 secs //PAL.LockExecution;
// Test variables so I can test my logic before I get the MySQL code working var Requested_by : String = 'Anonymous'; var Dedication_Message : String = 'None';
// Instantiate a Song Info object var Song : TSongInfo; Song := TSongInfo.Create;
// Check if current song has a request ID if (ActivePlayer.GetSongInfo['requestID']) then Begin WriteLn('Song is a Request'); // Do some MySQL stuff here to get the "Requested by" & "Dedication Message" // Assign "Requested by" to Requested_by // Assign "Dedication Message" to Dedication_Message
// Test Requested_by. If null Requested_by = "Anonymous" // Test Dedication_Message. If null Dedication_Message = "None" // Maybe even need to parse the message to strip out line feeds?
If ((Requested_by = 'Anonymous') and (Dedication_Message = 'None')) then Begin WriteLn('Request without Dedication'); WriteLn(Requested_by); WriteLn(Dedication_Message); Song['artist'] := ActivePlayer.GetSongInfo['artist'] + ' - ' + ActivePlayer.GetSongInfo['title']; Song['title'] := '~Requested~'; Encoders.SongChange(Song); End else Begin WriteLn('Request with Dedication'); WriteLn(Requested_by); WriteLn(Dedication_Message); Song['artist'] := ActivePlayer.GetSongInfo['artist'] + ' - ' + ActivePlayer.GetSongInfo['title']; Song['title'] := '~Requested by ' + Requested_by + ' : Dedication:- ' + Dedication_Message + '~'; Encoders.SongChange(Song); End; End;
// PAL.UnlockExecution; WriteLn('Done....');
// Release data structures Song.Free;
// I just added this so my Debug text does not get cleared before I can read it. PAL.WaitForTime(T['+00:00:10']); //Wait 10 secs
Post subject: Re: Dedication info in Mp3 title stream
Posted: November 11th, 2004, 3:29 pm
Junior User
Joined: October 25th, 2004, 3:14 am Posts: 74
That was the final piece of the puzzle.
Hope you don't mind but I used your pal header as a template for this one.
It works great, but I still have one small problem. And that is with line feeds in the message. For every line feed Winamp displays a square box like a Wingdings font .
So I need to work on a parser for Dedication_Message.
Other than that it does what I need. It would be great if someone with more experience could give it the once over to see if I have made any noobie errors.
Any feedback is more than welcome.
Many thanks
Code:
{ Insert Request Dedication information into encoded stream : script by Xgeek (aka Xgeek) $Id: Inject Request Dedication.pal,v 0.05 2004/11/12
* This script would not have been possible without the help from FesterHead. Thank You!!!
What this PAL does: * On song change checks to see if the song was requested, and if it was: * If no dedication information it will inject ~Requested~ in the title stream after Artist - Title * If dedication information it will inject ~Requested by <Name> : Who had this to say:- <Message>~ in the title stream after Artist - Title
What is configurable: * Nothing
PAL built to run continuously: * Switch to a desktop with the 'PAL Scripts' window visible
* Click '+' (Add new PAL script)
* Check the 'Automatically start script' box
* Click the folder icon and navigate to this script
* Click 'OK'
* Highlight PAL and click 'Start selected PAL script' (VCR type play button)
* Save settings by clicking the 'File' menu item and selecting 'Save Configuration' }
PAL.Loop := True;
WriteLn('New song started');
WriteLn('Waiting 5 Seconds before checking if it is a Request'); // Wait a few seconds just in case this song is a Jingle. If it is, and it is under 10 seconds the script will still get the correct info for the song after. PAL.WaitForTime(T['+00:00:05']); //Wait 5 secs PAL.LockExecution;
// Instantiate a Song Info object var Song : TSongInfo; Song := TSongInfo.Create;
WriteLn('Checking if song has been Requested......'); if ((ActivePlayer.GetSongInfo['requestID']) = 0) then WriteLn('Song is not a Request');
// Check if current song has a request ID if ((ActivePlayer.GetSongInfo['requestID']) > 0) then Begin WriteLn('Song is a Request'); var reqInfo : TDataSet = Query('SELECT name, msg FROM requestlist WHERE id = ' + ActivePlayer.GetSongInfo['requestID'], [], true); var Requested_by : String = reqInfo['name']; var Dedication_Message : String = reqInfo['msg']; reqInfo.Free;
If (Requested_by = '') then Requested_by := 'Anonymous'; If (Dedication_Message = '') then Dedication_Message := 'Nothing...';
If ((Requested_by = 'Anonymous') and (Dedication_Message = 'Nothing...')) then Begin WriteLn('Song is a Request without Dedication'); WriteLn(Requested_by); // This should aways echo Anonymous WriteLn(Dedication_Message); // This should aways echo Nothing... Song['artist'] := ActivePlayer.GetSongInfo['artist'] + ' - ' + ActivePlayer.GetSongInfo['title']; Song['title'] := '~Requested~'; Encoders.SongChange(Song); End else Begin WriteLn('Song is a Request with a Dedication'); WriteLn(Requested_by); WriteLn(Dedication_Message); Song['artist'] := ActivePlayer.GetSongInfo['artist'] + ' - ' + ActivePlayer.GetSongInfo['title']; Song['title'] := '~Requested by ' + Requested_by + ' : Who had this to say:- ' + Dedication_Message + '~'; Encoders.SongChange(Song); End; End;
PAL.UnlockExecution; WriteLn('Done....');
// Release data structures Song.Free;
WriteLn('Waiting for next song to start'); PAL.WaitForPlayCount(1); {Wait for 1 songs to play} { ************** * Change log * **************
Revision 0.05 2004/11/12 xgeek }
Last edited by xgeek on November 12th, 2004, 7:08 pm, edited 2 times in total.
Post subject: Re: Dedication info in Mp3 title stream
Posted: November 11th, 2004, 3:53 pm
Cygnus X-1
Joined: March 11th, 2003, 1:34 pm Posts: 9656 Location: Maui, HI
I don't mind you or anybody using my template.
If you put your PALs under CVS control and use keywords you can get the Id and log section filled out automatically
Nice to see some code commented and indented.
Makes it easier to read and understand.
Yes. I image the line breaks would show up funny kine.
Yes. You will need to parse/replace the line breaks.
Not sure how long the title can be so be careful of really long dedications as results may be unpredicatble.
Couple ideas:
* Make sure to free reqInfo, too.
* Might want to use a PAL.WaitForPlayCount(1) at the end to keep the request info until song change rather than rebuilding every 10 seconds.
* might want to change the initial check to see if the request id is > 0 rather than interpreting it as a boolen. Since 0 is false and non-zero is true there may in the future be problems if a requestid is negative. That probably won't happen, though, and it's just personal preference speaking.
_________________ - Steve Kunitzer - SVS (Spacial Volunteer Support) / Forum Administrator
Post subject: Re: Dedication info in Mp3 title stream
Posted: November 11th, 2004, 4:16 pm
Junior User
Joined: October 25th, 2004, 3:14 am Posts: 74
Okay changes made. And code above updated.
Cheers
FesterHead wrote:
Couple ideas: * Make sure to free reqInfo, too. Done. But I got a compile error when I added it under song.Free;. So I added it in the IF statement just under the last time that reqInfo is used.
* Might want to use a PAL.WaitForPlayCount(1) at the end to keep the request info until song change rather than rebuilding every 10 seconds. Hmm I have one at the top . Are you saying I need to add another one at the bottom. As it is the script only runs once on a song change
* might want to change the initial check to see if the request id is > 0 rather than interpreting it as a boolen. Since 0 is false and non-zero is true there may in the future be problems if a requestid is negative. That probably won't happen, though, and it's just personal preference speaking. Done.
Post subject: Re: Dedication info in Mp3 title stream
Posted: November 12th, 2004, 4:12 pm
Junior User
Joined: October 25th, 2004, 3:14 am Posts: 74
By using FesterHeads search info I came up with this. It works okay and is a simple script.
If you want to censor dedication text for bad words you will need to edit 1 file and add a new file.
First edit req/req.dedication.php and add this under <?
Code:
##################################### ## Mod to Filter banned words from request messages include('filter.php'); $result = Filter($rmessage,1); #####################################
Save and upload the file.
Second copy and paste this code into a text file. Then save the text file as filter.php
You will need to add the bad words to the script before uploading it. Once you have added the words you want censored upload it to /req/
This function does all the work. If $replace is 1 it will replace all bad words with the wildcard replacements. If $replace is 0 it will not replace anything. In either case, it will return 1 if it found bad words or 0 otherwise.Be sure to fill the $bads array with the bad words you want filtered.
function Filter(&$text, $replace) { //fill this array with the bad words you want to filter and their replacements $bads = array ( array("Fool","F**l"), array("crap","c***") );
if($replace==1) { //we are replacing $remember = $text;
for($i=0;$i<sizeof($bads);$i++) { //go through each bad word $text = eregi_replace($bads[$i][0],$bads[$i][1],$text); //replace it }
if($remember!=$text) return 1; //if there are any changes, return 1
} else {
//we are just checking for($i=0;$i<sizeof($bads);$i++) { //go through each bad word if(eregi($bads[$i][0],$text)) return 1; //if we find any, return 1 }
} }
?>
Last edited by xgeek on November 12th, 2004, 7:14 pm, edited 1 time in total.
Post subject: Re: Dedication info in Mp3 title stream
Posted: November 12th, 2004, 7:00 pm
Junior User
Joined: October 25th, 2004, 3:14 am Posts: 74
Okay I could not find a way to parse the line feeds via pal. I spent about 5 hours looking at scripts and searching. So I gave up and decided to do it server side.
If you use this script and want to remove line feeds from the dedication so winamp displays them okay. Add this just under <? in /req/req.dedication.php
Code:
##################################### ## Mod to strip Line Feeds from the request message $rmessage = preg_replace("#\r\n#"," ",$rmessage); #####################################
Users browsing this forum: Google [Bot] and 1 guest
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum