Item.Attribute Possible?

Hi there,

I was wondering is there a way to recall an attribute in a script? I would like to create a ‘now playing’ script that includes a set field from the song’s attribute list.

i.e. Instead of Item.GetTitle … it’s like: Item.GetAttribute.AttributeName ?

Best,
Marc5000

Absolutely yes!

My YearJingleAdder script (http://forum.mairlist.com/index.php/topic,4658.msg33223.html) does that.

The line I used in that script is:
sYear := Trim(piNextItem.GetAttributes.GetValue(‘Year’));
piNextItem is a Playlist Item object, and the line above reads the Item’s Year attribute.

The YearJingleAdder script does several checks before trying to read this, but you understand the line above, I hope?

BFN
CAD

Hi,

Thanks for the reply!! I knew there was a way! I think I’m being a bit naive to the language at hand. I am trying to recall those functions as additional lines in the ‘Now Playing’ script by Charlie Davy.

Are you able to guide me in the right direction on how to implement this into that script? I’ve been trying to add it into the Now Playing script and getting errors when mAirList loads, but I suspect I’m missing some lines of code out?

Best,
Marc5000

Can you put Charlie’s original script AND your version of it into a ZIPfile and post it here? I’d really need to pore over both to see what’s wrong.

Also include any error messages you get when you try to trun your version. That will help a lot. I think you can copy/paste those from the mAirList System Log into a text file, but don’t quote me on that. :smiley: If so, please include that text file in the ZIPfile as well.

BFN
CAD

Hey CAD,

Thanks for getting back. Like I said, I am quite naive toward most of this kind of code. Effectively, I am just adding a mod what you posted to a line in Charlie’s code.

sl.Add (piNextItem.GetAttributes.GetValue(‘Year’));

I would love it so that whenever I need to recall an Attribute Type, it just shows up and adds it as text. So if I needed the year, it would just spit out: 1985, for example. I am probably missing out loads of lines or am not doing it properly somehow. If you could let me know, I would be humbled!

The main error I’m getting is: Unknown identifier

However, in your script, everything seems to work fine! So I am very miffed.

Thanks again CAD, really appreciate it.


attribute_error.zip (3.81 KB)

OK, several points here:

  1. piNextItem was a var in my original script. Put another way, because you hadn’t declared it, mAirList didn’t know about it. Plus, what you’ve got here is a custom NOTIFICATION script, which is called when (in this case) a Player starts. So: you need to use the IPlaylistItem defined in the OnPlayerStart line to access the item which has just started playing; and that is (perhaps confusingly) named Item. I’ve fixed that for you.

  2. The version of the script you had would probably have screwed up when checking item duration. This isn’t your fault: time values in mAirList now have their own custom built-in functions to change them to and from seconds, via a single precision float variable/value. I’ve fixed that for you as well, and made sure this is read only once.

  3. For similar reasons, the artist code would have failed. mAirList now supports multiple artists per item, so the correct function is now GetArtistsString. I’ve fixed that for you as well.

I’ve also split out the URL, PHP filename, etc. as consts. That way, you only need to change them ONCE if (say) the page name, user, or password is changed (you DO change the password regularly, right?). That’s what we programmers call ‘manifest constants.’ :wink:

Finally, I’ve improved the indenting to make what the script is doing somewhat clearer.

So although I haven’t run it or anything, here’s the corrected script, which should work without crashing unless I’ve made some daft typo somewhere. 8)

PS: You DO know you have to add the finished, working script to your Notification Script list in Config, right?

BFN
CAD


modified.mls (3.11 KB)