WatchFoobar lets you monitor and display what foobar2000 is playing. The script retrieves the information from Foobar and turns it into a variable that can be used everywhere in Opus. For instance in a button:
How to set up and use
Download and install foobar2000 or run
winget install --silent --id PeterPawlowski.foobar2000
from a command line.
Download and install foo_nowplaying2 from GitHub. This component does the heavy lifting for us.
Configure foo_nowplaying2 in foobar2000:
Paste
%temp%\foobar2000NowPlaying.dop
into the file open dialog (the environment variable needs to expand).
If you want to replicate the demo from above, paste
%artist% - %title% - %playback_time%
into the Format space.
Now Playing 2 offers a gazillion more options - your choice!
Save CommandWatchFoobar.js.txt to ↓
%appdata%\GPSoftware\Directory Opus\Script AddIns
Use WatchFoobarStart and WatchFoobarStop to start and stop the monitoring. The variable
$glob:foobar2000Monitor
will be on
or off
.
Use the variable
$glob:foobar2000NowPlaying
to retrieve the current information.
This button from the demo combines everything:
// For reference only. Get the fully functional button from below
@evalalways:fb2000mon = Val("$glob:foobar2000Monitor")=="on"
@label:fb2000mon ? Val("$glob:foobar2000NowPlaying") : "<not monitoring>"
@toggle:update
=return fb2000mon ? "WatchFoobarStop" : "WatchFoobarStart"
XML
<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none">
<label>foobar2000NowPlaying</label>
<icon1>{apppath|foobar2000}foobar2000.exe,-105</icon1>
<function type="normal">
<instruction>@evalalways:fb2000mon = Val("$glob:foobar2000Monitor")=="on"</instruction>
<instruction>@label:fb2000mon ? Val("$glob:foobar2000NowPlaying") : "<not monitoring>"</instruction>
<instruction>@toggle:update</instruction>
<instruction />
<instruction>=return fb2000mon ? "WatchFoobarStop" : "WatchFoobarStart"</instruction>
<instruction />
<instruction>// https://resource.dopus.com/t/watchfoobar-monitor-what-foobar2000-is-playing/51286</instruction>
</function>
</button>
Things you might enjoy reading
How to use buttons and scripts from this forum
The script's inner workings
JScript
function OnInit(initData) {
initData.name = 'WatchFoobar';
initData.version = '2024-06-14';
initData.url = 'https://resource.dopus.com/t/watchfoobar-monitor-what-foobar2000-is-playing/51286';
initData.desc = 'WatchFoobar';
initData.default_enable = true;
initData.min_version = '13.0';
}
function OnAddCommands(addCmdData) {
var cmd = addCmdData.AddCommand();
cmd.name = 'WatchFoobarStart';
cmd.method = 'OnWatchFoobarStart';
cmd.desc = 'WatchFoobarStart';
cmd.label = 'WatchFoobarStart';
cmd.template = '';
cmd.hide = false;
cmd.icon = 'script';
var cmd = addCmdData.AddCommand();
cmd.name = 'WatchFoobarStop';
cmd.method = 'OnWatchFoobarStop';
cmd.desc = 'WatchFoobarStop';
cmd.label = 'WatchFoobarStop';
cmd.template = '';
cmd.hide = false;
cmd.icon = 'script';
}
function OnWatchFoobarStart(scriptCmdData) {
var fsu = DOpus.FSUtil();
var item = fsu.Resolve('%temp%\\foobar2000NowPlaying.dop');
var itemID = 'foobar2000NowPlaying';
fsu.WatchChanges(itemID, item, 'fisw');
DOpus.vars.Set('foobar2000Monitor', 'on');
}
function OnWatchFoobarStop(scriptCmdData) {
var fsu = DOpus.FSUtil();
var itemID = 'foobar2000NowPlaying';
fsu.CancelWatchChanges(itemID);
DOpus.vars.Set('foobar2000Monitor', 'off');
}
function OnFilesystemChange(FilesystemChangeData) {
var itemID = 'foobar2000NowPlaying';
if (FilesystemChangeData.id != itemID) return;
var cmd = DOpus.Create().Command();
var fsu = DOpus.FSUtil();
var stt = DOpus.Create().StringTools();
var item = fsu.GetItem(fsu.Resolve('%temp%\\foobar2000NowPlaying.dop'));
if (fsu.Exists(item)) {
var tmpFile = item.Open();
var tmp = stt.Decode(tmpFile.Read(), 'utf8');
tmpFile.Close();
var nowPlaying = tmp ? tmp : '<none>';
} else {
var nowPlaying = '<none>';
}
DOpus.vars.Set(itemID, nowPlaying);
cmd.UpdateToggle();
}
// reference as
// Val("$glob:foobar2000NowPlaying")
// Val("$glob:foobar2000Monitor")