🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #126733

[dialog] X-Now-Playing script :)

#126733
From: matija
Date: Sat, 21 Jun 2003 13:11
136 lines
5294 bytes
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.



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 'FindWindowA@user32.dll stdcall';
function getWindowTextLength(hWnd: Cardinal): Integer; external 'GetWindowTextLengthA@user32.dll stdcall';
function getWindowText(hWnd: cardinal; lpString: PChar; nMaxCount: Integer): Integer; external 'GetWindowTextA@user32.dll stdcall';

function messageBox(hWnd: Cardinal; lpText, lpCaption: PChar; uType: longword): Integer; external 'MessageBoxA@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
Technical Details
Message-ID: <1m063ufypbf7v.dlg@shpongle.604>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.mbox.zip!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!newsfeed.vmunix.org!fu-berlin.de!CARNet.hr!not-for-mail

Show Full Headers
Complete Article Headers
Message-ID: <1m063ufypbf7v.dlg@shpongle.604>
Subject: [dialog] X-Now-Playing script :)
Date: Sat, 21 Jun 2003 15:11:17 +0200
From: matija <mSkPrAnMic@jaIgSor.srEcVe.IhLr>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.mbox.zip!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!newsfeed.vmunix.org!fu-berlin.de!CARNet.hr!not-for-mail
Newsgroups: news.software.readers
Organization: 604
Lines: 135
NNTP-Posting-Host: cmung3109.cmu.carnet.hr
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
X-Trace: bagan.srce.hr 1056201077 24377 193.198.140.61 (21 Jun 2003 13:11:17 GMT)
X-Complaints-To: abuse@carnet.hr
NNTP-Posting-Date: Sat, 21 Jun 2003 13:11:17 +0000 (UTC)
X-Now-Playing: "nothing"
X-Face: "7>Vm?rO.@qh|TIsbG@X7>asBJ8BSLKs%T@Wd+qgN<P?}[3`e1(M~;NT:f=hn#iN:nyAWyT fR9pPzc9ON|MqY_5Fvk)9[+7Lu!%Ihw.GS]KBQF6K_Vn1J2sB{Ne@3Fa5G-z
X-Afraid-Of: spiders
X-Searching-For: GMT soundtrack (guy sigsworth)
X-Mastered: the art of pizza making
User-Agent: 40tude_Dialog/2.0.5.53hr (48dcb0ff.508.68)