it works on my win2k machine with winamp 2.91, so if it doesn't work
on your computer, let me know. it should also work for e-mails, but
i haven't tried it since i use dialog for usenet only.
feedback much appreciated.
program OnBeforeSendingMessage;
// ----------------------------------------------------------------------
const
winampWindowTitle = 'Winamp v1.x';
WM_USER = 1024;
WM_WA_IPC = WM_USER;
IPC_GETVERSION = 0;
MB_YESNO = 4;
IDYES = 6;
IDNO = 7;
// ----------------------------------------------------------------------
function findWindow(c1, c2: PChar): Cardinal; external 'FindW...@user32.dll stdcall';
function getWindowTextLength(hWnd: Cardinal): Integer; external 'GetWindowT...@user32.dll stdcall';
function getWindowText(hWnd: cardinal; lpString: PChar; nMaxCount: Integer): Integer; external 'GetWind...@user32.dll stdcall';
function messageBox(hWnd: Cardinal; lpText, lpCaption: PChar; uType: longword): Integer; external 'Messa...@user32.dll stdcall';
// ----------------------------------------------------------------------
function findWinampHWND : cardinal;
begin
result := findWindow (winampWindowTitle, null);
end;
// ----------------------------------------------------------------------
function winampSong (winampHWND:cardinal) : string;
var titleLen : integer;
tempInt : integer;
tempStr : string;
plNum : integer;
tempmp3 : string;
begin
// used in case winamp is not running or the window is not found
tempStr := 'nothing';
// if winamp's window is found...
if winampHWND <> 0 then
begin
// find the caption text of winamp's window
titleLen := getWindowTextLength (winampHWND) + 2;
setLength (tempStr, titleLen);
getWindowText (winampHWND, pchar(tempStr), titleLen);
setLength (tempStr, length(tempStr));
// the window title is "x. song artist - song name - Winamp", where the x
// is the playlist position, but we don't want that, so we'll remove both
tempInt := pos (' - Winamp', tempStr);
plNum := pos (' ', tempStr) + 1;
tempStr := copy (tempStr, plNum, tempInt - plNum);
// check if the string ends with '.mp3' and remove it
tempmp3 := lowerCase (copy (tempStr, length(tempStr) - 3, 4));
if tempmp3 = '.mp3' then
begin
tempStr := copy (tempStr, 1, length(tempStr) - 4);
end;
end; // if winampHWND <> 0
result := TempStr;
end;
// ----------------------------------------------------------------------
function OnBeforeSendingMessage(var Message: TStringlist; Servername: string; IsEmail: boolean):boolean;
var tempSong : string;
begin
// don't do anything for e-mails, nobody looks at e-mail headers anyway :)
if isEmail = false then
begin
// get the song name
tempSong := winampSong (findWinampHWND);
// uncomment the line below to get a messagebox asking you if you wish
// to include the X-Now-Playing header in your post
// if (MessageBox(null, 'Insert X-Now-Playing: "' + tempSong + '"?', 'Insert X-Header?', MB_YESNO) = IDYES) then
// insert the x-header at the beginning of the message, dialog (or perhaps
// the news server) will sort it out as necessary.
message.insert (1, 'X-Now-Playing: "' + tempSong + '"');
// use this if you also wish to add the song name to the bottom of your post:
// message.add ('');
// message.add ('Now playing: ' + tempSong);
end;
result := true;
end;
// ----------------------------------------------------------------------
begin
end.
--
there is a cheer. the gnomes have learned a new way to say hooray. [-shpongle]
address is scrambled - remove SPAMISEVIL to reply
> i've written a nice little script that will add an "X-Now-Playing: song"
> header to your posts or at the end of them.
Damn cool! Thanks for sharing.
--
J. Cifer
and i've found a "bug". if winamp is not running, you get
X-Now-Playing: "nothing", which looks weird. here's a portion
of the script to fix it. of course, there's still the issue
when the song's name is actually "nothing" ;))
-----
// get the song name
tempSong := winampSong (findWinampHWND);
if tempSong <> 'nothing' then tempSong := '"' + tempSong + '"';
// uncomment the line below to get a messagebox asking you if you wish
// to include the X-Now-Playing header in your post
// if (MessageBox(null, 'Insert X-Now-Playing: ' + tempSong + '?', 'Insert X-Header?', MB_YESNO) = IDYES) then
// insert the x-header at the beginning of the message, dialog (or perhaps
// the news server) will sort it out as necessary.
message.insert (1, 'X-Now-Playing: ' + tempSong);
-----
my pleasure. i fixed some quirks since posting, but i'll send
a new version as soon as i get it to work with winamp 3.x.
i'll also try making it as configurable as possible - with or
without quotation marks / winamp version / adding the song name
to the bottom of the post, etc.
> my pleasure. i fixed some quirks since posting, but i'll send
> a new version [cut] i'll also try making it as configurable as possible
Please do, I'd love to use your script when it's «finished» :)
Great idea, and good scripting skills (I guess, mine are equal to 0 ;))
G
--
_____ Farewell! _ _ ___ ~ ICQ# 16553733 mailto:gandalf*ithn.net
| __|___ ___ _| |___| | _| ~ 40tude Dialog http://snurl.com/dialog
| | | .'| | . | .'| | _| ~ Google Groups http://snurl.com/ggroup
|_____|__,|_|_|___|__,|_|_| ~ ITHNetiquette http://snurl.com/ithnet
> my pleasure. i fixed some quirks since posting, but i'll send
> a new version as soon as i get it to work with winamp 3.x.
> i'll also try making it as configurable as possible - with or
> without quotation marks / winamp version / adding the song name
> to the bottom of the post, etc.
Two questions:
Have you added it to the script repository on the Dialog wiki pages?
You've already shown me how to add a header, can you give me a tip how to
delete a header on sending a message as well?
Thanks!
--
J. Cifer
>
> i've written a nice little script that will add an "X-Now-Playing: song"
> header to your posts or at the end of them.
>
> it works on my win2k machine with winamp 2.91, so if it doesn't work
> on your computer, let me know. it should also work for e-mails, but
> i haven't tried it since i use dialog for usenet only.
>
> feedback much appreciated.
Nice script. Unfortunately i can't try it out since i already have a
OnBeforeSending script running here which creates my expires... email
address. So i first have to integrate them both, but that shouldn't be to
hard. :-) Maybe i'll do that later today
thanx anyway!
Cheers, Dirk
--
"You know the world is going crazy when the best rapper is a white guy,
the best golfer is a black guy, The Swiss hold the America's Cup,
France is accusing the US of arrogance, and Germany doesn't want to
go to war."
not yet. i'll do so as soon as people on this and the croatian
news software groups say it's working as expected :)
> You've already shown me how to add a header, can you give me a tip how to
> delete a header on sending a message as well?
index := message.indexOf ('what you are searching for');
message.delete (index);
if you don't know the search string exactly, traversal
will be necessary:
for n := 0 to message.count do
if pos ('something', message[n]) <> 0 then message.delete (n);
so, if you're searching for 'X-Foo: bar' which is constant,
you go with the first method. if the X-Foo header changes
(e.g. 'X-Foo: bar' or 'X-Foo: baz' or 'X-Foo: quux' or...),
the second method should be used, and this time you're
searching only for 'X-Foo'.
> not yet. i'll do so as soon as people on this and the croatian
> news software groups say it's working as expected :)
[...]
For me, it's working just fine ;-)
--
=| ChaKy <ch...@softhome.net> | ICQ:96731865 |=
"Going back into time, blind through the night"
Now playing: "Robert Miles - Piano In Trance" (Winamp 2.91)