Article View: news.software.readers
Article #135676Re: [Dialog] [Dialog] foobar X-Now-Playing script
From: Jernej Simončič
Date: Sat, 18 Oct 2003 12:33
Date: Sat, 18 Oct 2003 12:33
148 lines
7880 bytes
7880 bytes
On Sat, 18 Oct 2003 14:12:23 +0200, Antonio 'Gandalf' Favata wrote:
> Thanks! So the «someone» I was talking about is Jernej Simončič...
> Please, Jernej, would you share the script? :)
Sure, here it is:
//program foobar2000;
(* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *)
(* Script: Add X-Now-Playing based on infromation from foobar2000 <http://foobar2000.hydrogenaudio.org/> *)
(* Version: 0.11 *)
(* Author: Jernej Simoncic <jernej simoncic at guest arnes si> *)
(* *)
(* Usage: The script directly inserts the text from your foobar2000 titlebar; use it's excellent formatting *)
(* formatting functions to fit the text to your needs; the script won't add anything if the titlebar starts with *)
(* foobar2000 - as this normally means that the player is stopped *)
(* You can set exactly what is added to the message below *)
(* *)
(* Tested with foobar2000 0.667 on Win2k. *)
(* *)
(* Changelog: *)
(* 0.10 - first release *)
(* 0.11 - can be used with $include *)
(* *)
(* ToDo: *)
(* - 8-bit/unicode character processing *)
(* *)
(* Use this script at your own risk. *)
(* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *)
const
EMail = 1; News = 2; XHeader = 1; EndOfMessage = 2;
(* * * * * * * * * * * * * * * * * * * * * * * * * * SETTINGS * * * * * * * * * * * * * * * * * * * * * * * * * *)
UseWith = EMail + News; //EMail: e-mail messages; News: newsgroup posts
AddTo = XHeader {+ EndOfMessage}; //XHeader, EndOfMessage
XHeaderText = 'X-Now-Playing: %song%'; //the x-header text to add
EndMessageText = '%n%Now playing: %song%'; //text to add to end of message
//In both XHeaderText and EndMessageText, %song% will be replaced by the song title; if %song% doesn't appear
//in the text, song title is added at the end
//You can also use %n% in the EndMessageText to represent a line break
(* * * * * * * * * * * * * * * * * * * * * * * * * END OF SETTINGS * * * * * * * * * * * * * * * * * * * * * * *)
fb2kWindowClass = 'FOOBAR2000_CLASS'; //don't change unless you know what you're doing
function FindWindow(lpClassName, lpWindowName: PChar): Cardinal; external 'FindWindowA@user32.dll stdcall';
function GetWindowTextLengthA(hWnd: Cardinal): Integer; external 'GetWindowTextLengthA@user32.dll stdcall';
function GetWindowTextA(hWnd: cardinal; lpString: PChar; nMaxCount: Integer): Integer; external 'GetWindowTextA@user32.dll stdcall';
function MessageBox(hWnd: Cardinal; lpText: WideString; lpCaption: WideString; uType: longword): Integer; external 'MessageBoxW@user32.dll stdcall';
procedure MsgBox(text: WideString);
begin
MessageBox(null,text,'aaa',0);
end;
function GetFB2kTitle: WideString;
var handle: Cardinal;
tlen,i: Integer;
titlea: String;
begin
titlea := ''
handle := FindWindow(fb2kWindowClass, null);;
if (handle <> 0) then
begin
tlen := GetWindowTextLengthA(handle)+1;
SetLength(titlea, tlen);
i := GetWindowTextA(handle, PChar(titlea), tlen);
SetLength(titlea, Length(titlea)-1);
end;
Result := titlea;
end;
function foobar2000(var Message: TStringlist; IsEmail: boolean): boolean;
var song, text: WideString;
i: Integer;
begin
if (((not isEmail) and ((UseWith and News) = News)) or (isEmail and ((UseWith and EMail) = EMail))) then
begin
song := GetFB2kTitle();
if (song = '') then
exit;
if (Copy(song,1,10) = 'foobar2000') then
exit;
if ((AddTo and XHeader) = XHeader) then
begin
if (Pos('%song%',XHeaderText) > 0) then
text := StringReplace(XHeaderText,'%song%',song,[rfReplaceAll])
else
text := XHeaderText + song;
//clean 8-bit characters from header
for i := 127 to 255 do
if (Pos(Chr(i),text) > 0) then
text := StringReplace(text,Chr(i),'_',[rfReplaceAll]);
//sanity checks
if (Copy(text,1,2) <> 'X-') then
text := 'X-' + text;
if (Pos(': ', text) > 2) and (Pos(': ',text) < (Length(text)-3)) then
for i := 0 to Message.Count - 1 do
if (Message.Strings[i] = '') then //insert as the last x-header
begin
Message.Insert(i, text);
break;
end;
end;
if ((AddTo and EndOfMessage) = EndOfMessage) then
begin
if (Pos('%song%', EndMessageText) > 0) then
text := StringReplace(EndMessageText,'%song%',song,[rfReplaceAll])
else
text := EndMessageText + song;
text := StringReplace(text,'%n%',#13#10,[rfReplaceAll]);
Message.Add(text);
end;
end;
Result := True;
end;
(*var s: WideString;
begin
s := GetFB2kTitle;
MsgBox(s);
end.*)
Note that it currently gets the text from FB2k's titlebar; I'll work on
this later.
--
Jernej Simončič, <jernej simoncic at guest arnes si>
http://www2.arnes.si/~sopjsimo/
Technical Details
Message-ID:
<xd4xuil2gaoj.dlg@deepthought.ena.si>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.20140922.mbox.gz!text1.nnrp.aus1!firehose2!nntp4!intern1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeed.arcor-online.net!fu-berlin.de!uni-berlin.de!tm.213.143.81.18.dc.telemach.NET!not-for-mailReferences:
<1n0078t63g3jq.dlg@gandalf.my-fqdn.de> <2f4o07cfixhh.dlg@darkside.df> <myeh33t3ib1v$.dlg@gandalf.ithn.net>Show Full Headers
Complete Article Headers
Message-ID: <xd4xuil2gaoj.dlg@deepthought.ena.si>
Subject: Re: [Dialog] [Dialog] foobar X-Now-Playing script
Date: Sat, 18 Oct 2003 14:33:09 +0200
From: Jernej Simončič <echo@arnes.si>
References: <1n0078t63g3jq.dlg@gandalf.my-fqdn.de> <2f4o07cfixhh.dlg@darkside.df> <myeh33t3ib1v$.dlg@gandalf.ithn.net>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.20140922.mbox.gz!text1.nnrp.aus1!firehose2!nntp4!intern1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeed.arcor-online.net!fu-berlin.de!uni-berlin.de!tm.213.143.81.18.dc.telemach.NET!not-for-mail
Newsgroups: news.software.readers
Organization: E-mailaholics International
Lines: 148
NNTP-Posting-Host: tm.213.143.81.18.dc.telemach.net (213.143.81.18)
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-13"
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de 1066480392 27397928 213.143.81.18 (16 [164251])
User-Agent: 40tude_Dialog/2.0.6.59 (49fef76b.425.390)
X-Face: ({psVvcpp>XZONa#L#5M3]]Yf-Q01XtQPi@z8PAz,4L{=1^2NE[D.m@[5^_h697j7}~F;
$| G$U/6Jkm(&MWj-OSHX; :R-5JHY8(!H3va:?&_dI/,)a4(a=B0;
C&PQRVLAK:cIHU:1DGYpkcC["%%) 3@[GLdB)#X,Mc8
X-Ultimate-Answer: 42