It is currently November 29th, 2021, 5:31 am

Nowplaying.dll to TXT

Discuss the use of Lua in Script measures.
Kobayen
Posts: 3
Joined: August 11th, 2017, 11:31 am

Nowplaying.dll to TXT

Post by Kobayen »

I wanted to know if anyone has ever written a script that takes the result string from NowPlaying.dll and send it to a txt file (so it can be captured and used by OBS). And if nobody had, how would one even start getting to do that?

I'm pretty sure this would involve scripting because of the file-writing part of the equation.
Kobayen
Posts: 3
Joined: August 11th, 2017, 11:31 am

Re: Nowplaying.dll to TXT

Post by Kobayen »

Window Capture needs to be set up every single time beforehand for a Photoshop stream, and Screen Capture assumes a given object will be drawn into the screen in a visible position at all times.

SMG stopped working for WinAMP for a while now, and newer versions where that bug is corrected are paid. 8 euro is quite an amount of cash in third-world-currency.
Kobayen
Posts: 3
Joined: August 11th, 2017, 11:31 am

Re: Nowplaying.dll to TXT

Post by Kobayen »

In the end, you solved my problem but not Quite the way I expected! :D Fuller's NowPlaying doesnt work for OBS (for a variety of reasons) but googling its name directed me to AMIP ( http://amip.tools-for.net/wiki/start ) -- which does have an option to output things to a text file the way OBS can actually use!

So, thanks for saving us both alot of needless work and worry. And 8 Euro. :bow:
FlyingHyrax
Posts: 232
Joined: July 1st, 2011, 1:32 am
Location: US

Re: Nowplaying.dll to TXT

Post by FlyingHyrax »

I see your problem is already solved, but just for future reference in case someone searches their way upon this thread - I do think this is doable with Lua.

Here's a quick and dirty script that takes the string value from a measure and appends it to a file:

Code: Select all

function Initialize()
    measureToSave = SKIN:GetMeasure(SELF:GetOption('MeasureToSave'))
    writeOnUpdate = SELF:GetNumberOption('WriteOnUpdate') == 1
    logFilePath = SKIN:MakePathAbsolute(SELF:GetOption('FileToWrite', 'default_log.txt'))
end

function Update()
    if writeOnUpdate then
        WriteMeasureValue()
    end
end

function WriteMeasureValue()
    local strVal = measureToSave:GetStringValue()
    local theFile = io.open(logFilePath, 'a')
    theFile:write(strVal .. "\n")
    theFile:close()
end

...and here is a corresponding skin that uses that script to write the current track name any time the track changes with the NowPlaying plugin:

Code: Select all

[Rainmeter]
Update=1000
MiddleMouseUpAction=[!Refresh]

[measureTrackname]
Measure=Plugin
Plugin=NowPlaying
PlayerName=CAD
PlayerType=Title
TrackChangeAction=[!CommandMeasure "measureWriteToFile" "WriteMeasureValue()"]

[measureWriteToFile]
Measure=Script
ScriptFile=.\save_measure_value.lua
MeasureToSave="measureTrackname"
FileToWrite="log.txt"
WriteOnUpdate=0

[meterTrackname]
Meter=String
MeasureName=measureTrackname
X=0
Y=0
W=200
H=25
SolidColor=0,0,0,100
FontSize=12
FontColor=255,255,255
ClipString=1
AntiAlias=1

The script could pretty easily be extended and cleaned up to add more flexibility, like writing the number value instead of the string value, writing to the top instead of the bottom of the text file, adding a prefix or suffix around the string written to the log, etc.
Flying Hyrax on DeviantArt
User avatar
MarcoPixel
Posts: 40
Joined: June 8th, 2012, 9:43 am
Location: Austria

Re: Nowplaying.dll to TXT

Post by MarcoPixel »

You could also use Snip for OBS, they pretty much support all major players except AIMP afaik.