by onkel_enno » Mon Aug 29, 2005 1:06 am
That should work for every collection (I hope):
Code: Select all
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>" & SDB.Localize("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>" & SDB.Localize("MediaMonkey Track List")&"</h1></a>"
' Headers of table
fout.WriteLine "<table cellpadding=4 cellspacing=0>"
fout.WriteLine "<tr align=left>"
fout.WriteLine " <th id=dark>#</th>"
fout.WriteLine " <th>" & SDB.Localize("Artist") & "</th>"
fout.WriteLine " <th id=dark>" & SDB.Localize("Title") & "</th>"
fout.WriteLine " <th>" & SDB.Localize("Length") & "</th>"
fout.WriteLine " <th id=dark>" & SDB.Localize("Album") & "</th>"
fout.WriteLine " <th>" & SDB.Localize("Track #") & "</th>"
fout.WriteLine " <th id=dark>" & SDB.Localize("Year") & "</th>"
fout.WriteLine " <th>" & SDB.Localize("Genre") & "</th>"
fout.WriteLine " <th id=dark>" & SDB.Localize("Rating") & "</th>"
fout.WriteLine " <th>" & SDB.Localize("Bitrate") & "</th>"
fout.WriteLine " <th id=dark>" & SDB.Localize("Media") & "</th>"
fout.WriteLine "</tr>"
' Use progress to notify user about the current action
Dim Progress
Set Progress = SDB.Progress
Progress.Text = SDB.Localize("Exporting...")
' Iterate through the list and export all songs
Progress.MaxValue = list.count
Dim SongsLength
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 = " "
end if
Dim year
year = itm.year
if year<=0 then
year = " "
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 = MapXML(itm.ArtistName)
if artistname="" then
artistname = " "
end if
Dim songtitle
songtitle = MapXML(itm.title)
if songtitle="" then
songtitle = " "
end if
Dim albumname
albumname = MapXML(itm.AlbumName)
if albumname="" then
albumname = " "
end if
Dim songlength
songlength = itm.SongLengthString
SongsLength = SongsLength + itm.SongLength
if songlength="" then
songlength = " "
end if
Dim songgenre
songgenre = MapXML(itm.Genre)
if songgenre="" then
songgenre = " "
end if
Dim trackorder
trackorder = itm.TrackOrder
if trackorder="" then
trackorder = " "
elseif trackorder = "0" then
trackorder = " "
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 rating
Dim ratingCal
rating = itm.Rating
Select Case rating
Case ""
ratingCal = " "
Case -1
ratingCal = " "
Case 100
ratingCal = 5
Case 90
ratingCal = 4.5
Case 80
ratingCal = 4
Case 70
ratingCal = 3.5
Case 60
ratingCal = 3
Case 50
ratingCal = 2.5
Case 40
ratingCal = 2
Case 30
ratingCal = 1.5
Case 20
ratingCal = 1
Case 10
ratingCal = 0.5
Case 0
ratingCal = 0
Case Else
ratingCal = " "
End Select
Dim medialabel
medialabel = MapXML(itm.MediaLabel)
if medialabel="" then
medialabel = " "
end if
' Body of the table
fout.WriteLine "<tr><td align=right class=dark>"&i+1&"</td><td>"&artistname&"</td><td class=dark>"&songtitle _
&"</td><td align=right>"&songlength&"</td><td class=dark>"&albumname _
&"</td><td align=right>"&trackorder&"</td><td align=right class=dark>"&Year _
&"</td><td>"&songgenre&"</td><td class=Dark>"&ratingCal&"</td><td align=right>"&bitrate _
&"</td><td align=right class=Dark>"&medialabel&"</td></tr>"
Progress.Value = i+1
if Progress.Terminate then
Exit For
end if
next
Dim Seconds
Dim Mins
Dim Hours
Seconds = Fix(SongsLength / 1000)
Mins = Fix(Seconds / 60)
Seconds = Seconds mod 60
Hours = Fix(Mins / 60)
Mins = Mins mod 60
Dim strTime
strTime = Hours & ":" & Right("0" & Mins, 2) & ":" & Right("0" & Seconds, 2)
' Write some code to finish html document
fout.WriteLine "</table><p/><table width=100%><tr>"
fout.WriteLine "<td style='border-bottom-width:0px'><b>"&SDB.Localize("Total Tracks:")&" </b>"&i&"</td>"
fout.WriteLine "<td style='border-bottom-width:0px'><b>"&SDB.Localize("Total time:")&" </b>" & strTime & "</td>"
fout.WriteLine "<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
The Main Changes are these Lines:
Code: Select all
songlength = itm.SongLengthString
Dim Seconds
Dim Mins
Dim Hours
Seconds = Fix(SongsLength / 1000)
Mins = Fix(Seconds / 60)
Seconds = Seconds mod 60
Hours = Fix(Mins / 60)
Mins = Mins mod 60
Dim strTime
strTime = Hours & ":" & Right("0" & Mins, 2) & ":" & Right("0" & Seconds, 2)
fout.WriteLine "<td style='border-bottom-width:0px'><b>"&SDB.Localize("Total time:")&" </b>" & strTime & "</td>"
That should work for every collection (I hope):
[code]
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>" & SDB.Localize("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>" & SDB.Localize("MediaMonkey Track List")&"</h1></a>"
' Headers of table
fout.WriteLine "<table cellpadding=4 cellspacing=0>"
fout.WriteLine "<tr align=left>"
fout.WriteLine " <th id=dark>#</th>"
fout.WriteLine " <th>" & SDB.Localize("Artist") & "</th>"
fout.WriteLine " <th id=dark>" & SDB.Localize("Title") & "</th>"
fout.WriteLine " <th>" & SDB.Localize("Length") & "</th>"
fout.WriteLine " <th id=dark>" & SDB.Localize("Album") & "</th>"
fout.WriteLine " <th>" & SDB.Localize("Track #") & "</th>"
fout.WriteLine " <th id=dark>" & SDB.Localize("Year") & "</th>"
fout.WriteLine " <th>" & SDB.Localize("Genre") & "</th>"
fout.WriteLine " <th id=dark>" & SDB.Localize("Rating") & "</th>"
fout.WriteLine " <th>" & SDB.Localize("Bitrate") & "</th>"
fout.WriteLine " <th id=dark>" & SDB.Localize("Media") & "</th>"
fout.WriteLine "</tr>"
' Use progress to notify user about the current action
Dim Progress
Set Progress = SDB.Progress
Progress.Text = SDB.Localize("Exporting...")
' Iterate through the list and export all songs
Progress.MaxValue = list.count
Dim SongsLength
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 = " "
end if
Dim year
year = itm.year
if year<=0 then
year = " "
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 = MapXML(itm.ArtistName)
if artistname="" then
artistname = " "
end if
Dim songtitle
songtitle = MapXML(itm.title)
if songtitle="" then
songtitle = " "
end if
Dim albumname
albumname = MapXML(itm.AlbumName)
if albumname="" then
albumname = " "
end if
Dim songlength
songlength = itm.SongLengthString
SongsLength = SongsLength + itm.SongLength
if songlength="" then
songlength = " "
end if
Dim songgenre
songgenre = MapXML(itm.Genre)
if songgenre="" then
songgenre = " "
end if
Dim trackorder
trackorder = itm.TrackOrder
if trackorder="" then
trackorder = " "
elseif trackorder = "0" then
trackorder = " "
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 rating
Dim ratingCal
rating = itm.Rating
Select Case rating
Case ""
ratingCal = " "
Case -1
ratingCal = " "
Case 100
ratingCal = 5
Case 90
ratingCal = 4.5
Case 80
ratingCal = 4
Case 70
ratingCal = 3.5
Case 60
ratingCal = 3
Case 50
ratingCal = 2.5
Case 40
ratingCal = 2
Case 30
ratingCal = 1.5
Case 20
ratingCal = 1
Case 10
ratingCal = 0.5
Case 0
ratingCal = 0
Case Else
ratingCal = " "
End Select
Dim medialabel
medialabel = MapXML(itm.MediaLabel)
if medialabel="" then
medialabel = " "
end if
' Body of the table
fout.WriteLine "<tr><td align=right class=dark>"&i+1&"</td><td>"&artistname&"</td><td class=dark>"&songtitle _
&"</td><td align=right>"&songlength&"</td><td class=dark>"&albumname _
&"</td><td align=right>"&trackorder&"</td><td align=right class=dark>"&Year _
&"</td><td>"&songgenre&"</td><td class=Dark>"&ratingCal&"</td><td align=right>"&bitrate _
&"</td><td align=right class=Dark>"&medialabel&"</td></tr>"
Progress.Value = i+1
if Progress.Terminate then
Exit For
end if
next
Dim Seconds
Dim Mins
Dim Hours
Seconds = Fix(SongsLength / 1000)
Mins = Fix(Seconds / 60)
Seconds = Seconds mod 60
Hours = Fix(Mins / 60)
Mins = Mins mod 60
Dim strTime
strTime = Hours & ":" & Right("0" & Mins, 2) & ":" & Right("0" & Seconds, 2)
' Write some code to finish html document
fout.WriteLine "</table><p/><table width=100%><tr>"
fout.WriteLine "<td style='border-bottom-width:0px'><b>"&SDB.Localize("Total Tracks:")&" </b>"&i&"</td>"
fout.WriteLine "<td style='border-bottom-width:0px'><b>"&SDB.Localize("Total time:")&" </b>" & strTime & "</td>"
fout.WriteLine "<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
[/code]
The Main Changes are these Lines:
[code]
songlength = itm.SongLengthString
Dim Seconds
Dim Mins
Dim Hours
Seconds = Fix(SongsLength / 1000)
Mins = Fix(Seconds / 60)
Seconds = Seconds mod 60
Hours = Fix(Mins / 60)
Mins = Mins mod 60
Dim strTime
strTime = Hours & ":" & Right("0" & Mins, 2) & ":" & Right("0" & Seconds, 2)
fout.WriteLine "<td style='border-bottom-width:0px'><b>"&SDB.Localize("Total time:")&" </b>" & strTime & "</td>"
[/code]