HTML export script examples

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

Moderators: Peke, Gurus

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

HTML export script examples

Post by Lowlander »

In the following posts you'll find some scripts for HTML output of your tracks. The original MM HTML output script has been modified to create these new scripts. Please read the following sections first before using these scripts.

Notes about these scripts:

* Updating the export.vbs might result in losing the updates when new version of MM is installed.
* These scripts have not been extensively tested, so create backup of current HTML output script.
* These scripts have not been tested in other browsers than IE6 so in other browsers the results might be undesired.
* These scripts should not, but could possibly update the MM DB, as such it is always a good idea to backup the DB when trying a third-party script.
* You'll need to modify the scripts do to a mistake in the way forums display code. You'll need to replace this & n b s p ; part by the same thing without the spaces in between. This code is the HTML code for an empty space (Simply writing an empty space won't do).

* Feel free to use and modify these scripts as that's where they are meant for. They are meant to give you an idea of what is possible as well as some design modifications over the current scripts.

Tip:
* Create a new script file (*.vbs) to include these scripts. This will prevent them from being erased by new installations of MM, allow you to keep the current HTML output script and include as many output scripts as you want. You'll need to add this part first to any new file:
Option Explicit ' report undefined variables, ...

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

Dim list ' list of songs 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 songs to be exported
Set list = SDB.SelectedSongList
If list.count=0 Then
Set list = SDB.AllVisibleSongList
End If

If list.count=0 Then
res = SDB.MessageBox( "Select songs 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 successfully finished.", mtInformation, Array(mbOk))
else
res = SDB.MessageBox( "Export was terminated.", mtInformation, Array(mbOk))
end if
End Sub
You'll need to modify the following part of the scripts:
Sub ExportHTML to a unique name like Sub ExportHTML1 or any other unique name.

You'll need to modify the scripts.ini file as well. You'll need to add one of these:
[ExportHTML] change to reflect name, like [ExportHTML1]
FileName=Export.vbs change to filename of new *.vbs file
ProcName=ExportHTML change to reflect name, like [ExportHTML1]
Order=3 change to unique order number
DisplayName=Export to HTML change to name you want displayed
Description=Exports selected songs to a .htm file change if you like
Language=VBScript
ScriptType=1


Changes from current version:
* Added code to write space when cell contains no information (solves problem with table borders)
* Changed information displayed (Added Track Number and deleted Media)
* Added CSS for better formatting
* Changed table format (deleted right and left border and added column shading)
* Modified fonts
* Modified color layout

Quick Jump:
http://www.songs-db.com/forum/viewtopic.php?p=2391#2391 - Black & White Theme
http://www.songs-db.com/forum/viewtopic.php?p=2392#2392 - MediaMonkey.com Theme
http://www.songs-db.com/forum/viewtopic.php?p=2393#2393 - Pinternet.net Theme
http://www.songs-db.com/forum/viewtopic.php?p=2394#2394 - Single Artist Display
http://www.songs-db.com/forum/viewtopic.php?p=2395#2395 - Single Artist Sorted By Album Display

Lowlander
Last edited by Lowlander on Thu Oct 09, 2003 1:07 pm, edited 2 times in total.
Lowlander
Posts: 56574
Joined: Sat Sep 06, 2003 5:53 pm
Location: MediaMonkey 5

Black & White Theme

Post by Lowlander »

Please read notes at beginning of this post!
Go there: http://www.songs-db.com/forum/viewtopic.php?p=2390#2390

Theme: Black & White
' Black and white
Sub ExportHTML
' 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 Exported Songs</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 "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 "#dark{background-color:#EEEEEE}"
fout.WriteLine "</STYLE>"

fout.WriteLine "</head><body>"
fout.WriteLine "<H1>MediaMonkey Exported Songs</H1>"

' Headers of table
fout.WriteLine "<TABLE width=100% CELLPADDING=4 CELLSPACING=0>"
fout.WriteLine "<tr>"
fout.WriteLine " <th>Artist</th>"
fout.WriteLine " <th ID=dark>Song</th>"
fout.WriteLine " <th>Length</th>"
fout.WriteLine " <th ID=dark>Album</th>"
fout.WriteLine " <th>Track #</th>"
fout.WriteLine " <th ID=dark>Year</th>"
fout.WriteLine " <th>Genre</th>"
fout.WriteLine " <th ID=dark>Bitrate</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)
Dim bitrate
bitrate = itm.bitrate
if bitrate>0 then
bitrate = CStr(Round( bitrate/1000))
else
bitrate = "& n b s p ;"
end if

Dim year
year = itm.year
if year<=0 then
year = "& n b s p ;"
else
year = CStr( year)
end if

' 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 = "& n b s p ;"
end if

Dim songtitle
songtitle = itm.title
if songtitle="" then
songtitle = "& n b s p ;"
end if

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

Dim songlength
songlength = itm.SongLengthString
if songlength="" then
songlength = "& n b s p ;"
end if

Dim songgenre
songgenre = itm.Genre
if songgenre="" then
songgenre = "& n b s p ;"
end if

Dim trackorder
trackorder = itm.TrackOrder
if trackorder="" then
trackorder = "& n b s p ;"
elseif trackorder = "0" then
trackorder = "& n b s p ;"
end if

' Body of the table
fout.WriteLine "<tr><td>"&artistname&"</td><td ID=dark>"&songtitle _
&"</td><td align=right>"&songlength&"</td><td ID=dark>"&albumname _
&"</td><td align=right>"&trackorder&"</td><td align=right ID=dark>"&Year _
&"</td><td>"&songgenre&"</td><td align=right ID=dark>"&bitrate&"</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>"
fout.WriteLine "</body>"
fout.WriteLine "</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
Lowlander

PS. Using this script is on your own risk!
Last edited by Lowlander on Thu Oct 09, 2003 12:56 pm, edited 3 times in total.
Lowlander
Posts: 56574
Joined: Sat Sep 06, 2003 5:53 pm
Location: MediaMonkey 5

MediaMonkey.com Theme

Post by Lowlander »

Please read notes at beginning of this post!
Go there: http://www.songs-db.com/forum/viewtopic.php?p=2390#2390

Theme: MediaMonkey.com
' MediaMonkey.com Theme
Sub ExportHTML
' 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 Exported Songs</title>"

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

fout.WriteLine "</head><body>"
fout.WriteLine "<H1>MediaMonkey Exported Songs</H1>"

' Headers of table
fout.WriteLine "<TABLE width=100% CELLPADDING=4 CELLSPACING=0>"
fout.WriteLine "<tr>"
fout.WriteLine " <th>Artist</th>"
fout.WriteLine " <th>Song</th>"
fout.WriteLine " <th>Length</th>"
fout.WriteLine " <th>Album</th>"
fout.WriteLine " <th>Track #</th>"
fout.WriteLine " <th>Year</th>"
fout.WriteLine " <th>Genre</th>"
fout.WriteLine " <th>Bitrate</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)
Dim bitrate
bitrate = itm.bitrate
if bitrate>0 then
bitrate = CStr(Round( bitrate/1000))
else
bitrate = "& n b s p ;"
end if

Dim year
year = itm.year
if year<=0 then
year = "& n b s p ;"
else
year = CStr( year)
end if

' 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 = "& n b s p ;"
end if

Dim songtitle
songtitle = itm.title
if songtitle="" then
songtitle = "& n b s p ;"
end if

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

Dim songlength
songlength = itm.SongLengthString
if songlength="" then
songlength = "& n b s p ;"
end if

Dim songgenre
songgenre = itm.Genre
if songgenre="" then
songgenre = "& n b s p ;"
end if

Dim trackorder
trackorder = itm.TrackOrder
if trackorder="" then
trackorder = "& n b s p ;"
elseif trackorder = "0" then
trackorder = "& n b s p ;"
end if

' Body of the table
fout.WriteLine "<tr><td>"&artistname&"</td><td ID=dark>"&songtitle _
&"</td><td align=right>"&songlength&"</td><td ID=dark>"&albumname _
&"</td><td align=right>"&trackorder&"</td><td align=right ID=dark>"&Year _
&"</td><td>"&songgenre&"</td><td align=right ID=dark>"&bitrate&"</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>"
fout.WriteLine "</body>"
fout.WriteLine "</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
PS. Using this script is on your own risk!
Last edited by Lowlander on Thu Oct 09, 2003 12:58 pm, edited 2 times in total.
Lowlander
Posts: 56574
Joined: Sat Sep 06, 2003 5:53 pm
Location: MediaMonkey 5

Pinternet.net Theme

Post by Lowlander »

Please read notes at beginning of this post!
Go there: http://www.songs-db.com/forum/viewtopic.php?p=2390#2390

Theme: Pinternet.net
' Pinternet Theme
Sub ExportHTML
' 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 Exported Songs</title>"

' Code to format the document
fout.WriteLine "<STYLE TYPE=text/css>"
fout.WriteLine "body{font-family:'Verdana',sans-serif; background-color:#FFFFEE; font-size:9pt; color:#660000;}"
fout.WriteLine "H1{font-family:'Verdana',sans-serif; font-size:13pt; font-weight:bold; color:#055005; text-aligh:left}"
fout.WriteLine "TH{font-family:'Verdana',sans-serif; font-size:10pt; font-weight:bold; color:#055005; border-color:#055005; 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:#660000; border-color:#055005; border-style: solid; border-left-width:0px; border-right-width:0px; border-top-width:0px; border-bottom-width:1px;}"
fout.Writeline "#dark{background-color:#FFFFCC}"
fout.WriteLine "</STYLE>"

fout.WriteLine "</head><body>"
fout.WriteLine "<H1>MediaMonkey Exported Songs</H1>"

' Headers of table
fout.WriteLine "<TABLE width=100% CELLPADDING=4 CELLSPACING=0>"
fout.WriteLine "<tr>"
fout.WriteLine " <th>Artist</th>"
fout.WriteLine " <th ID=dark>Song</th>"
fout.WriteLine " <th>Length</th>"
fout.WriteLine " <th ID=dark>Album</th>"
fout.WriteLine " <th>Track #</th>"
fout.WriteLine " <th ID=dark>Year</th>"
fout.WriteLine " <th>Genre</th>"
fout.WriteLine " <th ID=dark>Bitrate</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)
Dim bitrate
bitrate = itm.bitrate
if bitrate>0 then
bitrate = CStr(Round( bitrate/1000))
else
bitrate = "& n b s p ;"
end if

Dim year
year = itm.year
if year<=0 then
year = "& n b s p ;"
else
year = CStr( year)
end if

' 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 = "& n b s p ;"
end if

Dim songtitle
songtitle = itm.title
if songtitle="" then
songtitle = "& n b s p ;"
end if

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

Dim songlength
songlength = itm.SongLengthString
if songlength="" then
songlength = "& n b s p ;"
end if

Dim songgenre
songgenre = itm.Genre
if songgenre="" then
songgenre = "& n b s p ;"
end if

Dim trackorder
trackorder = itm.TrackOrder
if trackorder="" then
trackorder = "& n b s p ;"
elseif trackorder = "0" then
trackorder = "& n b s p ;"
end if

' Body of the table
fout.WriteLine "<tr><td>"&artistname&"</td><td ID=dark>"&songtitle _
&"</td><td align=right>"&songlength&"</td><td ID=dark>"&albumname _
&"</td><td align=right>"&trackorder&"</td><td align=right ID=dark>"&Year _
&"</td><td>"&songgenre&"</td><td align=right ID=dark>"&bitrate&"</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>"
fout.WriteLine "</body>"
fout.WriteLine "</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
PS. Using this script is on your own risk!
Last edited by Lowlander on Thu Oct 09, 2003 1:00 pm, edited 2 times in total.
Lowlander
Posts: 56574
Joined: Sat Sep 06, 2003 5:53 pm
Location: MediaMonkey 5

Single artist display

Post by Lowlander »

Please read notes at beginning of this post!
Go there: http://www.songs-db.com/forum/viewtopic.php?p=2390#2390

Theme: Black & White

This script is an example of how to display information which all has one unique field (in this case artist). This script includes a check to see if tracks from only one artist are selected. The script will show error and stop executing when more than one artist is selected.
The output has been modified to display the artist only once, check for yourself.
'Display songs from just one artist
Sub ExportHTML
' initialize export
Call InitExport( ".htm", "HTML (*.htm)|*.htm|All files (*.*)|*.*", _
"LastExportHTMLDir")
if fullfile="" then
Exit Sub
end if

' Check if actually one artist is selected, exit on multiple's
Dim i, itm
Set itm = list.Item(0)
Dim oneartist
oneartist = itm.ArtistName
for i=0 to list.count-1
Set itm = list.Item(i)
If itm.ArtistName <> oneartist Then
res = SDB.MessageBox( "Multiple artists selected! Please select songs from only one artist.", mtError, Array(mbOk))
Exit Sub
End If
Next

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

' Write header line
fout.WriteLine "<html>"
fout.WriteLine "<head><title>MediaMonkey Exported Songs for "&oneartist&"</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:20pt; font-weight:bold; color:#AAAAAA; text-aligh:left}"
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 "#dark{background-color:#EEEEEE}"
fout.WriteLine "</STYLE>"

fout.WriteLine "</head><body>"

' 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

fout.WriteLine "<H1>"&oneartist&"</H1>"

' Headers of table
fout.WriteLine "<TABLE width=100% CELLPADDING=4 CELLSPACING=0>"
fout.WriteLine "<tr>"
fout.WriteLine " <th>Song</th>"
fout.WriteLine " <th ID=dark>Length</th>"
fout.WriteLine " <th>Album</th>"
fout.WriteLine " <th ID=dark>Track #</th>"
fout.WriteLine " <th>Year</th>"
fout.WriteLine " <th ID=dark>Genre</th>"
fout.WriteLine " <th>Bitrate</th>"
fout.WriteLine "</tr>"

for i=0 to list.count-1
Set itm = list.Item(i)
Dim bitrate
bitrate = itm.bitrate
if bitrate>0 then
bitrate = CStr(Round( bitrate/1000))
else
bitrate = "& n b s p ;"
end if

Dim year
year = itm.year
if year<=0 then
year = "& n b s p ;"
else
year = CStr( year)
end if

' 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 = "& n b s p ;"
end if

Dim songtitle
songtitle = itm.title
if songtitle="" then
songtitle = "& n b s p ;"
end if

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

Dim songlength
songlength = itm.SongLengthString
if songlength="" then
songlength = "& n b s p ;"
end if

Dim songgenre
songgenre = itm.Genre
if songgenre="" then
songgenre = "& n b s p ;"
end if

Dim trackorder
trackorder = itm.TrackOrder
if trackorder="" then
trackorder = "& n b s p ;"
elseif trackorder = "0" then
trackorder = "& n b s p ;"
end if

' Body of the table
fout.WriteLine "<tr><td>"&songtitle&"<td align=right ID=dark>"&songlength _
&"</td><td>"&albumname&"</td><td align=right ID=dark>"&trackorder _
&"</td><td align=right>"&Year&"</td><td ID=dark>"&songgenre _
&"</td><td align=right>"&bitrate&"</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>"
fout.WriteLine "</body>"
fout.WriteLine "</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
PS. Using this script is on your own risk!
Last edited by Lowlander on Thu Oct 09, 2003 1:01 pm, edited 2 times in total.
Lowlander
Posts: 56574
Joined: Sat Sep 06, 2003 5:53 pm
Location: MediaMonkey 5

Single artist sorted by album display

Post by Lowlander »

Please read notes at beginning of this post!
Go there: http://www.songs-db.com/forum/viewtopic.php?p=2390#2390

Theme: Black & White

This script (a modified version of the single artist script http://www.songs-db.com/forum/viewtopic.php?p=2394#2394) is an example of how to display information which all has one unique field (in this case artist) and than display it sorted by album. This script includes a check to see if tracks from only one artist are selected. The script will show error and stop executing when more than one artist is selected. This script has no sorting capability of itself so you'll need to sort the selected tracks from one artist by album to get the intended output.
The output has been modified to show to levels, first the artist and as sublevel album.
'Display songs from just one artist by album
Sub ExportHTML

' This script contains no sorting and us such user needs to sort songs on album in MM itself, this message informs about that
res = SDB.MessageBox( "This script requires you to sort the export list on album yourself. Hope you did!", mtInformation, Array(mbOk))

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

' Check if actually one artist is selected, exit on multiple's
Dim i, itm
' Delete the next part till NEXT and you'll have a list of albums with songs. Multiple artist would be possible again. You might want to add the artist info back into the table.
Set itm = list.Item(0)
Dim oneartist
oneartist = itm.ArtistName
for i=0 to list.count-1
Set itm = list.Item(i)
If itm.ArtistName <> oneartist Then
res = SDB.MessageBox( "Multiple artists selected! Please select songs from only one artist.", mtError, Array(mbOk))
Exit Sub
End If
Next

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

' Write header line
fout.WriteLine "<html>"
fout.WriteLine "<head><title>MediaMonkey Exported Songs for "&oneartist&"</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:20pt; font-weight:bold; color:#AAAAAA; text-aligh:left}"
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 "#album{font-family:'Verdana',sans-serif; font-size:12pt; font-weight:bold; color:#AAAAAA; text-aligh:left; border-bottom-width:3px;}"
fout.Writeline "#dark{background-color:#EEEEEE}"
fout.WriteLine "</STYLE>"

fout.WriteLine "</head><body>"

' 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

fout.WriteLine "<H1>"&oneartist&"</H1>"

' Headers of table
fout.WriteLine "<TABLE width=100% CELLPADDING=4 CELLSPACING=0>"
fout.WriteLine "<tr>"
fout.WriteLine " <th ID=dark>Track #</th>"
fout.WriteLine " <th>Song</th>"
fout.WriteLine " <th ID=dark>Length</th>"
fout.WriteLine " <th>Year</th>"
fout.WriteLine " <th ID=dark>Genre</th>"
fout.WriteLine " <th>Bitrate</th>"
fout.WriteLine "</tr>"

Dim currentalbum
currentalbum = ""
for i=0 to list.count-1
Set itm = list.Item(i)
If itm.AlbumName <> currentalbum Then
fout.WriteLine "<TR><TD COLSPAN=6 ID=album><BR><BR>"&itm.AlbumName&"</TD></TR>"
currentalbum=itm.AlbumName
End If
Dim bitrate
bitrate = itm.bitrate
if bitrate>0 then
bitrate = CStr(Round( bitrate/1000))
else
bitrate = "& n b s p ;"
end if

Dim year
year = itm.year
if year<=0 then
year = "& n b s p ;"
else
year = CStr( year)
end if

' 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 = "& n b s p ;"
end if

Dim songtitle
songtitle = itm.title
if songtitle="" then
songtitle = "& n b s p ;"
end if

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

Dim songlength
songlength = itm.SongLengthString
if songlength="" then
songlength = "& n b s p ;"
end if

Dim songgenre
songgenre = itm.Genre
if songgenre="" then
songgenre = "& n b s p ;"
end if

Dim trackorder
trackorder = itm.TrackOrder
if trackorder="" then
trackorder = "& n b s p ;"
elseif trackorder = "0" then
trackorder = "& n b s p ;"
end if

' Body of the table
fout.WriteLine "<tr><td ID=dark>"&trackorder&"</td><td>"&songtitle _
&"</td><td align=right ID=dark>"&songlength _
&"</td><td align=right>"&Year&"</td><td ID=dark>"&songgenre _
&"</td><td align=right>"&bitrate&"</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>"
fout.WriteLine "</body>"
fout.WriteLine "</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
PS. Using this script is on your own risk!
Last edited by Lowlander on Thu Oct 09, 2003 1:04 pm, edited 2 times in total.
Lowlander
Posts: 56574
Joined: Sat Sep 06, 2003 5:53 pm
Location: MediaMonkey 5

Other HTML export script

Post by Lowlander »

This script was posted by FurAnt, not by me in the forums. Just added it here so all scripts are nicely in the same thread.

FurAnt profile: http://www.songs-db.com/forum/profile.p ... file&u=228
Original Post: http://www.songs-db.com/forum/viewtopic.php?t=466
Sub ExportHTML
' 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 HTML header
fout.WriteLine "<html>"
fout.WriteLine "<head><title>MP3 Song Listing</title></head>"
fout.WriteLine "<body>"
fout.WriteLine "<style type='text/css' media='screen'>"
fout.WriteLine "TD {font-family: verdana, arial, sans-serif; font-size: 12px; color: #000000; margin-left: 10%; margin-right: 5%;}"
fout.WriteLine "TH {background : #0000CC; font-family: verdana, arial, sans-serif; font-size: 14px; color: #FFFFFF; margin-left: 10%; margin-right: 5%;}"
fout.WriteLine "body { background: #FFFFFF; font-family : verdana, arial, sans-serif; color: #FFFFFF }"
fout.WriteLine ".tmaintable { background : #CCCCCC }"
fout.WriteLine ".teven { background : #CCCCCC;}"
fout.WriteLine ".tnoteven { background : #FFFFFF;}"
fout.WriteLine "</style>"

' Write Table Title
fout.WriteLine "<table border=0 width=80%>"
fout.WriteLine "<tr>"
fout.WriteLine " <th>Artist</th>"
fout.WriteLine " <th>Song</th>"
fout.WriteLine " <th>Album</th>"
fout.WriteLine " <th>Length</th>"
fout.WriteLine " <th>Year</th>"
fout.WriteLine " <th>Genre</th>"
fout.WriteLine " <th>Bitrate</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-2
Set itm = list.Item(i)
Dim bitrate
bitrate = itm.bitrate
if bitrate>0 then
bitrate = CStr(Round( bitrate/1000))
else
bitrate = ""
end if
Dim year
year = itm.year
if year<=0 then
year = " "
else
year = CStr( year)
end if
if fix(i/2)=i /2 then
fout.WriteLine "<tr class=teven><td>"&itm.ArtistName&"</td><td>"&itm.title&"</td><td>"&itm.AlbumName _
&"</td><td align=right>"&itm.SongLengthString&"</td><td align=right>"&Year&"</td><td>"&itm.Genre _
&"</td><td align=right>"&bitrate&"</td></tr>"
else
fout.WriteLine "<tr class=tnoteven><td>"&itm.ArtistName&"</td><td>"&itm.title&"</td><td>"&itm.AlbumName _
&"</td><td align=right>"&itm.SongLengthString&"</td><td align=right>"&Year&"</td><td>"&itm.Genre _
&"</td><td align=right>"&bitrate&"</td></tr>"
end if
Progress.Value = i+1
if Progress.Terminate then
Exit For
end if
next

' Write some code to finish html document
fout.WriteLine "</table>"
fout.WriteLine "</body>"
fout.WriteLine "</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
jiri
Posts: 5419
Joined: Tue Aug 14, 2001 7:00 pm
Location: Czech Republic
Contact:

Post by jiri »

Thanks for all the scripts!

There is just a small problem - probably because of conversion to the HTML page of the forum, all empty strings don't appear correctly, there is an ampersand shown in each empty field. However, that can be easily fixed and we will do so when adding the scripts to the MM scripts page.

Thanks,
Jiri
Lowlander
Posts: 56574
Joined: Sat Sep 06, 2003 5:53 pm
Location: MediaMonkey 5

Actually it needs to be the empty space code for HTML

Post by Lowlander »

This sucks and I should have thought of that, but the &'s need to be replaced by: & n b s p ; (Added spaces so code would show up).

Dim songtitle
songtitle = itm.title
if songtitle="" then
songtitle = "& n b s p ;"
end if

Adding an empty space won't work you'll need to use the HTML code for an empty space for the code to work!!!

The problem is that HTML code is of in the forums otherwise putting the code in a textareabox would solve the problem too.

I updated all the forum articles to reflect this problem and added a statement in the first post about this problem.

I hope you all like the scripts.

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

Post by Lowlander »

Please read notes at beginning of this post!
Go there: http://www.songs-db.com/forum/viewtopic.php?p=2390#2390

Theme: Black & White

This script has all the possible things you can display in a HTML export file included, as well as entry numbering and a total track count. This file misses some formatting, which results in not all table borders are displayed correctly. But the purpose of this script is to help everyone with creating theirs and as such I didn't bother to add all the formatting code that was needed.
I hope that this script helps many on their way, good luck!
Sub ExportHTML
' 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 Exported Songs</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 "#dark{background-color:#EEEEEE}"
fout.WriteLine "</STYLE>"

fout.WriteLine "</head><body>"
fout.WriteLine "<H1>MediaMonkey Exported Songs</H1>"

' Headers of table
fout.WriteLine "<TABLE CELLPADDING=4 CELLSPACING=0>"
fout.WriteLine "<tr>"
fout.WriteLine " <th>i+1</th>"
fout.WriteLine " <th>itm.ArtistName</th>"
fout.WriteLine " <th ID=dark>itm.title</th>"
fout.WriteLine " <th>itm.SongLengthString</th>"
fout.WriteLine " <th ID=dark>itm.AlbumName</th>"
fout.WriteLine " <th>itm.TrackOrder</th>"
fout.WriteLine " <th ID=dark>itm.year</th>"
fout.WriteLine " <th>itm.Genre</th>"
fout.WriteLine " <th ID=dark>itm.bitrate</th>"
fout.WriteLine " <th>itm.Path</th>"
fout.WriteLine " <th ID=dark>itm.FileLength</th>"
fout.WriteLine " <th>itm.Cached</th>"
fout.WriteLine " <th ID=dark>itm.SampleRate</th>"
fout.WriteLine " <th>itm.Channels</th>"
fout.WriteLine " <th ID=dark>itm.SongID</th>"
fout.WriteLine " <th>itm.UpdateDB</th>"
fout.WriteLine " <th ID=dark>itm.MediaLabel</th>"
fout.WriteLine " <th>itm.BPM</th>"
fout.WriteLine " <th ID=dark>itm.VBR</th>"
fout.WriteLine " <th>itm.Author</th>"
fout.WriteLine " <th ID=dark>itm.PlayCounter</th>"
fout.WriteLine " <th>itm.Rating</th>"
fout.WriteLine " <th ID=dark>itm.FileModified</th>"
fout.WriteLine " <th>itm.Lyricist</th>"
fout.WriteLine " <th ID=dark>itm.MusicComposer</th>"
fout.WriteLine " <th>itm.Band</th>"
fout.WriteLine " <th ID=dark>itm.Conductor</th>"
fout.WriteLine " <th>itm.InvolvedPeople</th>"
fout.WriteLine " <th ID=dark>itm.OriginalArtist</th>"
fout.WriteLine " <th>itm.OriginalLyricist</th>"
fout.WriteLine " <th ID=dark>itm.OriginalTitle</th>"
fout.WriteLine " <th>itm.Year</th>"
fout.WriteLine " <th ID=dark>itm.ISRC</th>"
fout.WriteLine " <th>itm.Lyrics</th>"
fout.WriteLine " <th ID=dark>itm.Comment</th>"
fout.WriteLine " <th>itm.Custom1</th>"
fout.WriteLine " <th ID=dark>itm.Custom2</th>"
fout.WriteLine " <th>itm.Custom3</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)
Dim bitrate
bitrate = itm.bitrate
if bitrate>0 then
bitrate = CStr(Round( bitrate/1000))
else
bitrate = "& n b s p ;"
end if
Dim year
year = itm.year
if year<=0 then
year = "& n b s p ;"
else
year = CStr( year)
end if

' 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 = "& n b s p ;"
end if

Dim songtitle
songtitle = itm.title
if songtitle="" then
songtitle = "& n b s p ;"
end if

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

Dim songlength
songlength = itm.SongLengthString
if songlength="" then
songlength = "& n b s p ;"
end if

Dim songgenre
songgenre = itm.Genre
if songgenre="" then
songgenre = "& n b s p ;"
end if

Dim trackorder
trackorder = itm.TrackOrder
if trackorder="" then
trackorder = "& n b s p ;"
elseif trackorder = "0" then
trackorder = "& n b s p ;"
end if

' These are added to get some decent display, all the others haven't, this script is just to demonstrate all the available options

Dim BPM
BPM = itm.BPM
if BPM ="" then
BPM = "& n b s p ;"
elseif BPM = "-1" then
BPM = "& n b s p ;"
end if

Dim Rating
Rating = itm.Rating
if Rating ="" then
Rating = "& n b s p ;"
elseif Rating = "-1" then
Rating = "& n b s p ;"
end if

Dim originalyear
Rating = itm.OriginalYear
if originalyear ="" then
originalyear = "& n b s p ;"
elseif originalyear = "-1" then
originalyear = "& n b s p ;"
end if

' Body of the table
fout.WriteLine "<tr><td ID=dark>"&i+1&"</TD><TD>"&artistname&"</td><td ID=dark>"&songtitle _
&"</td><td align=right>"&songlength&"</td><td ID=dark>"&albumname _
&"</td><td align=right>"&trackorder&"</td><td align=right ID=dark>"&Year _
&"</td><td>"&songgenre&"</td><td align=right ID=dark>"&bitrate _
&"</td><td>"&itm.Path&"</td><td align=right ID=dark>"&itm.FileLength _
&"</td><td>"&itm.Cached&"</td><td align=right ID=dark>"&itm.SampleRate _
&"</td><td>"&itm.Channels&"</td><td align=right ID=dark>"&itm.SongID _
&"</td><td>"&itm.UpdateDB&"</td><td align=right ID=dark>"&itm.MediaLabel _
&"</td><td>"&BPM&"</td><td align=right ID=dark>"&itm.VBR _
&"</td><td>"&itm.Author&"</td><td align=right ID=dark>"&itm.PlayCounter _
&"</td><td>"&rating&"</td><td align=right ID=dark>"&itm.FileModified _
&"</td><td>"&itm.Lyricist&"</td><td align=right ID=dark>"&itm.MusicComposer _
&"</td><td>"&itm.Band&"</td><td align=right ID=dark>"&itm.Conductor _
&"</td><td>"&itm.InvolvedPeople&"</td><td align=right ID=dark>"&itm.OriginalArtist _
&"</td><td>"&itm.OriginalLyricist&"</td><td align=right ID=dark>"&itm.OriginalTitle _
&"</td><td>"&originalyear&"</td><td align=right ID=dark>"&itm.ISRC _
&"</td><td>"&itm.Lyrics&"</td><td align=right ID=dark>"&itm.Comment _
&"</td><td>"&itm.Custom1&"</td><td align=right ID=dark>"&itm.Custom2 _
&"</td><td>"&itm.Custom3&"</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>"
fout.WriteLine "<P><B>Total Songs: </B>"&i&"</P>"
fout.WriteLine "</body>"
fout.WriteLine "</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
PS. Using this script is on your own risk!
Post Reply