Export Artist-Album List to HTML

Download and get help for different MediaMonkey for Windows 4 Addons.

Moderators: Peke, Gurus

Frodo56us

Export Artist-Album List to HTML

Post by Frodo56us »

Anyone know the object name I would use in this type of script to pull the Artist or Album? I tried this:

' Get a list of albums to be exported
Set list = SDB.Artists
If list.count=0 Then
Set list = SDB.Artists
End If


But it didn't work. Said it didn't like that object name. I don't want a list of all the tracks, just a list of the Artists and Albums. Any ideas on how to do this?

Thanks!
Frodo56us

Export Artist-Album list to HTML

Post by Frodo56us »

It doesn't like SDB.SelectedArtists or SelectedAlbums either.

If I use the SelectedSongList like the track export, I get a bunch of redundant entries. Since I am really wanting a list of Albums, I guess I need the object name for the selected albums.

I am new to VBScript, so please bear with me.

Frodo
jiri
Posts: 5417
Joined: Tue Aug 14, 2001 7:00 pm
Location: Czech Republic
Contact:

Post by jiri »

You can use SDB.SelectedSongList.Artists to get a list of all artists in the selected list. An example of this is in the XML export script.

Jiri
Frodo56us

Export Artist-Album to HTML

Post by Frodo56us »

Sweet! Do you know if SDB.SelectedSongList.Albums will work as well?

Frodo
jiri
Posts: 5417
Joined: Tue Aug 14, 2001 7:00 pm
Location: Czech Republic
Contact:

Post by jiri »

Yes, should work fine.

Jiri
Frodo56us

Export Artist-Album List to HTML

Post by Frodo56us »

Argh, that part works, but now I'm getting other errors from the script. It doesn't like where I've tried to dim the Year and Album stuff. I'll look at the xml portion of the original script and see what it's doing.

Frodo
Frodo56us

Export Artist-Album List to HTML

Post by Frodo56us »

Argh, that part works, but now I'm getting other errors from the script. It doesn't like where I've tried to dim the Year and Album stuff. I'll look at the xml portion of the original script and see what it's doing.

Frodo
Lowlander
Posts: 56491
Joined: Sat Sep 06, 2003 5:53 pm
Location: MediaMonkey 5

Check these out

Post by Lowlander »

Frodo56us

Export Artist-Album list to HTML

Post by Frodo56us »

I've looked at those, but I must be too dense to make a lot of sense out of them. I am totally new to writing scripts.

I've created two seperate vbscripts, one for exporting all my songs to HTML which works fine. However the one for the Artist/Albums doesn't work. Really these are just edited versions of the HTML section of the original. Here is the offending script:

Option Explicit ' report undefined variables, ...

' function for quoting strings
Function QStr( astr)
QStr = chr(34) & astr & chr(34)
End Function

Dim list ' list of albums to be exported
Dim res ' results of dialogs calls
Dim fullfile ' fully specified output file name
Dim fso ' FileSystemObject

' SDB variable is connected to MediaMonkey application object

Sub InitExport( ext, filter, iniDirValue)
fullfile = ""

' Get a list of albums to be exported
Set list = SDB.SelectedSongList.Albums
If list.count=0 Then
Set list = SDB.AllVisibleSongList.Albums
End If

If list.count=0 Then
res = SDB.MessageBox( "Select Albums to be exported, please.", mtError, Array(mbOk))
Exit Sub
End If

' Open inifile and get last used directory
Dim iniF
Set iniF = SDB.IniFile

' Create common dialog and ask where to save the file
Dim dlg
Set dlg = SDB.CommonDialog
dlg.DefaultExt=ext
dlg.Filter=filter
dlg.Flags=cdlOFNOverwritePrompt + cdlOFNHideReadOnly
dlg.InitDir = iniF.StringValue( "Scripts", iniDirValue)
dlg.ShowSave

if Not dlg.Ok Then
Exit Sub ' if cancel was pressed, exit
End If

' Get the selected filename
fullfile = dlg.FileName

' Connect to the FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")

' Write selected directory to the ini file
iniF.StringValue( "Scripts", iniDirValue) = fullfile
End Sub

Sub FinishExport( ok)
On Error Resume Next

' remove the output file if terminated
if not Ok then
fso.DeleteFile( fullfile)
end if

' Notify user that it was successful
if ok then
res = SDB.MessageBox( "Export was completed successfully.", mtInformation, Array(mbOk))
else
res = SDB.MessageBox( "Export was terminated.", mtInformation, Array(mbOk))
end if
End Sub

Sub HTMLAlbumList
' initialize export
Call InitExport( ".htm", "HTML (*.htm)|*.htm|All files (*.*)|*.*", _
"LastExportHTMLDir")
if fullfile="" then
Exit Sub
end if

' Create the output file
Dim fout
Set fout = fso.CreateTextFile( fullfile, True)

' Write header line
fout.WriteLine "<html>"
fout.WriteLine "<head><title>MediaMonkey Track List</title>"

' Code to format the document
fout.WriteLine "<STYLE TYPE=text/css>"
fout.WriteLine "body{font-family:'Verdana',sans-serif; background-color:#FFFFFF; font-size:9pt; color:#000000;}"
fout.WriteLine "H1{font-family:'Verdana',sans-serif; font-size:13pt; font-weight:bold; color:#AAAAAA; text-aligh:left}"
fout.WriteLine "P{font-family:'Verdana',sans-serif; font-size:9pt; color:#000000;}"
fout.WriteLine "TH{font-family:'Verdana',sans-serif; font-size:10pt; font-weight:bold; color:#000000; border-color:#000000; border-style: solid; border-left-width:0px; border-right-width:0px; border-top-width:0px; border-bottom-width:3px;}"
fout.WriteLine "TD{font-family:'Verdana',sans-serif; font-size:9pt; color:#000000; border-color:#000000; border-style: solid; border-left-width:0px; border-right-width:0px; border-top-width:0px; border-bottom-width:1px;}"
fout.Writeline "TD.dark{background-color:#EEEEEE}"
fout.WriteLine "</STYLE>"

fout.WriteLine "</head><body>"
fout.WriteLine "<a href='http://www.mediamonkey.com'><H1>MediaMonkey Track List</H1></a>"

' Headers of table
fout.WriteLine "<TABLE CELLPADDING=4 CELLSPACING=0>"
fout.WriteLine "<tr>"
fout.WriteLine " <th ID=dark>#</th>"
fout.WriteLine " <th>Artist</th>"
fout.WriteLine " <th ID=dark>Album</th>"
fout.WriteLine "</tr>"

' Use progress to notify user about the current action
Dim Progress
Set Progress = SDB.Progress
Progress.Text = "Exporting to a HTML file..."

' Iterate through the list and export all songs
Progress.MaxValue = list.count
Dim i, itm
for i=0 to list.count-1
Set itm = list.Item(i)

' Add space to empty fields, so table is displayed correctly (Cell borders do not show up for empty cells)
Dim artistname
artistname = itm.ArtistName
if artistname="" then
artistname = "&"
end if

Dim albumname
albumname = itm.AlbumName
if albumname="" then
albumname = "&"
end if

' Body of the table
fout.WriteLine "<tr><td align=right class=dark>"&i+1 _
&"</TD><TD>"&artistname _
&"</td><td class=dark>"&albumname _
&"</td></tr>"
Progress.Value = i+1
if Progress.Terminate then
Exit For
end if
next

' Write some code to finish html document
fout.WriteLine "</table><p/><table width=100%><tr>"
fout.WriteLine "<td style='border-bottom-width:0px'><B>Total Tracks: </B>"&i&"</td> <td align=Right style='border-bottom-width:0px'>Generated by <a href='http://www.mediamonkey.com'>MediaMonkey</a></td>"
fout.WriteLine "</tr></table></body></html>"

' Close the output file and finish
fout.Close

' Was it successfull?
Dim ok
if Progress.Terminate then
ok = False
else
ok = True
end if

' hide progress
Set Progress = Nothing

FinishExport( ok)
End Sub


Which gives me the following error:

Error #438 - Microsoft VBScript Runtime Error
Object doesn't support this property or method: 'itm.artistname'
File "C:\Program Files\MediaMonkey\Scripts\HTMLAlbumList.vbs",
Line: 122, Column: 4


Think anyone more knowledgable than me can take a look at my code and see what I am doing wrong?

Frodo
Lowlander
Posts: 56491
Joined: Sat Sep 06, 2003 5:53 pm
Location: MediaMonkey 5

Not sure

Post by Lowlander »

My first guess is that the connection with MM has an error. But I can't verify your code right now.

You might want to use this code which can be found on the page I previously mentioned. It might get close to your desired results.
http://www.songs-db.com/forum/viewtopic.php?p=2395#2395
AlanB

a suggestion

Post by AlanB »

I did it using Access, but a script solution would be better (but I am still learning here also).

Since you haven't received an answer from anyone more knowlegable, I offer my suggestion.
Refereing to the idl already mentioned at
http://www.songs-db.com/Songs-DB.idl

I suspect that you are trying to access the wrong member property. All the previous scripts have obtained a song list and hence rely on the interfaces ISDBSongList and hence .Item yields a ISDBSongData (i.e. .ArtistName, AlbumName etc). However, you have used the ISDBSongList .Albums member to obtain an album list, hence the .Item property will yield a ISDBAlbum instead, hence you need to consider its members.

I this is correct, then you would need to use .Artist instead of .ArtistName and .Name instead of .AlbumName.

I hope this is correct, in which case it might help.


AlanB
AlanB

correction

Post by AlanB »

OK, so I couldn't try it, so it didn't work. But it was close. This I have tried and it does work...

You would need to use .Artist.Name instead of .ArtistName
and .Name instead of .AlbumName.
Hence the appropriate part of your script becomes...

' Add space to empty fields, so table is displayed correctly (Cell borders do not show up for empty cells)
Dim artistname
artistname = itm.Artist.Name
if artistname="" then
artistname = "& n b s p"
end if

Dim albumname
albumname = itm.Name
if albumname="" then
albumname = "& n b s p"
end if

note... remove spaces from "& n b s p"

If I have copied that in correctly, the script should now run (mine does).

Good luck, AlanB
Post Reply