Page 1 of 2
How do I get the 'AlbumArtist' property
Posted: Sun Aug 21, 2005 4:29 am
by Neil Sunderland
I've written the following script that writes the name, artist and album of the currently playing track to a text file; whenever I send an email that information is added to my .sig, and the recipient can then judge whether the music I'm listening to is affecting the tone of my message
Code: Select all
Sub Main()
Dim oFSO, oOutput, oTrack, oAlbum, sAlbumArtist
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oOutput = oFSO.CreateTextFile("CookieData.txt")
Set oTrack = SDB.Player.CurrentSong
Set oAlbum = oTrack.Album
'Need to get the AlbumArtist Property, not the Track Artist
AlbumArtist = oAlbum.Artist.Name
oOutput.Write "NP: " & oTrack.ArtistName & " - " & oTrack.Title
If (Instr(oTrack.AlbumName, "Best")=0 And Instr(oTrack.AlbumName, "Greatest")=0) Or _
Instr(AlbumArtist, "Various")=0 Then
oOutput.Write " (from the album " & Track.AlbumName & ")"
End If
oOutput.Close()
Set oTrack = Nothing
Set oAlbum = Nothing
Set oOutput = Nothing
Set oFSO = Nothing
End Sub
I've set the AlbumArtist for multi-artist albums in my database to 'Various Artists'; I don't want to display the Album details for these, but I can't find the AlbumArtist property in the Online Help. The Album.Artist.Name is returning the Artist property for the track.
Am I missing something obvious?
Posted: Sun Aug 21, 2005 1:17 pm
by tvjunky
I think the property you're looking for is indeed "AlbumArtistName" from an "SDBSongData" object. I'm unable to find it in
webhelp, however you can verify the property's existence in the
downloadable .chm file.
To make your script work as intended (I just skimmed it) it is probably enough to change
Code: Select all
If (Instr(oTrack.AlbumName, "Best")=0 And Instr(oTrack.AlbumName, "Greatest")=0) Or _
Instr(AlbumArtist, "Various")=0 Then
oOutput.Write " (from the album " & Track.AlbumName & ")"
End If
to
Code: Select all
If (Instr(oTrack.AlbumName, "Best")=0 And Instr(oTrack.AlbumName, "Greatest")=0) Or _
Instr(oTrack.AlbumArtistName, "Various")=0 Then
oOutput.Write " (from the album " & Track.AlbumName & ")"
End If
hth, tvjunky
How do I get the 'AlbumArtist' property
Posted: Sun Aug 21, 2005 2:56 pm
by Neil Sunderland
That's perfect. Thank you!
How are you adding this content to your email sig?
Posted: Wed Oct 19, 2005 7:57 pm
by milesy20
What email app are you using? Could you provide examples?
Thanks in advance!
Posted: Sat Apr 15, 2006 7:35 am
by kalex
Please excuse the newbie question, this is exactly what I was looking for, but where do I put the script so that it automatically does its work when I play a song? Into the auto folder? Do I have to edit the script.ini as well?
[about the email app - I'm using "The Bat!" from Ritlabs, it has a template system for messages with a macro language that allows to include text files very easily, %INCLUDE("D:\nowplaying.txt") for example]
Thanks...
Posted: Sat Apr 15, 2006 11:09 am
by Steegy
Hi
The script has to be in MediaMonkey's "Scripts" folder, and you have to add an entry to the "Scripts.ini" file. See the example below:
Code: Select all
[SignatureWriter]
FileName=SignatureWriter.vbs
ProcName=Main
Order=1
DisplayName=SignatureWriter
Description=SignatureWriter
Language=VBScript
ScriptType=2
This supposes that you named the script text file "SignatureWriter.vbs".
BTW: ScriptType=2 means that the script will be launched each time a song starts playing.
More information:
http://faq.mediamonkey.com/index.php?ac ... artlang=en
Cheers
Steegy
Posted: Sat Apr 15, 2006 11:41 am
by kalex
Thanks, it works now. I got the RTFM hint.
However (this question goes to the original script author), when I stop the song, or exit MM (though I have the feeling that is seldomly gonna happen, I start to rrrrreally like the program), the textfile remains. Seeing that there is no "stop" action in the scripts type, I wonder if its possible to delete the file when the song is stopped and/or MM is quit?
Posted: Sat Apr 15, 2006 12:07 pm
by Steegy
Am I not good enough to answer your question???
Anyway, the author hasn't been here in a long time, so maybe I can give an answer:
The script runs when a song starts playing, does it's work, and ends. The whole process shouldn't take more than a second. (i.e. creating/overwriting the text file and storing the song info in it).
That means that you can edit/delete/rename/... the text file always. *Except* at the moment when a song starts playing (and so the script runs). Then you'll have to wait a second for the script to finish.
Does the script work correctly? I mean, does it always contain one (or two) line(s) of text from the last played song?
If it doesn't, then change
Code: Select all
Set oOutput = oFSO.CreateTextFile("CookieData.txt")
to
Code: Select all
Set oOutput = oFSO.CreateTextFile("CookieData.txt", True)
The "True" makes sure that the file gets overwritten by a new version and so always contains the last played song.
Cheers
Steegy
Posted: Sun Apr 16, 2006 6:12 am
by kalex
Hehe. Don't worry - I just didn't want to bother you too much.
The problem is not that that the script will be locked, or something. I have to explain the details a little more, I think.
I've added some simply "code" into the templates of my email program. It checks for the existence of the "now playing" file. If its there, it is added below my signature to the message. If its NOT there, a random tagline ("cookie") is added, instead.
As it is now the file stays there for all eternity. Even if I wouldn't play a song with MM the whole month (which is hardly going to happen, but anyway), my email program would still show that I'm listening to... Ozzy Osbourne, or whatever, in an infinite loop.
So, what I'm looking for would be an additional functionality that deletes the created textfile (or empties its contents, either way) as soon as I press stop, or before I exit MM.
You see, thats why I didn't want to bother you too much with it!
A happy easter & thanks for the help you already provided.
Posted: Sun Apr 16, 2006 7:57 am
by Steegy
Happy easter too.
This is an improved version.
It has to be placed in MediaMonkey's Scripts\Auto folder, and you will have to remove the entry you previously made in the Scripts.ini file (you can remove the other script file in the Scripts folder too).
It will create a file NowPlayingSignature.txt in MediaMonkey's Scripts\Auto folder.
When playback stops, or you shut down MediaMonkey, the file will be deleted.
Code: Select all
Option Explicit
Dim oFSO
Set oFSO = CreateObject("Scripting.FileSystemObject")
Dim sSignatureFileName
sSignatureFileName = SDB.ApplicationPath & "Scripts\Auto\NowPlayingSignature.txt"
Sub OnStartUp
Script.RegisterEvent SDB, "OnPlay", "WriteSignatureFile"
Script.RegisterEvent SDB, "OnStop", "DeleteSignatureFile"
Script.RegisterEvent SDB, "OnShutDown", "DeleteSignatureFile"
End Sub
Sub WriteSignatureFile
On Error Resume Next
Dim oSignatureFile, oTrack, sAlbumArtist
Set oSignatureFile = oFSO.CreateTextFile(sSignatureFileName, True)
Set oTrack = SDB.Player.CurrentSong
oSignatureFile.Write "NP: " & oTrack.ArtistName & " - " & oTrack.Title
If (Instr(oTrack.AlbumName, "Best")=0 And Instr(oTrack.AlbumName, "Greatest")=0) _
Or Instr(oTrack.AlbumArtistName, "Various")=0 Then
oSignatureFile.Write " (from the album " & oTrack.AlbumName & ")"
End If
oSignatureFile.Close()
End Sub
Sub DeleteSignatureFile
On Error Resume Next
oFSO.DeleteFile(sSignatureFileName)
End Sub
Cheers
Steegy
Posted: Sun Apr 16, 2006 9:12 am
by kalex
Yeeehaa! Send me a PM with your address. This deserves some beer sent to you - awesome, man.
One minor glitch: I'm working with a limited user account - no administrative rights, no write access to the SDB.ApplicationPath directory. I changed it to my user profile path & everything is just fine.
Thanks a million, Steegy!
Error #438?
Posted: Sun May 14, 2006 12:25 pm
by pepoluan
I got an error #438 - Microsoft VBScript runtime error
Object doesn't support this property or method: 'Script.RegisterEvent'
Posted: Sun May 14, 2006 2:58 pm
by Steegy
You'll need a newer version of MediaMonkey, to be able to run this script (and many other scripts on this site). I think you need at least version 2.5.2
Cheers
Steegy
Posted: Sun May 14, 2006 11:19 pm
by pepoluan
I *am* using the latest version
Or must I use the Gold (i.e. paid) version?
Edit: Whoa. On second check, I'm still using 2.5.1. I could've sworn I've installed 2.5.2
Will try reinstalling 2.5.2
Edit2: Yup. That's the problem. Thanks for the wonderful script! Now I can wow my penpals *does a little dance of joy*
Error when changing properties
Posted: Fri May 19, 2006 6:25 am
by pepoluan
I experience error with this script installed:
When music is playing, I right-click and edit the property, click OK, an error pops up:
Error executing script event.
Click OK, and another error pops up:
Error executing script event.
But in the background, the music plays, but starts from the beginning.
Click OK, and the music resumes playing where it was before I edit the property.
Not fatal, but rather annoying.
FYI I am using MM 2.5.3.959 (beta)